program HowToUseAnimationWithMultipleSprites; uses SwinGame,sgTypes; procedure Main(); var myLizard : Sprite; myFrog : Sprite; begin OpenAudio(); OpenGraphicsWindow('Dance' ,800 ,600 ); LoadResourceBundle('dance_bundle.txt' ); myFrog := CreateSprite(BitmapNamed('FrogBmp' ) ,AnimationScriptNamed('WalkingScript' ) ); SpriteStartAnimation(myFrog ,'Dance' ); SpriteSetX(myFrog ,496 ); SpriteSetY(myFrog ,250 ); myLizard := CreateSprite(BitmapNamed('LizardBmp' ) ,AnimationScriptNamed('WalkingScript' ) ); SpriteStartAnimation(myLizard ,'Dance' ); SpriteSetX(myLizard ,238 ); SpriteSetY(myLizard ,272 ); repeat ClearScreen(ColorWhite ); DrawSprite(myFrog ); DrawSprite(myLizard ); RefreshScreen(60 ); UpdateSprite(myFrog ); UpdateSprite(myLizard ); ProcessEvents(); until WindowCloseRequested(); FreeSprite(myLizard ); FreeSprite(myFrog ); CloseAudio(); ReleaseAllResources(); end; begin Main(); end.
How To Use Animation With Multiple Sprites
This article will show you how to move multiple sprites with animation at the same time on the game screen. In most games it is important to show multiple animated sprites on the screen at the same time.
SwinGame allows you to create and draw as many sprites as you want on the screen. To make an animation out of it, you need to follow these steps:
- Create two different sprites (Create Sprite) and place them in different positions (Sprite Set X and Sprite Set Y) of the screen
- Start both animations (Sprite Start Animation)
- In game loop update (Update Sprite) and draw (Draw Sprite) the sprites followed by refresh the screen (Refresh Screen)
The code below shows a small program that demonstrates all these steps in making an animation with two sprites. Similarly it is possible to make lots of animation with different sprites simulteniously from one script or more.
If there is a useful hint you will find it in a box like this
Suggested projects will appear here.