I am trying to make a Galaga type game in android using the basic surfaceview single thread engine. My problem is quite simple, in the Gameview class which extends I have defined the onTouch method which reads any touch events taking place on the canvas. If the screen is touched where the left button is placed (or the right button) The starship is supposed to move left/right as long as the button is pressed.
But when the button area is touched, the update method of my ship is only called once and it moves to the left or right only once and the button has to be touched again in order to move is further. Is there a way so to make the ship continuously move left/right as long as the button area is touched?
Thanks in advance.
Don’t mix your move logic with the onTouch logic. In onTouch you can just set a flag ‘touched’, and then during the regular game update loop you can move the ship if touched is true. Then unset the ‘touched’ flag in onTouchReleased.