Advertisement

Sprite Class Design

Started by September 12, 2000 11:42 AM
4 comments, last by reaptide 24 years, 3 months ago
Hello everyone, I''m busily writing an isometric game engine and have come upon a rather nasty snag. I''ve no clue how to design my sprite class. I''ve got the basics like x and y position, the sprites velocity, etc... but don''t know how to properly handle the graphics. Should I use a large bitmap of sprites and use a RECT to blit the required sprite, or use a large bitmap of sprites and copy each frame of animation into their own frame or, or.... Ahhh!! Anyway I was wondering whether anyone had an example of a proper sprite class lying around. It would be a big help. Thanks, Reaptide
As I know one big surface would be better (and faster for ddraw) than number of smalls...




=============================
Denis "Mr.Snow" Kozhukhov
CEO & Lead programmer
Choco Snow Creation
dkcscPortal
=============================
=============================Denis "Mr.Snow" KozhukhovCEO & Lead programmerChoco Snow CreationdkcscPortal=============================
Advertisement
heres my sprite class, somewhat based on lamothe''s code..
    typedef class CSprite	//a sprite{	public:		~CSprite();			//destructor		int State;			//state of sprite	int AnimState;		//animation state if animated	int Attribs;		//attributes pertaining to the object (general)	int XPos,YPos;		//position of sprite	int XVel,YVel;		//velocity of sprite	int Acceleration;	//acceleration of sprite	int Width, Height;	//width + height of sprite	int CurrentFrame;	//current animation frame	int NumFrames;		//total number of animation frames	int CurrentAnim;	//index of current animation	int AnimCounter;	//used to time animation transitions	int AnimIndex;		//animation element index	int MaxAnimCount;	//number of cycles before animation	int *Animations[MAX_SPRITE_ANIMATIONS]; //animation sequences		RECT Images[MAX_SPRITE_FRAMES]; //the bitmap images	int Init(int XPos,int YPos,int Width,int Height,int NumFrames,int Attribs);	int LoadFrame(int Frame,int XPos,int YPos,int Mode);	int LoadFrames(int StartFrame,int NumFrames,int StartX,int StartY);	int Draw();	int Move();	int Animate();	int Collision();	}Sprite, *pSprite;    
You might also want to add a variable to keep track of parallex.
What I''ve done is to create a separate class (actually, struct -- I''m a C-type) which stores sprite frames, called a FrameSet. Each Sprite stores a pointer to the FrameSet which contains the images it will use. This way, instead of having, say, 100 orcs each with copies of orc images, all orcs instead share the orc FrameSet.

My FrameSet is designed to handle either individual frames, but I usually load in a single, large bitmap and then divide it up.
Check the referrence section. There are many arcticles with which you should become familiar. I would recomend taking a couple days and reading through most of them. If you have any questions, post... or email the authors.
There is no spoon.

This topic is closed to new replies.

Advertisement