O'Reilly logo

Procedural Content Generation for C++ Game Development by Dale Green

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a SpriteComponent

The next component that we're going to make is a SpriteComponent. This will provide an object with either a static or an animated sprite. It's a behavior that is commonly reused through many objects so is a great candidate to be moved into a component.

Encapsulating sprite behavior

Currently, all the animation-related behavior is inherited from the base Object class. The following code consists of all the sprite- and animation-related functions and variables that we'll pull from Object into its own class:

public: virtual void Draw(sf::RenderWindow &window, float timeDelta); bool SetSprite(sf::Texture& texture, bool isSmooth, int frames = 1, int frameSpeed = 0); sf::Sprite& GetSprite(); int GetFrameCount() const; bool IsAnimated(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required