program HowToUseBundles; uses SwinGame,sgTypes; procedure Main(); var explosion : Sprite; begin OpenAudio(); OpenGraphicsWindow('Using Bundles' ,300 ,300 ); LoadResourceBundle('how_to_bundles.txt' ); BitmapSetCellDetails(BitmapNamed('fireBmp' ) ,38 ,38 ,8 ,2 ,16 ); explosion := CreateSprite(BitmapNamed('fireBmp' ) ,AnimationScriptNamed('fire' ) ); SpriteSetX(explosion ,131 ); SpriteSetY(explosion ,131 ); repeat ProcessEvents(); ClearScreen(ColorWhite ); DrawText('[A]nimation' ,ColorBlack ,0 ,0 ); DrawText('[T]ext' ,ColorBlack ,0 ,10 ); DrawText('[S]ound Effect' ,ColorBlack ,0 ,20 ); DrawText('[M]usic' ,ColorBlack ,0 ,30 ); DrawSprite(explosion ); UpdateSprite(explosion ); if KeyTyped(vk_a ) then SpriteStartAnimation(explosion ,'FireExplosion' ) else if KeyDown(vk_t ) then DrawText('Hi!!!' ,ColorRed ,FontNamed('harabaraText' ) ,120 ,125 ) else if KeyTyped(vk_s ) then PlaySoundEffect(SoundEffectNamed('danceBeat' ) ) else if KeyTyped(vk_m ) then PlayMusic(MusicNamed('danceMusic' ) ,1 ); RefreshScreen(60 ); until WindowCloseRequested(); FreeSprite(explosion ); CloseAudio(); ReleaseAllResources(); end; begin Main(); end.
How To Use Bundles
This article will show you how to use bundles in a program. Bundles makes a program relatively easier to understand with less coding from your part.
Please look at About Resources section to know about how to write a bundle script. Once you have your bundle script you will be able to use any TrueType font in your game environment, you can use an animation with ease and lot less coding, you can just load a music or sound effect file and play that file in your game, or you can use a timer that is already created in the bundles.
To be able to do all these things you need to follow the steps below:
- After opening the audio (Open Audio) and graphics window (Open Graphics Window) you need to load the bundles (Load Resource Bundle).
- Call the bitmap file (Bitmap Named) which is already loaded in bundle from the bundle script and set the cell details (Bitmap Set Cell Details) for that image. Please read about how to put bitmap (BITMAP) in Bundles.
- Get the animation by its name (Animation Script Named) which is already given in bundle script. Please read about how to put animation (ANIM) in bundles.
- Now create a sprite (Create Sprite) by calling that bitmap name and the animation name.
- After that the game loop is introduced and it shows all the options that the users have.
- Draw (Draw Sprite) and update (Update Sprite) the sprite that you have just created.
- Now depending on the user's command-
- Start the animation (Sprite Start Animation) if the user types "A" (Key Typed(VK_A)).
- Else draw the text (Draw Text) by calling the font name (Font Named) that is already loaded with the bundles if the user press and holds "T" (Key Down(VK_T)). Please read about resources to know how to put bitmap (BITMAP) in Bundles.
- Else play the sound effect (Play Sound Effect) by calling the sound effect name (Sound Effect Named) that is already loaded with the bundles if the user types "S" (Key Typed(VK_S)).
- Else play the music (Play Music) by calling the music name (Music Named) that is already loaded with the bundles if the user types "M" (Key Typed(VK_M)).
The code below shows a small program that demonstrates all these functions in action.
If there is a useful hint you will find it in a box like this
Suggested projects will appear here.