Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


2D Game Animation?

This topic is 5490 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

For my first 2D game, I''ve implemented a basic sprite class, and it looks like this:
class CSprite
	CSprite(char *filename);

	int load(char *filename);
	void move(int x, int y);

	friend class CVideo;

	SDL_Surface *_sprite;
	SDL_Rect _pos;
Pretty basic, eh? Now I have a video class (CVideo) that is responsible for blitting CSprites:
class CVideo
	int init(int width, int height, int bit_depth);
	void kill();
	void blit(CSprite *tsprite);
	void start_blit();
	void end_blit();

	int _width;
	int _height;
	int _bit_depth;
	SDL_Surface *_screen;
	bool _locked;
	bool _must_lock;
Still pretty basic. But it''s about to get a lot more complex (unnecessarily, I hope). What I wanted to do was to be able to have a templated sprite (i.e., an image with a grid of frames that make up the animations) and each frame in the template would have a frame number. Then when I would want to display an animation, I would make an array of integers that express the order of the frames I want to blit in order to show an animation. I would pass that array to a function, which would store it in some sort of list. The blitter function would read the list and render the corresponding frame, and then move onto the next element on the list. It''s getting pretty tough to code that, so I''m wondering if there is an easier way to do animated sprites and templates. I''ve gotten so far as to be able to break down an image into frames, but I''m stuck at the part where I store the stuff in a list (mostly because I have no clue how to work STL in order to use their built-in list). So does anyone know of a simpler way to do this stuff? Or help me do it the current way I''m doing it? I''ll post more code if you need me to. Thanks!

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
Go look at the lessons at cone3d.gamedev.net. He used SDL, but is Sprite class setup was a little different from yours.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!