• Create Account

### #Actualbglanzer

Posted 17 June 2012 - 09:43 PM

In the case of your sprite I think its pretty good. Here is simple quick example of a sprite class I did in the past, just to give you an example of animated sprites

Hopefully the classes are understandable. Pretty much because animations can run at different speeds and a sprite can have many different animations you want to separate your sprite animations. Also it makes it easier to put things like positions and scale into class called Transform which is derived from a Component class. Then allow additional
components to be added that hold things like velocity, speed, bounding box, etc.

Currently what you have is good. But when you want to create more complex sprites below is a structure that worked for me.

****EDIT**** On second thought you might want Transform and Component under a GameObject class which Sprite is derived from.

class SpriteAnimation {
public:
//Set methods, Get methods, update method
protected:
int m_iCellWidth;
int m_iCellHeight;
int m_iFirstFrame;
int m_iLastFrame;
int m_iCurrentFrame;
int m_iAnimationDirection; // 1 for forward -1 for backward

bool m_bLoop;
bool m_bAnimating;
bool m_bCustomFrameList;

float m_fFrameDelay;
float m_fTimer;
TArray<int> customFrameArray;
};

class Sprite {
public:
//Constructors, Destructors, Setters, Getters
bool AddAnimation( SpriteAnimation* animation );
bool AddComponent( Component* component);

protected:
Transform m_transform; //transform hold position, scale, ect
TArray<Component *> m_components; //Holds any components
TArray<SpriteAnimations *> m_animations; //holds all animations
};


### #1bglanzer

Posted 17 June 2012 - 09:41 PM

In the case of your sprite I think its pretty good. Here is simple quick example of a sprite class I did in the past, just to give you an example of animated sprites

Hopefully the classes are understandable. Pretty much because animations can run at different speeds and a sprite can have many different animations you want to separate your sprite animations. Also it makes it easier to put things like positions and scale into class called Transform which is derived from a Component class. Then allow additional
components to be added that hold things like velocity, speed, bounding box, etc.

Currently what you have is good. But when you want to create more complex sprites below is a structure that worked for me.

class SpriteAnimation {
public:
//Set methods, Get methods, update method
protected:
int m_iCellWidth;
int m_iCellHeight;
int m_iFirstFrame;
int m_iLastFrame;
int m_iCurrentFrame;
int m_iAnimationDirection; // 1 for forward -1 for backward

bool m_bLoop;
bool m_bAnimating;
bool m_bCustomFrameList;

float m_fFrameDelay;
float m_fTimer;
TArray<int> customFrameArray;
};

class Sprite {
public:
//Constructors, Destructors, Setters, Getters
bool AddAnimation( SpriteAnimation* animation );
bool AddComponent( Component* component);

protected:
Transform m_transform; //transform hold position, scale, ect
TArray<Component *> m_components; //Holds any components
TArray<SpriteAnimations *> m_animations; //holds all animations
};


PARTNERS