Dualie
Loading...
Searching...
No Matches
dl::Sprite Class Reference

A class used to handle the drawing and transformation of sprites. More...

#include <Sprite.hpp>

Inheritance diagram for dl::Sprite:
Collaboration diagram for dl::Sprite:

Public Member Functions

void loadFromSpriteSheet (SpriteSheet spriteSheet, size_t index)
 Loads an image into the sprite from a spritesheet.
 
void setPosition (const dl::Vector2f &position) override
 Sets the position of the sprite.
 
void move (const dl::Vector2f &offset) override
 Moves the sprite offset number of pixels.
 
void setOrigin (const dl::Vector2f &origin)
 Sets the rotation of the sprite in radians.
 
void setOrigin (float x, float y)
 Sets the origin of the shape. The default origin is (0,0) and is the top left pixel of the shape bounds. Setting the origin can affect where the shape is drawn. For instance, setting the origin to be half the shape size will cause the shape to be centered on its position.
 
void setRotation (const float &rotation)
 Sets the rotation of the sprite.
 
const dl::Vector2fgetOrigin ()
 
const float & getRotation ()
 
void rotate (const float &rotationOffset)
 Rotates the sprite on top of its current rotation.
 
void draw (const dl::Vector2f &viewOffset) override
 Draws the drawable to the screen.
 
- Public Member Functions inherited from dl::Transformable
void setPosition (float x, float y)
 Sets the position of the transformable.
 
void move (float xOffset, float yOffset)
 Moves the transformable offset number of pixels.
 
const dl::Vector2fgetPosition () const
 
- Public Member Functions inherited from dl::Drawable
void viewShouldAffect (bool effective)
 Set whether the current view should affect the position of the drawable. Otherwise, its position on the screen will be absolute.
 
void setDepth (float depth)
 Sets the depth of the drawable for 3d. This simply corresponds to the X offset calculated for the 2 separate top screens. Larger objects will require a deeper depth for the 3d effect to be noticable. A positive value will cause the drawable to sink into the screen, while a negative value will cause it to pop out.
 
const float & getDepth () const
 

Friends

C2D_SpriteSheet SpriteSheet::getSpriteSheet ()
 

Additional Inherited Members

- Protected Attributes inherited from dl::Transformable
dl::Vector2f m_position
 
- Protected Attributes inherited from dl::Drawable
bool m_bViewDoesAffect = true
 
float m_depth = 0.0f
 

Detailed Description

A class used to handle the drawing and transformation of sprites.

Member Function Documentation

◆ draw()

void dl::Sprite::draw ( const dl::Vector2f & viewOffset)
overridevirtual

Draws the drawable to the screen.

Parameters
viewOffsetThe offset of the current view to be used for internal drawable positioning

Implements dl::Drawable.

◆ getOrigin()

const dl::Vector2f & dl::Sprite::getOrigin ( )
Returns
The origin in pixels

◆ getRotation()

const float & dl::Sprite::getRotation ( )
Returns
The sprite's rotation in radians

◆ loadFromSpriteSheet()

void dl::Sprite::loadFromSpriteSheet ( SpriteSheet spriteSheet,
size_t index )

Loads an image into the sprite from a spritesheet.

Parameters
spriteSheetThe spritesheet to target
indexThe image index of the spritesheet

◆ move()

void dl::Sprite::move ( const dl::Vector2f & offset)
overridevirtual

Moves the sprite offset number of pixels.

Parameters
offsetThe offset to move

Reimplemented from dl::Transformable.

◆ rotate()

void dl::Sprite::rotate ( const float & rotationOffset)

Rotates the sprite on top of its current rotation.

Parameters
rotationOffsetThe rotation in radians to rotate

◆ setOrigin() [1/2]

void dl::Sprite::setOrigin ( const dl::Vector2f & origin)

Sets the rotation of the sprite in radians.

Parameters
rotationThe rotation to set (in radians)

Sets the origin of the shape. The default origin is (0,0) and is the top left pixel of the shape bounds. Setting the origin can affect where the shape is drawn. For instance, setting the origin to be half the shape size will cause the shape to be centered on its position.

Parameters
originThe origin in pixels

◆ setOrigin() [2/2]

void dl::Sprite::setOrigin ( float x,
float y )

Sets the origin of the shape. The default origin is (0,0) and is the top left pixel of the shape bounds. Setting the origin can affect where the shape is drawn. For instance, setting the origin to be half the shape size will cause the shape to be centered on its position.

Parameters
xThe origin in pixels (X)
yThe origin in pixels (Y)

◆ setPosition()

void dl::Sprite::setPosition ( const dl::Vector2f & position)
overridevirtual

Sets the position of the sprite.

Parameters
positionThe position to set

Reimplemented from dl::Transformable.

◆ setRotation()

void dl::Sprite::setRotation ( const float & rotation)

Sets the rotation of the sprite.

Parameters
rotationThe rotation in radians

The documentation for this class was generated from the following files: