I want help in set condition to control the speed of missile when screen touched(A missile shooter Jet). I tried with Timer schedule but didn't worked for me.
=========================================================================================
By calling batch.draw()
and updating the velocity of the missile in a while loop the missile will be moved off screen before it actually gets drawn. The while loop must complete before it moves down to the rest of the drawing code.
You will need to remove the while loop, which means you won't be able to use justTouched()
as that will only be active for one render cycle. Instead you'll need to create another variable (like "missileFired" or something) that is set when the button is pressed, and then you check this before updating the position of the missile and drawing it. Once the missile is off screen, then reset missileFired to false.
What you are calling "velocity", isn't really velocity. It is a position offset from the original position of the rocket. You can directly update the y position of the missile instead.
missileY += 1;
One final point is that your missile will move at different speeds when playing the game at different frame rates. The missile will move twice as fast when played at 60fps as it will at 30fps. To get around this, you need to use the delta time (the time between frames) and multiply this by the increment value that you use to update your missile's position. So that would look like this.
missileY += 20 * Gdx.graphics.getDeltaTime();
In this example, the missile will move 20 pixels every second. However, if you use missileY += 1
instead, then the missile will be updated 1 pixel every frame (which would be 30 pixels per second at 30fps or 60 pixels per second at 60fps). By using delta time the movement is now based on seconds instead of frames, which means your missile will move at exactly the same speed regardless of the frame rate of the device. Look up programming tutorials on "delta time", "game loops", and "frame rate independent game play" for more details on this topic.