This article will show you how to move a sprite in SwinGame.
In a game it is important to move almost all the characters and objects. Once a sprite is created SwinGame lets you move that sprite anyway you want. The code below shows how you can move a sprite and to do that SwinGame performs a few steps.
- Get the velocity of the sprite
- Introduce a game loop where it clears the screen with the color you want
- Place the sprite back to the screen if it goes off the screen
- Draw and update the sprite
- Have an end condition of the game loop
If the object is moving, there is a possibility of it being disappear from the screen. SwinGame has a function to detect if the sprite is off the screen. Use it wisely!
You can make lots of games using this principal. You can have all the people running around the screen and when you click on them they stop.