Skip to main content
added 127 characters in body
Source Link

buttonDown() and other methods inControllerListener only fired when the key is pressed.If you want constant movement you need a variable and set for example when KeyRight is called and unset when keyRight is released or another key like KeyLeft pressed There is a good sample here

http://www.gamefromscratch.com/post/2014/11/24/LibGDX-Video-Tutorial-Handling-Keyboard-Mouse-and-Touch-Input.aspx

http://www.gamefromscratch.com/post/2014/11/24/LibGDX-Video-Tutorial-Handling-Keyboard-Mouse-and-Touch-Input.aspx

As you see

   public boolean keyDown(int keycode) {
      if(keycode == Input.Keys.RIGHT)
         movingRight = true;
      return true;
   }

movingRight equals true whenever right arrow key pressed and in render() method try

   public void render () {

      if(movingRight)
         sprite.translateX(1f);
       //...
}

buttonDown() and other methods inControllerListener only fired when the key is pressed.If you want constant movement you need a variable and set for example when KeyRight is called and unset when keyRight is released or another key like KeyLeft pressed There is a good sample here

http://www.gamefromscratch.com/post/2014/11/24/LibGDX-Video-Tutorial-Handling-Keyboard-Mouse-and-Touch-Input.aspx

As you see

   public boolean keyDown(int keycode) {
      if(keycode == Input.Keys.RIGHT)
         movingRight = true;
      return true;
   }

movingRight equals true whenever right arrow key pressed and in render() method try

   public void render () {

      if(movingRight)
         sprite.translateX(1f);
       //...
}

buttonDown() and other methods inControllerListener only fired when the key is pressed.If you want constant movement you need a variable and set for example when KeyRight is called and unset when keyRight is released or another key like KeyLeft pressed There is a good sample here

http://www.gamefromscratch.com/post/2014/11/24/LibGDX-Video-Tutorial-Handling-Keyboard-Mouse-and-Touch-Input.aspx

As you see

   public boolean keyDown(int keycode) {
      if(keycode == Input.Keys.RIGHT)
         movingRight = true;
      return true;
   }

movingRight equals true whenever right arrow key pressed and in render() method try

   public void render () {

      if(movingRight)
         sprite.translateX(1f);
       //...
}
Source Link

buttonDown() and other methods inControllerListener only fired when the key is pressed.If you want constant movement you need a variable and set for example when KeyRight is called and unset when keyRight is released or another key like KeyLeft pressed There is a good sample here

http://www.gamefromscratch.com/post/2014/11/24/LibGDX-Video-Tutorial-Handling-Keyboard-Mouse-and-Touch-Input.aspx

As you see

   public boolean keyDown(int keycode) {
      if(keycode == Input.Keys.RIGHT)
         movingRight = true;
      return true;
   }

movingRight equals true whenever right arrow key pressed and in render() method try

   public void render () {

      if(movingRight)
         sprite.translateX(1f);
       //...
}