Sprite Class Design
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" Kozhukhov
CEO & Lead programmer
Choco Snow Creation
dkcscPortal
=============================
=============================Denis "Mr.Snow" KozhukhovCEO & Lead programmerChoco Snow CreationdkcscPortal=============================
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;
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.
My FrameSet is designed to handle either individual frames, but I usually load in a single, large bitmap and then divide it up.
--- Official D Blog | Learning D | The One With D | D Bits
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement