The sprite component renders a texture to the screen.
Example usage:
std::shared_ptr<Node> spriteNode = std::make_shared<Node>("spriteNode");
std::shared_ptr<Sprite> sprite = std::make_shared<Sprite>("res://path/to/texture.png", window);
spriteNode->addComponent(sprite);
Properties and usages
You can also modify it's origin:
sprite->origin = {0.0f, 0.0f}
The sprites Texture also has a width and height attribute. These define the size of the final rendered texture on the screen.
sprite->texture.width = 64;
sprite->texture.height = 64;
When you define the sprite, you can also define the TextureScaling mode:
std::shared_ptr<Sprite> sprite = std::make_shared<Sprite>(
"res://path/to/texture.png", window,
TextureScaling::PIXELART);
You can also define the sprites source rectangle in a texture atlas. This allows you to pack a bunch of textures in one image which you can load all at once!
Definition definitions.hpp:294
Definition definitions.hpp:77
Sprites also have a modulate property, which allows you to modify their color when theyre rendered:
static const Color BLUE
Definition definitions.hpp:62
You can also make sprites render using screen space positioning. This can be used for UI elements and things like that:
sprite->screenSpace = true;
Sprites also define flipH and flipV variables. You can use these when animating a sprite, for example.
Make sure to also check out the atlas example!