Open 3D Engine LyShine Gem API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
CSprite Class Reference

Inherits ISprite, and TextureAtlasNamespace::TextureAtlasNotificationBus::Handler.

Public Member Functions

 CSprite ()
 Construct an empty sprite.
 
const AZStd::string & GetPathname () const override
 Get the pathname of this sprite.
 
const AZStd::string & GetTexturePathname () const override
 Get the pathname of the texture of this sprite.
 
Borders GetBorders () const override
 Get the borders of this sprite.
 
void SetBorders (Borders borders) override
 Set the borders of this sprite.
 
void SetCellBorders (int cellIndex, Borders borders) override
 Set the borders of a given cell within the sprite-sheet.
 
void Serialize (TSerialize ser) override
 Serialize this object for save/load.
 
bool SaveToXml (const AZStd::string &pathname) override
 Save this sprite data to disk.
 
bool AreBordersZeroWidth () const override
 Test if this sprite has any borders.
 
bool AreCellBordersZeroWidth (int index) const override
 Tests if the sprite-sheet cell has borders.
 
AZ::Vector2 GetSize () override
 Get the dimensions of the sprite.
 
AZ::Vector2 GetCellSize (int cellIndex) override
 Gets the dimensions of a specific cell texture within a sprite-sheet.
 
const SpriteSheetCellContainer & GetSpriteSheetCells () const override
 Gets cell info for each of the cells within the sprite-sheet.
 
void SetSpriteSheetCells (const SpriteSheetCellContainer &cells) override
 Sets the sprite's sprite-sheet cells.
 
void ClearSpriteSheetCells () override
 Removes all sprite-sheet cell info for this sprite.
 
void AddSpriteSheetCell (const SpriteSheetCell &spriteSheetCell) override
 Defines a new SpriteSheetCell for this sprite.
 
AZ::Vector2 GetCellUvSize (int cellIndex) const override
 Gets the dimensions of a specific cell (in a sprite-sheet) in UV coords (UV range).
 
UiTransformInterface::RectPoints GetCellUvCoords (int cellIndex) const override
 Gets the UV coords associated for a given cell in a sprite-sheet.
 
UiTransformInterface::RectPoints GetSourceCellUvCoords (int cellIndex) const override
 Gets the UV coords associated for a given cell in a sprite-sheet in a way that ignores texture atlases.
 
Borders GetCellUvBorders (int cellIndex) const override
 
Borders GetTextureSpaceCellUvBorders (int cellIndex) const override
 
const AZStd::string & GetCellAlias (int cellIndex) const override
 Gets the string alias associated with the given cell in a sprite-sheet.
 
void SetCellAlias (int cellIndex, const AZStd::string &cellAlias) override
 Sets the string alias associated with the given cell in a sprite-sheet.
 
int GetCellIndexFromAlias (const AZStd::string &cellAlias) const override
 Returns the sprite-sheet cell index that corresponds to the given string alias.
 
bool IsSpriteSheet () const override
 Returns true if this sprite is configured as a sprite-sheet, false otherwise.
 
AZ::Data::Instance< AZ::RPI::Image > GetImage () override
 
void OnAtlasLoaded (const TextureAtlasNamespace::TextureAtlas *atlas) override
 
void OnAtlasUnloaded (const TextureAtlasNamespace::TextureAtlas *atlas) override
 
- Public Member Functions inherited from ISprite
virtual ~ISprite ()
 Deleting a sprite will release its texture.
 
virtual const AZStd::string & GetPathname () const =0
 Get the pathname of this sprite.
 
virtual const AZStd::string & GetTexturePathname () const =0
 Get the pathname of the texture of this sprite.
 
virtual Borders GetBorders () const =0
 Get the borders of this sprite.
 
virtual void SetBorders (Borders borders)=0
 Set the borders of this sprite.
 
virtual void SetCellBorders (int cellIndex, Borders borders)=0
 Set the borders of a given cell within the sprite-sheet.
 
virtual void Serialize (TSerialize ser)=0
 Serialize this object for save/load.
 
virtual bool SaveToXml (const AZStd::string &pathname)=0
 Save this sprite data to disk.
 
virtual bool AreBordersZeroWidth () const =0
 Test if this sprite has any borders.
 
virtual bool AreCellBordersZeroWidth (int cellIndex) const =0
 Tests if the sprite-sheet cell has borders.
 
virtual AZ::Vector2 GetSize ()=0
 Get the dimensions of the sprite.
 
virtual AZ::Vector2 GetCellSize (int cellIndex)=0
 Gets the dimensions of a specific cell texture within a sprite-sheet.
 
virtual const SpriteSheetCellContainer & GetSpriteSheetCells () const =0
 Gets cell info for each of the cells within the sprite-sheet.
 
virtual void SetSpriteSheetCells (const SpriteSheetCellContainer &cells)=0
 Sets the sprite's sprite-sheet cells.
 
virtual void ClearSpriteSheetCells ()=0
 Removes all sprite-sheet cell info for this sprite.
 
virtual void AddSpriteSheetCell (const SpriteSheetCell &spriteSheetCell)=0
 Defines a new SpriteSheetCell for this sprite.
 
virtual AZ::Vector2 GetCellUvSize (int cellIndex) const =0
 Gets the dimensions of a specific cell (in a sprite-sheet) in UV coords (UV range).
 
virtual UiTransformInterface::RectPoints GetCellUvCoords (int cellIndex) const =0
 Gets the UV coords associated for a given cell in a sprite-sheet.
 
virtual UiTransformInterface::RectPoints GetSourceCellUvCoords (int cellIndex) const =0
 Gets the UV coords associated for a given cell in a sprite-sheet in a way that ignores texture atlases.
 
virtual Borders GetCellUvBorders (int cellIndex) const =0
 
virtual Borders GetTextureSpaceCellUvBorders (int cellIndex) const =0
 
virtual const AZStd::string & GetCellAlias (int cellIndex) const =0
 Gets the string alias associated with the given cell in a sprite-sheet.
 
virtual void SetCellAlias (int cellIndex, const AZStd::string &cellAlias)=0
 Sets the string alias associated with the given cell in a sprite-sheet.
 
virtual int GetCellIndexFromAlias (const AZStd::string &cellAlias) const =0
 Returns the sprite-sheet cell index that corresponds to the given string alias.
 
virtual bool IsSpriteSheet () const =0
 Returns true if this sprite is configured as a sprite-sheet, false otherwise.
 
virtual AZ::Data::Instance< AZ::RPI::Image > GetImage ()=0
 

Static Public Member Functions

static void Initialize ()
 
static void Shutdown ()
 
static CSpriteLoadSprite (const AZStd::string &pathname)
 
static CSpriteCreateSprite (const AZ::Data::Asset< AZ::RPI::AttachmentImageAsset > &attachmentImageAsset)
 
static bool DoesSpriteTextureAssetExist (const AZStd::string &pathname)
 
static void ReplaceSprite (ISprite **baseSprite, ISprite *newSprite)
 Replaces baseSprite with newSprite with proper ref-count handling and null-checks.
 
static bool FixUpSourceImagePathFromUserDefinedPath (const AZStd::string &userDefinedPath, AZStd::string &sourceImagePath)
 
static AZStd::string GetImageSourcePathFromProductPath (const AZStd::string &productPathname)
 

Protected Member Functions

bool CellIndexWithinRange (int cellIndex) const
 

Additional Inherited Members

- Public Types inherited from ISprite
using SpriteSheetCellContainer = AZStd::vector< SpriteSheetCell >
 

Member Function Documentation

◆ AddSpriteSheetCell()

void CSprite::AddSpriteSheetCell ( const SpriteSheetCell spriteSheetCell)
overridevirtual

Defines a new SpriteSheetCell for this sprite.

Implements ISprite.

◆ AreBordersZeroWidth()

bool CSprite::AreBordersZeroWidth ( ) const
overridevirtual

Test if this sprite has any borders.

Implements ISprite.

◆ AreCellBordersZeroWidth()

bool CSprite::AreCellBordersZeroWidth ( int  cellIndex) const
overridevirtual

Tests if the sprite-sheet cell has borders.

Implements ISprite.

◆ ClearSpriteSheetCells()

void CSprite::ClearSpriteSheetCells ( )
overridevirtual

Removes all sprite-sheet cell info for this sprite.

Implements ISprite.

◆ FixUpSourceImagePathFromUserDefinedPath()

static bool CSprite::FixUpSourceImagePathFromUserDefinedPath ( const AZStd::string &  userDefinedPath,
AZStd::string &  sourceImagePath 
)
static

Pathname allows any of the following:

  1. image source/product path (will use pathname to look for an existing .sprite sidecar file)
  2. .sprite source/product path (will use pathname to look for an existing image file with a supported extension)
  3. legacy .dds product path (will use pathname to look for an existing texture file with a supported extension)

◆ GetBorders()

Borders CSprite::GetBorders ( ) const
overridevirtual

Get the borders of this sprite.

Implements ISprite.

◆ GetCellAlias()

const AZStd::string & CSprite::GetCellAlias ( int  cellIndex) const
overridevirtual

Gets the string alias associated with the given cell in a sprite-sheet.

Implements ISprite.

◆ GetCellIndexFromAlias()

int CSprite::GetCellIndexFromAlias ( const AZStd::string &  cellAlias) const
overridevirtual

Returns the sprite-sheet cell index that corresponds to the given string alias.

Implements ISprite.

◆ GetCellSize()

AZ::Vector2 CSprite::GetCellSize ( int  cellIndex)
overridevirtual

Gets the dimensions of a specific cell texture within a sprite-sheet.

Implements ISprite.

◆ GetCellUvBorders()

Borders CSprite::GetCellUvBorders ( int  cellIndex) const
overridevirtual

Gets the sliced border info for a given cell within a sprite-sheet.

The returned UV borders are in "cell space" relative to the given indexed spell. For example, a top-left border of (0.5, 0.5) would be the center of the given cell.

Implements ISprite.

◆ GetCellUvCoords()

UiTransformInterface::RectPoints CSprite::GetCellUvCoords ( int  cellIndex) const
overridevirtual

Gets the UV coords associated for a given cell in a sprite-sheet.

Implements ISprite.

◆ GetCellUvSize()

AZ::Vector2 CSprite::GetCellUvSize ( int  cellIndex) const
overridevirtual

Gets the dimensions of a specific cell (in a sprite-sheet) in UV coords (UV range).

Implements ISprite.

◆ GetImage()

AZ::Data::Instance< AZ::RPI::Image > CSprite::GetImage ( )
overridevirtual

Implements ISprite.

◆ GetPathname()

const AZStd::string & CSprite::GetPathname ( ) const
overridevirtual

Get the pathname of this sprite.

Implements ISprite.

◆ GetSize()

AZ::Vector2 CSprite::GetSize ( )
overridevirtual

Get the dimensions of the sprite.

Implements ISprite.

◆ GetSourceCellUvCoords()

UiTransformInterface::RectPoints CSprite::GetSourceCellUvCoords ( int  cellIndex) const
overridevirtual

Gets the UV coords associated for a given cell in a sprite-sheet in a way that ignores texture atlases.

Implements ISprite.

◆ GetSpriteSheetCells()

const SpriteSheetCellContainer & CSprite::GetSpriteSheetCells ( ) const
overridevirtual

Gets cell info for each of the cells within the sprite-sheet.

Implements ISprite.

◆ GetTexturePathname()

const AZStd::string & CSprite::GetTexturePathname ( ) const
overridevirtual

Get the pathname of the texture of this sprite.

Implements ISprite.

◆ GetTextureSpaceCellUvBorders()

Borders CSprite::GetTextureSpaceCellUvBorders ( int  cellIndex) const
overridevirtual

Gets the sliced border UV coordinates in texture space for a given cell within a sprite-sheet.

The returned UV border coordinates are in texture space. For example, a top-left border of (0.5, 0.5) would be the center of the sprite-sheet.

Implements ISprite.

◆ IsSpriteSheet()

bool CSprite::IsSpriteSheet ( ) const
overridevirtual

Returns true if this sprite is configured as a sprite-sheet, false otherwise.

Implements ISprite.

◆ SaveToXml()

bool CSprite::SaveToXml ( const AZStd::string &  pathname)
overridevirtual

Save this sprite data to disk.

Implements ISprite.

◆ Serialize()

void CSprite::Serialize ( TSerialize  ser)
overridevirtual

Serialize this object for save/load.

Implements ISprite.

◆ SetBorders()

void CSprite::SetBorders ( Borders  borders)
overridevirtual

Set the borders of this sprite.

Implements ISprite.

◆ SetCellAlias()

void CSprite::SetCellAlias ( int  cellIndex,
const AZStd::string &  cellAlias 
)
overridevirtual

Sets the string alias associated with the given cell in a sprite-sheet.

Implements ISprite.

◆ SetCellBorders()

void CSprite::SetCellBorders ( int  cellIndex,
Borders  borders 
)
overridevirtual

Set the borders of a given cell within the sprite-sheet.

Implements ISprite.

◆ SetSpriteSheetCells()

void CSprite::SetSpriteSheetCells ( const SpriteSheetCellContainer &  cells)
overridevirtual

Sets the sprite's sprite-sheet cells.

Implements ISprite.


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