O'Reilly logo

Mastering SFML Game Development by Raimondas Pupius

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

Sprite system

Since we're working on a 2D game, the most likely candidate for the way graphics are going to be done is a sprite sheet. Unifying the way sprite sheet cropping and animations are handled is key to not only minimizing code, but also creating a simple, neat interface that's easy to interact with. Let us take a look at how that can be done:

class SpriteSheet{ public: ... void CropSprite(const sf::IntRect& l_rect); const sf::Vector2u& GetSpriteSize()const; const sf::Vector2f& GetSpritePosition()const; void SetSpriteSize(const sf::Vector2u& l_size); void SetSpritePosition(const sf::Vector2f& l_pos); void SetDirection(const Direction& l_dir); Direction GetDirection() const; void SetSheetPadding(const sf::Vector2f& l_padding); void SetSpriteSpacing(const ...

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