Class SubTexture2D#

Class Documentation#

class SubTexture2D#

Public Functions

SubTexture2D(std::string name, Ref<TRAP::Graphics::Texture> texture, const TRAP::Math::Vec2 &min, const TRAP::Math::Vec2 &max) noexcept#

Constructor.

Parameters:
  • name – Name for the sprite.

  • texture – Sprite sheet to use.

  • min – Min texture coordinates to use.

  • max – Max texture coordinates to use.

SubTexture2D(const SubTexture2D&) noexcept = default#

Copy constructor.

SubTexture2D(SubTexture2D&&) noexcept = default#

Move constructor.

SubTexture2D &operator=(const SubTexture2D&) noexcept = default#

Copy assignment operator.

SubTexture2D &operator=(SubTexture2D&&) noexcept = default#

Move assignment operator.

~SubTexture2D() = default#

Destructor.

Ref<TRAP::Graphics::Texture> GetTexture() const noexcept#

Retrieve the used sprite sheet texture.

Returns:

Sprite sheet texture.

constexpr const std::array<TRAP::Math::Vec2, 4> &GetTexCoords() const noexcept#

Retrieve the texture coordinates for this sub texture.

Returns:

Texture coordinates.

constexpr std::string GetName() noexcept#

Retrieve the name of the sprite.

Returns:

Name of the sprite.

constexpr const std::string &GetName() const noexcept#

Retrieve the name of the sprite.

Returns:

Name of the sprite.

Public Static Functions

static TRAP::Ref<SubTexture2D> CreateFromCoords(std::string name, Ref<TRAP::Graphics::Texture> texture, const TRAP::Math::Vec2 &coords, const TRAP::Math::Vec2 &cellSize, const TRAP::Math::Vec2 &spriteSize = {1.0f, 1.0f})#

Create a 2D sub texture from a texture and the given coordinates and sprite size.

Parameters:
  • name – Name for the sprite.

  • texture – Sprite sheet texture.

  • coords – The coordinates for the sub texture.

  • cellSize – Size the sprite in pixels (16x16 for example).

  • spriteSizeOptional: Multiplier for the cell size (allows to use multi cell sprites as a single sprite).

Returns:

Created 2D sub texture.

static TRAP::Ref<SubTexture2D> CreateFromPixels(std::string name, Ref<TRAP::Graphics::Texture> texture, const TRAP::Math::Vec2 &pixelPos, const TRAP::Math::Vec2 &pixelSize, const TRAP::Math::Vec2 &spriteSize = {1.0f, 1.0f})#

Create a 2D sub texture from a texture and the given pixel coordinates and size.

Parameters:
  • name – Name for the sprite.

  • texture – Sprite sheet texture.

  • pixelPos – Position of the top-left corner of the sprite.

  • pixelSize – Size of the sprite in pixels

  • spriteSizeOptional: Multiplied for the pixel size (allows to use multi cell sprites as a single sprite).

Returns:

Created 2D sub texture.