program HowToCreateAnAnimation; uses SwinGame,sgTypes; procedure Main(); var explosion : Sprite; begin OpenAudio(); OpenGraphicsWindow('Create Animation' ,200 ,200 ); LoadResourceBundle('explosion_bundle.txt' ); explosion := CreateSprite(BitmapNamed('explosionBmp' ) ,AnimationScriptNamed('explosionScrpt' ) ); SpriteStartAnimation(explosion ,'explosion_loop' ); SpriteSetX(explosion ,64 ); SpriteSetY(explosion ,64 ); repeat ClearScreen(ColorWhite ); DrawSprite(explosion ); RefreshScreen(60 ); UpdateSprite(explosion ); ProcessEvents(); until WindowCloseRequested(); Delay(800 ); FreeSprite(explosion ); CloseAudio(); ReleaseAllResources(); end; begin Main(); end.
How To Create An Animation
This article will show you how to create animation in SwinGame.
SwinGame lets you create animations. To make an animation you will need an image with some bitmap cells in it. Create your own animation script and the bundle script. Please refer to All about resources and all about animation to know how to write a bundle script and an animation script.
After that you will be able to build your own animation by just following these steps:
- Load the bundles (Load Resource Bundle) first
- Create a sprite (Create Sprite)
- Start the animation (Sprite Start Animation) with the animation name in the animation script.
- Give the animated sprite an initial position (Sprite Set X and Sprite Set Y) on the game screen.
- In game loop draw the sprite (Draw Sprite) and update the sprite (Update Sprite) you have just created.
The code below shows a small program that demonstrates all these steps in making an animation.
To avoid memory lick before ending the program free all the sprites (Free Sprite) you have created and close all audio (Close Audio).
Please visit http://charas-project.net/ and you will find hundreds of image files which is essential to build animations.