Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Graphical Representation and Animations.  (Read 1189 times)

0 Members and 1 Guest are viewing this topic.

Veritas

  • Jr. Member
  • **
  • Posts: 79
    • View Profile
    • Email
Graphical Representation and Animations.
« on: April 23, 2014, 03:13:11 pm »
Lately I've been trying to separate graphics from logic on my game and so far things are looking good. One thing I am not sure how I should deal with is storing animation states and accessing them using a command system. How I am going about animations is that I have an Animation class that stores sf::IntRects which I use on the renderer to choose the correct part of the needed texture. In the beginning I thought that having an animation object as an attribute of the entity class would be ok since it's just a state and it doesn't contain actual graphical information. Something like this:

class Entity
{
public:
        Entity(sf::Vector2f, float);
        virtual ~Entity() = 0;

        void setPosition(sf::Vector2f);
        void setPosition(int, int);
        void move(sf::Vector2f);
        void move(int, int);
        sf::Vector2f getPosition() const;

        void setVelocity(sf::Vector2f);
        void setVelocity(int, int);
        void accelerate(sf::Vector2f);
        void accelerate(int, int);
        sf::Vector2f getVelocity() const;

        void setRotation(float);
        void rotate(sf::Vector2f);
        void rotate(float);
        float getRotation() const;
       
        Animation& getAnimationState() const;
        void update(float);
private:
        Animation mAnimation;
        sf::Vector2f mPosition;
        sf::Vector2f mVelocity;
        float mRotation;
};

This is how the basic drawEntity function works (it's the base for more specific drawing functions providing the texture files) :

void Renderer::DrawEntity(const Entity& entity, const char* file)
{
        sf::Texture& texture = mResourceManager.getTexture(file);
        texture.isSmooth();
        sf::Sprite sprite;
        sprite.setTexture(texture);
        sprite.setTextureRect(entity.getAnimationState().getCurrentFrame());
        sprite.setPosition(entity.Position);
        sprite.setRotation(entity.Rotation);
        mRenderWindow.draw(sprite);
}

Technically, storing an animation object to the entity class makes sense since it simply holds a state, however after exchanging some messages with Nexus I am having doubts whether I should store the actual animation object or use the pimpl idiom and store a pointer to it. Another option is to store the animation objects in a separate map but that probably complicate things.

Is the above an acceptable design and if not, how should I proceed ?
Any feedback is much appreciated!
« Last Edit: April 23, 2014, 03:14:52 pm by Veritas »
"Lasciate ogni speranza, voi ch'entrate"

 

anything