Jump to content
  • Advertisement
Sign in to follow this  
Hilake

About animate 2D spirit

This topic is 4814 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi all! I'm a beginner about 2D game programmer. I know I will change the different picture of the spirit make it animate. But I think this way maybe low efficienty. I want to know if there are ways to make it animate? For example, How does a cartoon editor of which I heared? Any comment will be welcome. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
If you mean the 2D animation, such as explosions or like in Super Mario Bros with Mario moving around, then the only way is to have many images in sequence.

What I do is to tile all those together in one big bitmap file, then have Frame to keep count of the current frame.

pseudo code:

if(right button down)
{
Frame += 1
if(Frame > 30) //30 frames of walking
Frame = 0
}

That's one way of doing it.

then do this:

Tile.x = Frame * Tile.size //if each tile is 16 pixels long, then 20*16 will get you to the 20th tiled frame.

then draw the bitmap.

Edit: If you mean animate like in 3D models being able to move around and bending, then it's impossible in the 2D sense. The 2D method is that you have different bitmaps for parts of the bitmap. Such like having bitmap animation for arm, so you just draw different frames for the arm, but keeping the body same, or do combination. This is utilized in some games to achieve smooth animation effects. But requires more work though.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
i need something in allegro for walking but i dont understand how to do it

Share this post


Link to post
Share on other sites
Quote:
Original post by Zeraan
The 2D method is that you have different bitmaps for parts of the bitmap. Such like having bitmap animation for arm, so you just draw different frames for the arm, but keeping the body same, or do combination. This is utilized in some games to achieve smooth animation effects. But requires more work though.


I think this way maybe well display, but how to programme in this way? Give me some suggest, Thanks!
I want to know if there is a way like that I just play a spirit's walk file which contain a cartoon. In this way, I will only play a file when I want to make the spirit move.

Share this post


Link to post
Share on other sites
Well friend, there is long trail ahead of you. I'm not saying I'm done with it but it appears I'm a little bit further.

Quote:
I will only play a file when I want to make the spirit move.


Do not worry about playing file. This way or another most likely you want to load all the bitmaps images at the game start (or start of each level, or actually whenever you want but a simple game should be able to load all of them at startup) since they are all in the memory until you delete them.

To make things even simpler, this is how I did it developing my first project. I put all images into different bitmap files:

LoadImage ('ThinkingHard01')
LoadImage ('ThinkingHard02')
LoadImage ('ThinkingHard03')
.
.
.
When I wanted to animate I had to check what time is it. Ok we have 0.000 sec, cool – let’s display the first image on the screen

DisplayImage ('ThinkingHard01')

Now, depending on how many frames per second you wish you make another time check. Let’s say you want a frame every half second, so as long as the counter shows: 0.5 sec – display:

DisplayImage ('ThinkingHard02')

Time=1 sec:

DisplayImage ('ThinkingHard03')

This above is a very VERY simple and generalized animation approach.

I cannot provide you a link to any article about animation, but here:
  • Ok, what I'd suggest is to make a class that contains your player's animation stuff, so that it'd be easier to work with.

    If you want to use the multi-bitmap method (using more than one bitmap at same time for animation) then I would do like this:

    class Person
    {
    private:
    T_2DObject Frames[3][10]; //3 different frames, 10 frames each part
    int X,Y; //Stores the arbitary locations
    int Frame; //Which Frame it is on, can add more for individual parts
    int Speed; //stores the frames per second for your game speed to calculate animation
    //This is all the basic storage variables you'll need. Now for the functions

    MoveArm1(); //Moves the arm, the frame state is stored in the class
    MoveArm2(); //Moves the other arm

    public:
    Person(istream&); //Pass a file input method here to load up the bitmap for animation

    void Walk(int Direction, int FPS); //This handles all the walking stuff

    void Display(); //Displays the current bitmap
    };

    //a sample Walk function may look like this:
    void Person::Walk(int Dir, int FPS);
    {
    Speed += float(FPS)/10.00; //10 frames per sec for animation
    if(Speed > = .1) //Is it time to update frame?
    {
    MoveArm1();
    MoveArm2();
    Frame++;
    if(Frame > 10) //repeat the animation cycle
    Frame = 0;
    }
    }

    //MoveArm1() would look like above, using the Frame2 and Frame3.

    void Display()// would look like this:
    {
    Display.DrawBitmap(Frame[0][Frame], X, Y, other display stuff here); //Draw the body
    //then when you draw arms, you need to add or subtract from the X,Y to get the proper position. For example if it is 5 pixels higher than Y is, then do this
    Display.DrawBitmap(Frame[1][Frame], X, Y-5, other display stuff here);

    //and so forth.
    }






    That's the very barebones of an animation class. Hope this helps!

    Also, don't forget to update the X,Y coordinates when moving!

    [Edited by - Zeraan on September 12, 2005 12:07:11 PM]

    Share this post


    Link to post
    Share on other sites
    Guest Anonymous Poster
    Zeraan

    could you put that in the code box thingy so i see it better?

    Share this post


    Link to post
    Share on other sites
    Quote:
    Original post by Rob Loach
    I'm going to be the devil's advocate and shout out SDL as it, in my opinion, is a more complete API.


    I only provided the allegro link because I assumed that the first AP was also the OP. ;)

    Quote:
    Original post by Anonymous Poster
    i need something in allegro for walking but i dont understand how to do

    Share this post


    Link to post
    Share on other sites
    Sign in to follow this  

    • Advertisement
    ×

    Important Information

    By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

    We are the game development community.

    Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

    Sign me up!