Jump to content
  • Advertisement
Sign in to follow this  
Ars7c3

C++ Animation in Allegro Problem

This topic is 2499 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

Hey guys. I have been trying for days now to figure out this problem! I am 13 years old and I am trying to write an animation class for my game. It will be able to blit sprites off a
spritesheet onto the screen based on what frame the animation is on. However, I have encountered a problem, and I will appreciate anyone's assistance to my problem. Happy Holidays and thanks in advance!biggrin.gif




void Animation::PlayAnimation(int framex, int framey, int totalframes, int objectx, int objecty,BITMAP *buffer)
{

SetFrameX(framex); //Sets the X cord for SpriteSheet
SetFrameY(framey); // Sets the Y cord for SpriteSheet
SetTotalFrames(totalframes); //Total frames in animation

for(int i = 0; i < TotalFrames; i++)
{
Frame = i;
FrameX = i * Size; //Size is the size of each sprite on SpriteSheet. What this line does is sets X cord(FrameX) on the SpriteSheet to the next Sprite


if(Frame == TotalFrames) //Resets Animation when animation reaches the max frames
{
Frame = 0;
FrameX = 0;
}





}

masked_blit(SpriteSheet,buffer,FrameX,FrameY,objectx,objecty,Size,Size); //This is where i blit the sprite to the screen. But it only plays the 3(last) frame?! When I put it in the loop // it just draws all frames at the same time so it looks all like 1 bitmap

}



I have attached the SpriteSheet i am using

Share this post


Link to post
Share on other sites
Advertisement
It seems as if you don't have code to cause a delay between two frames, which would cause the frames to display very quickly. Also, your post doesn't have the spritesheet attached for some reason.

Share this post


Link to post
Share on other sites
I understand what you are saying, but not entirely sure how to implement that. Could you maybe help me out by writing some quick peusado code; or at least give me a basic idea how to do that. Btw idk why the sprites beet didn't attach.

Share this post


Link to post
Share on other sites
Well, a simple way would be to do this:
  1. advance all the animations 1 frame and then redraw them
  2. wait until the next frame
For the second step, look for a function named "Delay" or "Sleep" (depending on what platform, language and library you are using to write your game)


Share this post


Link to post
Share on other sites
I tried the Sleep function and it does help slow down the animation speed, thank you very much. However, I still encounter the same problem i was having before. The blit function is outside the for loop and so can only blit when the for loop is over, making it only able to draw the last frame. I tried to fix this by putting the blit function inside the for loop, but it just drew all the sprites at the same time.

Share this post


Link to post
Share on other sites
Well, that was rather silly of me. I didn't notice that you had a loop going through all the frames and then drawing the picture. Alright, so you probably want to replace the loop with a single step.

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!