How can I make a sprite animation?
First, I''m making a Fighting Game, I need to make an object something like this (I don''t know at all):
I want to call an animation like player1.punch(); and that function should put in screen the punch animation... plz help =S
I''m using allegro and dev-c++
Thanks
________
Ibito =P
________Ibito =P
Animations in 2D is basicaly drawing alot of pictures after each other (kind of like on of thos book where you flip the pages fast enought to make it look like somone is runing or such)
Well I don''t know how allegro deals with displaying graphic. But the way I did it for a OpenGL 2D game was to store my sprites for the animation in a array. Then I simply wrote a funtion someting like this.
Where DrawSprite(index) would draw the sprite that was in the value of index spot on the array. Of course, this is just barebone. With this function the animation would run very fast, and in diffrent speed on diffrent system.
What needs to be added is a time control that only lett index increase when it''s time for the next frame (e.g. one new sprite every 1/5th of a second).
Well I don''t know how allegro deals with displaying graphic. But the way I did it for a OpenGL 2D game was to store my sprites for the animation in a array. Then I simply wrote a funtion someting like this.
Animate(){ static int index = 0; DrawSprite(index); index++; if(index >= SPRITES_IN_ANIMATION) { index = 0; }}
Where DrawSprite(index) would draw the sprite that was in the value of index spot on the array. Of course, this is just barebone. With this function the animation would run very fast, and in diffrent speed on diffrent system.
What needs to be added is a time control that only lett index increase when it''s time for the next frame (e.g. one new sprite every 1/5th of a second).
never use a loop! make a frame counter nd draw that frame a time then check if time has come fir the next frame
I understand all that stuff... the thing I don''t understand at all is... I dont know how/when I''ll change the animation from walking to running, or walking to jumping, or walking to kicking, ect..., I read somewhere is like an array of objects... but I dont understand it very well...
Sorry about my english... I''m from México, many thanks over anyway
Sorry about my english... I''m from México, many thanks over anyway
________Ibito =P
enum theMoveof{ jumping, dying, eating, bathing, smoking };
theMoveof myFighter;
myFighter = smoking;
enum is like bool only with more options, why dont you try to find out a good way to apply this?
theMoveof myFighter;
myFighter = smoking;
enum is like bool only with more options, why dont you try to find out a good way to apply this?
Crosspost much?
"Luck is for people without skill."- Robert (I Want My Island)"Real men eat food that felt pain before it died."- Me
quote: Original post by black_mage_s
Crosspost much?
is not a crosspost... I posted in game programming, then I saw this forum (Begginers), nobody reply the post in game programming so I tought it was better if I post here
________Ibito =P
quote: Original post by Pipo DeClown
enum theMoveof{ jumping, dying, eating, bathing, smoking };
theMoveof myFighter;
myFighter = smoking;
enum is like bool only with more options, why dont you try to find out a good way to apply this?
and how can I set the frames for moving, eating, smoking, ect, to the player1 and player2 if each player has a diferent quantity of frames?
________Ibito =P
You want each player to be in a certain "state" at a any givin time. for example, If I am running to the supermarket, you can consider me to be in a "running" state. If i stop to take a pee, then you can consider me to be in a "peeing" state.
What you need is a set of images which animate the player in each of the states that he can possibly be in. then, you just figure out what the player has done (in terms of control), set the state, then animate appropriatly.
So, to show you via some type of real example, here it is:
[without writing all the wonderfull class ish...]
enum PLAYER_STATE{RUNNING, PUNCHING};
PLAYER_STATE PlayerState;
//We want the player to punch when then mouse button is clicked
if(Mouse.LeftButton) //assuming you have some type of input control
PlayerState = PUNCHING;
//...
//Then later, when you want to draw
switch PlayerState
{
case RUNNING:
{
Player.Run();//Do your running stuff
}
case PUNCHING:
{
Player.punch();//do your punching stuff
}
}
What you need is a set of images which animate the player in each of the states that he can possibly be in. then, you just figure out what the player has done (in terms of control), set the state, then animate appropriatly.
So, to show you via some type of real example, here it is:
[without writing all the wonderfull class ish...]
enum PLAYER_STATE{RUNNING, PUNCHING};
PLAYER_STATE PlayerState;
//We want the player to punch when then mouse button is clicked
if(Mouse.LeftButton) //assuming you have some type of input control
PlayerState = PUNCHING;
//...
//Then later, when you want to draw
switch PlayerState
{
case RUNNING:
{
Player.Run();//Do your running stuff
}
case PUNCHING:
{
Player.punch();//do your punching stuff
}
}
------------------------------------------VOTE Patrick O'GradyWrite in Presidential CandidateThe Candidate who Cares.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement