Wraith  0.1.5
Basic 3D game engine in C++

A Sprite entity is used for displaying a 2D image on the screen. It can be used anywhere within a user defined GameObject. More...

Collaboration diagram for Sprite:

Functions

 Sprite::Sprite (const std::string &imageKey)
 Constructs sprite using image key defined within Image Manager. More...
 
void Sprite::render ()
 Renders this sprite. More...
 
void Sprite::setPosition (float positionX, float positionY)
 Sets sprite position. More...
 
float Sprite::getPositionX () const
 Gets position x coordinate. More...
 
void Sprite::setCenter (float centerX, float centerY)
 Sets sprite center. More...
 
void Sprite::setAngle (float angle)
 Sets sprite angle./ More...
 
float Sprite::getAngle () const
 Gets the sprite angle. More...
 
void Sprite::offsetAngle (float angleOffset)
 Offset sprite angle. More...
 
void Sprite::setScaleFactor (float scaleX, float scaleY)
 Sets scale factor. More...
 
void Sprite::setScalePixel (float width, float height)
 Sets scale pixel. More...
 
float Sprite::getWidth () const
 Gets the width of the sprite. More...
 
float Sprite::getHeight () const
 Gets the height of the sprite. More...
 

Detailed Description

A Sprite entity is used for displaying a 2D image on the screen. It can be used anywhere within a user defined GameObject.

The Sprite's constructor must take in a imageKey, a key used to assign to a particular image within the ImageManager, in order to create Sprite entity.

IMPORTANT: To render a Sprite entity, it you must call Sprite::render() within the GameObject::draw2D() callback in order to display the sprite properly.

Here is an example of how a sprite can be used.

HUD::HUD()
{
_pHeartSprite = new Sprite("HeartImage");
_pHeartSprite->setPosition(50, 100);
_pLoadingSprite = new Sprite("LoadingImage");
_pLoadingSprite->setPosition(10, 100);
// IMPORTANT: Submit Draw 2D Registration
// Other registrations (not really needed for sprite)
GameObject::submitUpdateRegistraion();
}
void HUD::update()
{
_pLoadingSprite->offsetAngle(0.05f);
}
void HUD::draw2D()
{
// IMPORTANT: if two sprites overlap each other
// the one that gets drawn on top is the sprite
// who's Sprite::render() was called last
_pLoadingSprite->render();
_pHeartSprite->render();
}
A sprite used to display 2D images.
Definition: Sprite.h:18
void submitDraw2DRegistration()
Submit draw 2D registration to current scene.
Definition: Drawable.cpp:60

Function Documentation

◆ getAngle()

float Sprite::getAngle ( ) const

Gets the sprite angle.

angle is in radians.

Returns
The angle.

◆ getHeight()

float Sprite::getHeight ( ) const

Gets the height of the sprite.

Returns
The height.

◆ getPositionX()

float Sprite::getPositionX ( ) const

Gets position x coordinate.

Returns
The position x coordinate.

◆ getWidth()

float Sprite::getWidth ( ) const

Gets the width of the sprite.

Returns
The width.

◆ offsetAngle()

void Sprite::offsetAngle ( float  angleOffset)

Offset sprite angle.

angle offset is in radians.

Parameters
angleOffsetThe angle offset.

◆ render()

void Sprite::render ( )

Renders this sprite.

must be called within GameObject::draw2D() of the user derived GameObject entity.

◆ setAngle()

void Sprite::setAngle ( float  angle)

Sets sprite angle./

angle is in radians.

Parameters
angleThe angle.

◆ setCenter()

void Sprite::setCenter ( float  centerX,
float  centerY 
)

Sets sprite center.

the (0, 0) center is the actual center of the sprite image.

Parameters
centerXThe center x coordinate.
centerYThe center y coordinate.

◆ setPosition()

void Sprite::setPosition ( float  positionX,
float  positionY 
)

Sets sprite position.

The (0, 0) position is the lower left corner of the screen.

Parameters
positionXThe position x coordinate.
positionYThe position y coordinate.

◆ setScaleFactor()

void Sprite::setScaleFactor ( float  scaleX,
float  scaleY 
)

Sets scale factor.

Parameters
scaleXThe X scale factor.
scaleYThe Y scale factor.

◆ setScalePixel()

void Sprite::setScalePixel ( float  width,
float  height 
)

Sets scale pixel.

Parameters
widthThe width.
heightThe height.

◆ Sprite()

Sprite::Sprite ( const std::string &  imageKey)

Constructs sprite using image key defined within Image Manager.

The key is one that used to assign a particular image in ImageManager.

Parameters
imageKeyThe image key.