program HowToCreateMultipleAnimationsFromOneScript; uses SwinGame,sgTypes; procedure Main(); var explosion : Sprite; begin OpenAudio(); OpenGraphicsWindow('Create Multiple Animations' ,200 ,200 ); LoadResourceBundle('explosion_bundle.txt' ); explosion := CreateSprite(BitmapNamed('explosionBmp' ) ,AnimationScriptNamed('explosionScrpt' ) ); SpriteSetX(explosion ,64 ); SpriteSetY(explosion ,64 ); repeat ClearScreen(ColorWhite ); DrawText('[E]xplosion' ,ColorBlack ,0 ,0 ); DrawText('[I]mplosion' ,ColorBlack ,0 ,10 ); DrawText('[L]oop' ,ColorBlack ,0 ,20 ); DrawSprite(explosion ); RefreshScreen(60 ); UpdateSprite(explosion ); ProcessEvents(); if KeyTyped(vk_e ) then SpriteStartAnimation(explosion ,'explosion' ); if KeyTyped(vk_i ) then SpriteStartAnimation(explosion ,'implosion' ); if KeyTyped(vk_l ) then SpriteStartAnimation(explosion ,'explosion_loop' ); until WindowCloseRequested(); FreeSprite(explosion ); CloseAudio(); ReleaseAllResources(); end; begin Main(); end.
How To Create Multiple Animations From One Script
This article will show you how to create multiple animations from one script.
In your animation script you need to mention different frames for different animations with an identifier for those animations. Please read about animation to know how you can create a script with multiple animation frames. After you create the identifier for different animations you can follow the steps below:
- In your game loop prompt the users which key they have to press to get the animation they want.
- Draw Sprite, Refresh Screen and update the sprite (Update Sprite).
- Next process all the events (Process Events) to get what the user input is.
- Now depending on the user's command-
- Start animating (Sprite Start Animation) your previously created sprite. Here you also have to mention the name of the animation that you want to play by calling the identifier of that animation. For the code below it will start the animation called explosion if the user press the key "E".
- It will start the animation called implosion if the user press the key "I"
- It will start the animation called explosion_loop if the user press the key "L"
The code below shows you step by step process to get multiple animations from the same bitmap file and one animation script.
Note that in Windows you must show a window before audio will play.
Suggested projects will appear here.