Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualServant of the Lord

Posted 06 December 2012 - 08:30 PM

Sure, there are two common ways:

A) On button press, set bool "move" to true. On button release, set bool "move" to false. (You have to create such a bool yourself). Every frame, if "move" is true, move the player. Realistically, you'll want several bools, because you can move in several directions, or alternatively, two ints (x,y) holding the amount to move each frame, positively or negatively.

B) Let SDL handle the "move" boolean for you, and instead call SDL_GetKeyState() which returns a bool array of most of the keyboard keys and whether they are currently being held or not (see documentation link). Every frame you can then check if the key is held down, and move the player.

#3Servant of the Lord

Posted 06 December 2012 - 08:30 PM

Sure, there are two common ways:

A) On button press, set bool "move" to true. On button release, set bool "move" to false. (You have to create such a bool yourself). Every frame, if "move" is true, move the player. Realistically, you'll want several bools, because you can move in several directions, or alternatively, two ints (x,y) holding the amount to move each frame, positively or negatively.
B) Let SDL handle the "move" boolean for you, and instead call SDL_GetKeyState() which returns a bool array of most of the keyboard keys and whether they are currently being held or not (see documentation link). Every frame you can then check if the key is held down, and move the player.

#2Servant of the Lord

Posted 06 December 2012 - 08:29 PM

Sure, there are two common ways:
  • On button press, set bool "move" to true. On button release, set bool "move" to false. (You have to create such a bool yourself). Every frame, if "move" is true, move the player. Realistically, you'll want several bools, because you can move in several directions, or alternatively, two ints (x,y) holding the amount to move each frame, positively or negatively.
  • Let SDL handle the "move" boolean for you, and instead call SDL_GetKeyState() which returns a bool array of most of the keyboard keys and whether they are currently being held or not (see documentation link). Every frame you can then check if the key is held down, and move the player.

#1Servant of the Lord

Posted 06 December 2012 - 08:29 PM

Sure, there are two common ways:
  • On button press, set bool "move" to true. On button release, set bool "move" to false. (You have to create such a bool yourself). Every frame, if "move" is true, move the player. Realistically, you'll want several bools, because you can move in several directions, or alternatively, two ints (x,y) holding the amount to move each frame, positively or negatively.
  • Let SDL handle the "move" boolean for you, and instead call SDL_GetKeyState() which returns a bool array of most of the keyboard keys and whether they are currently being held or not (see documentation link). Every frame you can then check if the key is held down, and move the player.

PARTNERS