Skip to main content
GameDev.net gamedev.net
🔒 Locked

Sprites

Started by Andre Luiz Silva Mar 1, 2003 at 5:53 AM 2 replies 700+ views
Original Post
Andre Luiz Silva
Andre Luiz Silva
Hello, I wonder if you can share some information about sprites for a 2D plataform game. How do you structure them? I''ve been thinking about it, but I didn''t enjoy any of my approaches. Do you make them based on state machines? If so, does all of your sprites have the same states? What kind of information do you store on your structures? Thanks very much, Andre "- To begin with, said the Cat, a dog''s not mad. You grant that? - I suppose so, said Alice. - Well, then, - the Cat went on - you see, a dog growls when it''s angry, and wags its tail when it''s pleased. Now I growl when I''m pleased, and wag my tail when I''m angry. Therefore I''m mad."
"- To begin with, said the Cat, a dog's not mad. You grant that? - I suppose so, said Alice. - Well, then, - the Cat went on - you see, a dog growls when it's angry, and wags its tail when it's pleased. Now I growl when I'm pleased, and wag my tail when I'm angry. Therefore I'm mad."
thehurricane
thehurricane
The way I'm thinking about doing it is like this:

Each animation is defined as a list of images
typedef list Animation;    

Then I have a vector of animations for each sprite "type"...

vector<Animation> anims;

Keep an int of which animation you're currently using...
int currentAnim    

And the important part, an iterator pointing to one of the frames in your current animation:
Animation::iterator currentFrame    

If you don't know about iterators and container classes look for STL documentation on Google. So then on each processing frame, a sprite's DoAnim() member function is called.
void Sprite::DoAnim()
{
currentFrame++;
if (currentFrame == anims[currentAnim].end())
{
currentFrame = anims[currentAnim].begin();
}
}

Then you're draw function could simply access the current image by using
(*currentFrame)->Draw();    
...for example if your image class has a Draw member function.

Also you probably would want to implement a timing system in Sprite::DoAnim() so that it gets the system's "ticks" or time and compares it with the old time, and advance the frame if only a certain time has passed.


[edited by - thehurricane on March 1, 2003 10:43:12 AM]
Andre Luiz Silva
Andre Luiz Silva
Hello thehurricane,

Thanks for your reply. I am really worried is the way I should create my sprites considering behaviour (graphically while changing states and for AI). For example, if I have an enemy that''s only walking and it sees the player and then it has to change its behaviour/state for ATTACK. Which way do you guys implement it? I have already build a level editor and now I would like to add sprites to it, and some kind of behaviour, but I don''t imagine how and what should I consider. Imagine a game like Mario 3. There are several kinds of enemies. Some of them fly, jump, run, etc. Which way should I implement my sprites so I can set and retrive different kinds of behaviours?
"- To begin with, said the Cat, a dog's not mad. You grant that? - I suppose so, said Alice. - Well, then, - the Cat went on - you see, a dog growls when it's angry, and wags its tail when it's pleased. Now I growl when I'm pleased, and wag my tail when I'm angry. Therefore I'm mad."
Roof Top Pew Wee
Roof Top Pew Wee
Hey. I''ve been writing my own 2D engine that does probably what you''re looking to do with sprites. If you''re interested, you can IM me on AOL Instant Messenger. Screen name''s Army Sarj. If you want to make your own engine, and are looking to talk theory, I can help ya with that, since I''ve done 4 games/projects with sprites, and am currently working on 2 more.

--Vic--

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.