How To Create An Animation

This article will show you how to create animation in SwinGame.

Level

Advanced

Details

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:

  1. Load the bundles (Load Resource Bundle) first
  2. Create a sprite (Create Sprite)
  3. Start the animation (Sprite Start Animation) with the animation name in the animation script.
  4. Give the animated sprite an initial position (Sprite Set X and Sprite Set Y) on the game screen.
  5. 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.

Source Code Widget

  • 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.
    Download Now"
  • #include 
    #include "SwinGame.h"
    int main() 
    {
        sprite  explosion;
        open_audio();
        open_graphics_window("Create Animation" ,200 ,200 );
        load_resource_bundle("explosion_bundle.txt" );
        explosion = create_sprite(bitmap_named("explosionBmp" ) ,animation_script_named("explosionScrpt" ) ) ;
        sprite_start_animation(explosion ,"explosion_loop" );
        sprite_set_x(explosion ,64 );
        sprite_set_y(explosion ,64 );
        do 
        {
            clear_screen(color_white );
            draw_sprite(explosion );
            refresh_screen(60 );
            update_sprite(explosion );
            process_events();
        }
        while ( ! (window_close_requested() ) );
        delay(800 );
        free_sprite(explosion );
        close_audio();
        release_all_resources();
        return 0;
    }
    
    Download Now"
  • Source Code Coming Soon

  • Source Code Coming Soon

  • Source Code Coming Soon

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.

Possibilities