timbobsteve
Member
- Joined
- Oct 4, 2005
- Messages
- 301
Hi All,
I'm currently trying to extend my little SDL demo to include animations and I'm wondering how best to implement the classes to achieve this. Currently I have the following:
Engine
Entity
Player
The Engine runs the game loop and has a member "vector<Entity*> EntityList". On each loop it iterates through EntityList and calls EntityList[x].Update() and EntityList[x].Render(SDL_Surface* screen).
Currently the player has it's own SDL_Surface* that is just a blue square and just draws itself to the surface passed in Render(SDL_Surface*).
I want to throw animations into the mix, so I was thinking of having a new class called Sprite. In this class I would load a single animation (say player_walk.png) and set the size of each frame. I was going to do this for each animation that the player has to do, e.g.
Then on Update() I could set the *currentAnimation to be &walk if walking, &idle if idle etc. All the frame update stuff was going to be done in the Sprite class itself and the Player's Render(SDL_Surface*) function was just going to call currentAnimation->GetFrame() to return the current frame based on the animations position.
What do people think of this way of handling animation? Is it a bad/dodgy way of implementing animation? Are there better or easier methods?
Also, in the Sprite::Load() function I was going to pass a filename. In the file I would define all the sprite attributed, like frame speed, number of frames, width, height etc. Do you think having these values outside of the code is a good idea, or am I just asking for issues?
I appreciate any and all input, but be warned... I might not understand you
Cheers,
Dave / Timbobsteve
PS: If these entry-level queries are clogging up the Development thread, perhaps we can arrange a sub-forum of "Development" for the n00bs to play around in? Just a thought.
I'm currently trying to extend my little SDL demo to include animations and I'm wondering how best to implement the classes to achieve this. Currently I have the following:
Engine
Entity
Player
The Engine runs the game loop and has a member "vector<Entity*> EntityList". On each loop it iterates through EntityList and calls EntityList[x].Update() and EntityList[x].Render(SDL_Surface* screen).
Currently the player has it's own SDL_Surface* that is just a blue square and just draws itself to the surface passed in Render(SDL_Surface*).
I want to throw animations into the mix, so I was thinking of having a new class called Sprite. In this class I would load a single animation (say player_walk.png) and set the size of each frame. I was going to do this for each animation that the player has to do, e.g.
Code:
class Player {
....
private:
Sprite* currentAnimation;
Sprite walk;
Sprite jump;
Sprite idle;
....
};
What do people think of this way of handling animation? Is it a bad/dodgy way of implementing animation? Are there better or easier methods?
Also, in the Sprite::Load() function I was going to pass a filename. In the file I would define all the sprite attributed, like frame speed, number of frames, width, height etc. Do you think having these values outside of the code is a good idea, or am I just asking for issues?
I appreciate any and all input, but be warned... I might not understand you
Cheers,
Dave / Timbobsteve
PS: If these entry-level queries are clogging up the Development thread, perhaps we can arrange a sub-forum of "Development" for the n00bs to play around in? Just a thought.