Jump to content

  • Log In with Google      Sign In   
  • Create Account


C++ Animation in Allegro Problem


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 Ars7c3   Members   -  Reputation: 178

Like
0Likes
Like

Posted 16 December 2011 - 06:29 PM

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!Posted Image



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

Sponsor:

#2 RulerOfNothing   Members   -  Reputation: 1159

Like
0Likes
Like

Posted 16 December 2011 - 10:06 PM

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.

#3 Ars7c3   Members   -  Reputation: 178

Like
0Likes
Like

Posted 16 December 2011 - 10:49 PM

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.

#4 RulerOfNothing   Members   -  Reputation: 1159

Like
0Likes
Like

Posted 17 December 2011 - 04:09 AM

Well, a simple way would be to do this:
  • advance all the animations 1 frame and then redraw them
  • 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)




#5 Ars7c3   Members   -  Reputation: 178

Like
0Likes
Like

Posted 17 December 2011 - 06:49 AM

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.

#6 RulerOfNothing   Members   -  Reputation: 1159

Like
0Likes
Like

Posted 17 December 2011 - 11:24 PM

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.

#7 Ars7c3   Members   -  Reputation: 178

Like
0Likes
Like

Posted 18 December 2011 - 08:33 AM

Thank you so much! It works!Posted Image




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS