jade-engine
0.0
|
#include <Sprite.h>
Public Member Functions | |
Sprite (const SpriteParams ¶ms) | |
Sprite (const ObjectLayer layer, std::shared_ptr< Texture > texture, const int32_t z) | |
void | Render (SDL_Renderer *renderer) override |
void | Clean () override |
void | Tint (const SDL_Color &tintColor) |
void | SetAlpha (const float alpha) |
void | MakeTextureUnique () |
virtual float | GetAlpha () const |
void | SetRotation (const double angle) |
virtual bool | HitTest (const int32_t x, const int32_t y) const |
virtual bool | HasHitTest () const |
void | SetSampling (const TextureSampling sampling) |
void | SetSpriteSheetSprite (const std::string &sprite) |
void | SetSpriteSheetMask (const Rectangle &mask) |
const std::string & | GetTextureName () const |
![]() | |
IGameObject () | |
virtual void | Update () |
virtual LoadState | Load (SDL_Renderer *renderer) |
LoadState | GetLoadState () const |
void | SetLoadState (const LoadState newState) |
bool | IsShown () const |
virtual void | Show (const bool show) |
int32_t | GetZ () const |
void | Destroy () |
bool | DestructionWanted () const |
Protected Attributes | |
std::shared_ptr< Texture > | _textureDescription |
const detail::SpriteSheetDescription * | _spriteSheetDescription |
SDL_Texture * | _texture |
bool | _spriteSheetMasked |
Rectangle | _spriteSheetMask |
std::string | _textureName |
bool | _rotated |
float | _alpha |
double | _rotationAngle |
ObjectLayer | _layer |
![]() | |
LoadState | _loadState |
bool | _shown |
int32_t | _z |
Additional Inherited Members | |
![]() | |
const std::shared_ptr< Transform > | transform |
Game object that renders a texture on screen.
JadeEngine::Sprite::Sprite | ( | const SpriteParams & | params | ) |
Constructor for Sprite that accepts SpriteParams.
Game::Create
function to create Sprites instead of constructing the object directly.JadeEngine::Sprite::Sprite | ( | const ObjectLayer | layer, |
std::shared_ptr< Texture > | texture, | ||
const int32_t | z | ||
) |
Utility constructor for Sprites where their texture is already known and created elsewhere.
Game::Create
function to create Sprites instead of constructing the object directly.Used internally by the Jade Engine and most likely of limited use otherwise.
|
overridevirtual |
Triggered when the game object is about to be destroyed or reset.
All resources belonging solely to the game object, such as textures, should be released at this point. The game object instance itself may or may not be destroyed after this callback.
Reimplemented from JadeEngine::IGameObject.
|
virtual |
Return the current transparency alpha value.
const std::string & JadeEngine::Sprite::GetTextureName | ( | ) | const |
Return the texture name that the sprite is rendering. In the case of sprite-sheet sprite it is the texture name of one of the packed textures.
|
virtual |
Return whether the sprite's texture was initialized with hit map.
Reimplemented in JadeEngine::BoxSprite.
|
virtual |
Perform a hit test, returning whether a pixel of the sprite is not empty (not completely transparent, alpha > 0).
void JadeEngine::Sprite::MakeTextureUnique | ( | ) |
Create a deep-copy of the Sprite texture that is not shared with other Sprites using the same texture.
This operation is necessary for Sprite::Tint
and Sprite::SetAlpha
and will be called automatically on their first call unless already called by the user.
Game::CopyTexture
.
|
overridevirtual |
Triggered every frame while the scene that owns this game object is active, the game object was successfully loaded and the game object is shown.
The trigger order is the following: IScene::PreUpdate -> IGameObject::Load -> IGameObject::Update -> IScene::Update -> IGameObject::Load -> IGameObject::Render.
renderer | The engine's SDL2 renderer that should be used to render the game object. |
Reimplemented from JadeEngine::IGameObject.
Reimplemented in JadeEngine::TextSprite.
void JadeEngine::Sprite::SetAlpha | ( | const float | alpha | ) |
Changed the transparency of the sprite.
MakeTextureUnique
is called which is potentially expensive operation. Consider calling MakeTextureUnique
explicitly during initialization to avoid flickering. alpha | Transparency alpha value to set. 0 will make the sprite completely invisible, 1 fully opaque. It will be clamped to [0.0f, 1.0f] range. |
void JadeEngine::Sprite::SetRotation | ( | const double | angle | ) |
Set the rotation the sprite will rendered with.
The rotation center will be the center of the sprite, i.e. GetWidth() / 2 and GetHeight() / 2. This only affects the rendering of the sprite and not its transform.
angle | Rotational angle in degrees in a clockwise direction. |
void JadeEngine::Sprite::SetSampling | ( | const TextureSampling | sampling | ) |
Change the sampling of the texture.
void JadeEngine::Sprite::SetSpriteSheetMask | ( | const Rectangle & | mask | ) |
Change the what rectangle of the sprite-sheet is used for rendering the sprite.
As sprite-sheets are collections of texture it is recommended to use Sprite::SetSpriteSheetSprite instead of directly specifying the rectangle.
void JadeEngine::Sprite::SetSpriteSheetSprite | ( | const std::string & | sprite | ) |
Change the sprite's texture to a different texture that is part of the same sprite-sheet.
Useful for simple frame-based animations of sprites. Nothing happens if the new texture is not found.
sprite | Name of the new texture as defined by the sprite-sheet. Usually original file name of the texture before packing into sprite-sheet. |
void JadeEngine::Sprite::Tint | ( | const SDL_Color & | tintColor | ) |
Tint the sprite with a single color.
MakeTextureUnique
is called which is potentially expensive operation. Consider calling MakeTextureUnique
explicitly during initialization to avoid flickering. tintColor | RGBA 0-255 color that will be used to multiply each pixel of the sprite. Alpha component is ignored. |