forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Proper Way to do an animation?

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
roland



Joined: 11 Feb 2006
Posts: 13

PostPosted: Sat Feb 11, 2006 10:32 pm    Post subject: Proper Way to do an animation? Reply with quote

I am trying to figure out the proper and best way to do an animation..

I have a small sprite (16x32) and a texture that is 256x32 wide. Each 16 Pixels there is a new animation stored (walking left 5 anims, waiting and then walking right!).

I currently just move the sprite from left to right and change the u Coordinate by 16 each animation and reset to zero again when the 5 animations going right are done..

This works just fine and looks as it should. The thing I am not sure is if
I want to have the sprite walk right for a certain amount of time, then stop and play the waiting animation and the turn around and walk left again...

I know this isnt exactly psp dev related but I am hoping that somebody here can point me in a direction that things like that are properly done!?

thanx
Back to top
View user's profile Send private message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Sat Feb 11, 2006 11:15 pm    Post subject: Reply with quote

Well, just play the right moving animation by setting your start u to the position of the first frame of the animation and play until you finish, then set the u to the position of the waiting animation and after this finishes, start with the left animation. So the only problem is to know the right u values for each animation frame. Then it's only a matter of correct checking for finished animations and starting another one.

However, I would highly recommend you to create a little organized type of animation system, to be more flexible and also be able to use the code for other animations. For this, you should create a structure for an animation frame that holds the coordinates of the sprite in the texture and maybe also some information about the time the sprite is to be displayed, making something like this:
struct AniFrame {
int u, v;
int delay;
}

Then the next level would be to create a structure for a complete animation sequence, which contains information on the number of frames included, the currently displayed frame, the time when the last update occured and maybe the base animation speed.
struct AniSequence {
int numframes;
int curframe;
int lastupdate;
int fps;
struct AniFrame *frames;
}

Then just create a function that plays a animation and takes the time of the current screen update and a display position and the animation structure as parameter.

void play_ani( int x, int y, int ms, struct AniSequence* ani )

In this function you'd check for the animation to be updated (ie the next frame is to be displayed after the ms exceeds the lastupdate time plus the fps time delta plus the delay time of the frame).
Then it just draws the sprite from the texture to the wanted position.

With this structure you could check on every screen update if the current frame of a animation is greater than the number of frames, meaning the animation is finished and either to be started again or another animation to be started. With this its very easy to create complex animation sequences out of a pool of available animations.

Hope this helps getting a basic idea of the concept :)
Back to top
View user's profile Send private message Visit poster's website
roland



Joined: 11 Feb 2006
Posts: 13

PostPosted: Sat Feb 11, 2006 11:58 pm    Post subject: Reply with quote

Actually this is a really good idea to deal with the issue. .I'll toy around with it.. thanx for the hint!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group