3DRadSpace 0.1.0Alpha
3DRadSpace is a free, simple to use, rapid application development game engine.
Loading...
Searching...
No Matches
Engine3DRadSpace.Objects.Sprite Class Reference

Represents a 2D sprite that can be drawn on the screen, with support for mouse hover and click interaction. More...

#include <Sprite.hpp>

Inheritance diagram for Engine3DRadSpace.Objects.Sprite:
Collaboration diagram for Engine3DRadSpace.Objects.Sprite:

Public Member Functions

 Sprite ()
ITexture2D GetTexture ()
 Sprite ()
 Default constructor.
 Sprite (const std::string &name, bool visible, const std::string &path, const Math::Vector2 &pos, const Math::Vector2 &scale, float depth=0.0, const Math::Vector2 &pivot=Math::Vector2::Zero(), float rotation=0.0f, bool flipU=false, bool flipV=false, const Math::Color &tintColor=Math::Colors::White)
 Constructs a sprite from a file path.
 Sprite (const std::string &name, bool visible, RefTexture2D resource, const Math::Vector2 &pos, const Math::Vector2 &scale, float depth=0.0, const Math::Vector2 &pivot=Math::Vector2::Zero(), float rotation=0.0f, bool flipU=false, bool flipV=false, const Math::Color &tintColor=Math::Colors::White)
 Constructs a sprite from a numerical asset identifier.
 Sprite (Sprite &&) noexcept=default
Sprite & operator= (Sprite &&) noexcept=default
Graphics::ITexture2D * GetSpriteImage ()
 Gets the underlying texture used by this sprite.
void SetSpriteImage (Graphics::ITexture2D *texture)
 Sets the underlying texture used by this sprite.
bool IsHovered () const noexcept
 Gets whether the sprite is currently hovered by the mouse cursor.
bool IsClicked () const noexcept
 Gets whether the sprite is currently clicked.
void ResetInputState () noexcept
 Resets the hover and click input state of the sprite.
void Initialize () override
 Sets up the input events (OnClick, OnMouseEnter, OnMouseLeave).
void Load () override
 Loads the texture asset.
void Load (const std::filesystem::path &path) override
 Loads a texture from a specified path.
void Update () override
 Updates the hover and click input state of the sprite.
void Draw2D () override
 Draws the sprite.
Reflection::UUID GetUUID () const noexcept override
 Gets the UUID of the Sprite type.
Gizmos::IGizmo * GetGizmo () const noexcept override
 Returns the gizmo associated with this object.
virtual ~Sprite ()=default
Public Member Functions inherited from Engine3DRadSpace.Objects.InstIObject2D
 InstIObject2D (IntPtr natPtr)
Public Member Functions inherited from Engine3DRadSpace.NatPtrWrapper
virtual void Dispose ()
Public Member Functions inherited from Engine3DRadSpace.Objects.IObject2D
virtual ~IObject2D ()=default
Public Member Functions inherited from Engine3DRadSpace.Objects.IObject
void Enable ()
void Disable ()
bool Switch ()
void Show ()
void Hide ()
bool SwitchVisibility ()
IObject GetChild (int idx)
int GetChildrenCount ()
void InternalInitialize (IGame *game)
 Called by ObjectsList to set the _game Game instance. If there are objects manually managed, this MUST be called before Initialize or EditorInitialize.
Graphics::IGraphicsDevice * GetGraphicsDeviceHandle () const noexcept
 Returns the graphics device handle associated with this object.
IGame * GetGame () const noexcept
 Gets the game that this object belongs to.
IObject * operator[] (size_t idxChild) const
 Returns the idx-th child of this object.
IObject * GetParent () const noexcept
 Returns the parent of this object.
void SetParent (IObject *newParent) noexcept
 Sets the parent of this object.
bool HasParent () const noexcept
 Checks if this object has a parent.
size_t GetChildrenCount () const noexcept
 Returns the number of children of this object.
virtual void Enable ()
 Enables this object.
virtual void Disable ()
 Disables this object.
virtual bool Switch ()
 Switched the enable/disable state of this object.
virtual void Show ()
 Shows this object.
virtual void Hide ()
 Hides this object.
virtual bool SwitchVisibility ()
 Switches the visibility state of this object.
void Uninitialize () override
 Called before the object has the destructor called.
virtual ~IObject ()
Public Member Functions inherited from Engine3DRadSpace.IInitializable
void Initialize ()
virtual ~IInitializable ()=default
Public Member Functions inherited from Engine3DRadSpace.IUpdateable
void Update ()
virtual ~IUpdateable ()=default
Public Member Functions inherited from Engine3DRadSpace.ILoadable
void Load ()
void Load (string path)
virtual ~ILoadable ()=default
Public Member Functions inherited from Engine3DRadSpace.IDrawable2D
void Draw2D ()
virtual ~IDrawable2D ()=default

Public Attributes

RefTexture2D Image
 Numerical reference to the texture asset used by this object.
Math::Color TintColor
 Tint colour applied to the sprite.
Math::RectangleF UVCoordinates = Math::RectangleF(0, 0, 1, 1)
 UV coordinates used to sample the sprite's texture.
Reflection::Event OnClick
 Executes when the sprite is clicked. Return value is ignored.
Reflection::Event OnMouseEnter
 Executes when the mouse cursor enters the sprite's bounds. Return value is ignored.
Reflection::Event OnMouseLeave
 Executes when the mouse cursor leaves the sprite's bounds. Return value is ignored.
Public Attributes inherited from Engine3DRadSpace.Objects.IObject2D
Math::Vector2 Position
 Position of this object in screen coordinates.
Math::Vector2 RotationCenter
 Rotation pivot.
Math::Vector2 Scale
 Scale of this object. Usually (1.0f, 1.0f).
Public Attributes inherited from Engine3DRadSpace.Objects.IObject
std::string Name
 Name of the object.
ChildObjectCollection Children
 Children of this object.

Protected Attributes

Graphics::ITexture2D * _texture
bool _hover
bool _click
Protected Attributes inherited from Engine3DRadSpace.NatPtrWrapper
IntPtr _handle
bool _disposed
Protected Attributes inherited from Engine3DRadSpace.Objects.IObject
IGame * _game = nullptr
Graphics::IGraphicsDevice * _device = nullptr
IObject * _parent = nullptr

Properties

bool FlipU [get, set]
 Flip the sprite horizontally.
bool FlipV [get, set]
 Flip the sprite vertically.
uint TextureID [get, set]
unsafe Color TintColor [get, set]
Properties inherited from Engine3DRadSpace.Objects.InstIObject2D
Vector2 Position [get, set]
Vector2 RotationCenter [get, set]
float Rotation [get, set]
Vector2 Scale [get, set]
float Depth [get, set]
Properties inherited from Engine3DRadSpace.NatPtrWrapper
IntPtr Handle [get]
Properties inherited from Engine3DRadSpace.Objects.IObject2D
Vector2 Position [get, set]
Vector2 RotationCenter [get, set]
Vector2 Scale [get, set]
float Depth [get, set]
 Z-depth for layering 2D objects.
float Rotation [get, set]
 Rotation in radians.
Properties inherited from Engine3DRadSpace.Objects.IObject
string Name [get, set]
bool Enabled [get, set]
 Is this object enabled?
bool Visible [get, set]
 Is this object visible?
Reflection.UUID UUID [get]
IGame Game [get]
IGraphicsDevice GraphicsDevice [get]
IGizmo Gizmo [get]
ObjectCollection Children [get]
IObject Parent [get, set]

Additional Inherited Members

Protected Member Functions inherited from Engine3DRadSpace.NatPtrWrapper
 NatPtrWrapper (IntPtr handle, Action< IntPtr > fnDestroy)
 NatPtrWrapper (Action< IntPtr > fnDestroy)
void Reset (IntPtr newObj)
void Dispose (bool disposing)
Protected Member Functions inherited from Engine3DRadSpace.Objects.IObject2D
 IObject2D (const std::string &name="", bool enabled=false, bool visible=false, const Math::Vector2 &pos=Math::Vector2::Zero(), const Math::Vector2 &scale=Math::Vector2(0.1f, 0.1f), float rotation=0.0f, const Math::Vector2 &pivot=Math::Vector2::Zero(), float depth=0.0f)
Protected Member Functions inherited from Engine3DRadSpace.Objects.IObject
 IObject (const std::string &name="Empty", bool enabled=false, bool visible=false)
 Default constructor used for reflection. Objects created with this constructor are initially invalid, until internalInitialize() is called.
 IObject (const IObject &) noexcept=delete
IObject & operator= (const IObject &) noexcept=delete
 IObject (IObject &&) noexcept=default
IObject & operator= (IObject &&) noexcept=default
Protected Member Functions inherited from Engine3DRadSpace.IInitializable
 IInitializable ()=default
 IInitializable (const IInitializable &) noexcept=default
IInitializable & operator= (const IInitializable &) noexcept=default
 IInitializable (IInitializable &&) noexcept=default
IInitializable & operator= (IInitializable &&) noexcept=default
Protected Member Functions inherited from Engine3DRadSpace.IUpdateable
 IUpdateable ()=default
 IUpdateable (const IUpdateable &) noexcept=default
IUpdateable & operator= (const IUpdateable &) noexcept=default
 IUpdateable (IUpdateable &&) noexcept=default
IUpdateable & operator= (IUpdateable &&) noexcept=default
Protected Member Functions inherited from Engine3DRadSpace.ILoadable
 ILoadable ()=default
 ILoadable (const ILoadable &) noexcept=default
ILoadable & operator= (const ILoadable &) noexcept=default
 ILoadable (ILoadable &&) noexcept=default
ILoadable & operator= (ILoadable &&) noexcept=default
Protected Member Functions inherited from Engine3DRadSpace.IDrawable2D
 IDrawable2D ()=default
 IDrawable2D (const IDrawable2D &)=default
IDrawable2D & operator= (const IDrawable2D &)=default
 IDrawable2D (IDrawable2D &&) noexcept=default
IDrawable2D & operator= (IDrawable2D &&) noexcept=default

Detailed Description

Represents a 2D sprite that can be drawn on the screen, with support for mouse hover and click interaction.

Constructor & Destructor Documentation

◆ Sprite() [1/5]

Sprite.Sprite ( )
inline

◆ Sprite() [2/5]

Default constructor.

◆ Sprite() [3/5]

Engine3DRadSpace.Objects.Sprite.Sprite ( const std::string & name,
bool visible,
const std::string & path,
const Math::Vector2 & pos,
const Math::Vector2 & scale,
float depth = 0.0,
const Math::Vector2 & pivot = Math::Vector2::Zero(),
float rotation = 0.0f,
bool flipU = false,
bool flipV = false,
const Math::Color & tintColor = Math::Colors::White )

Constructs a sprite from a file path.

Parameters
nameName of the object
visibleIs this object visible?
pathFile path to the texture
posPosition of the sprite
scaleScale of the sprite
depthDraw depth of the sprite
pivotPivot point of the sprite
rotationRotation of the sprite, in radians
flipUFlip the sprite horizontally
flipVFlip the sprite vertically
tintColorTint colour applied to the sprite

◆ Sprite() [4/5]

Engine3DRadSpace.Objects.Sprite.Sprite ( const std::string & name,
bool visible,
RefTexture2D resource,
const Math::Vector2 & pos,
const Math::Vector2 & scale,
float depth = 0.0,
const Math::Vector2 & pivot = Math::Vector2::Zero(),
float rotation = 0.0f,
bool flipU = false,
bool flipV = false,
const Math::Color & tintColor = Math::Colors::White )

Constructs a sprite from a numerical asset identifier.

Parameters
nameName of the object
visibleIs this object visible?
resourceNumerical asset identifier for the texture
posPosition of the sprite
scaleScale of the sprite
depthDraw depth of the sprite
pivotPivot point of the sprite
rotationRotation of the sprite, in radians
flipUFlip the sprite horizontally
flipVFlip the sprite vertically
tintColorTint colour applied to the sprite

◆ Sprite() [5/5]

◆ ~Sprite()

virtual Engine3DRadSpace.Objects.Sprite.~Sprite ( )
virtualdefault

Member Function Documentation

◆ Draw2D()

void Sprite::Draw2D ( )
overridevirtual

Draws the sprite.

Implements Engine3DRadSpace.IDrawable2D.

◆ GetGizmo()

Gizmos::IGizmo * Sprite::GetGizmo ( ) const
overridevirtualnoexcept

Returns the gizmo associated with this object.

Returns
Pointer to the gizmo

Implements Engine3DRadSpace.Objects.IObject.

◆ GetSpriteImage()

ITexture2D * Sprite::GetSpriteImage ( )

Gets the underlying texture used by this sprite.

Returns
Pointer to the underlying texture

◆ GetTexture()

ITexture2D Engine3DRadSpace.Objects.Sprite.GetTexture ( )
inline

◆ GetUUID()

Reflection::UUID Sprite::GetUUID ( ) const
overridevirtualnoexcept

Gets the UUID of the Sprite type.

Returns
{90239EA1-D02D-424C-90BB-15ABC5E5D55D}

Implements Engine3DRadSpace.Objects.IObject.

◆ Initialize()

void Sprite::Initialize ( )
overridevirtual

Sets up the input events (OnClick, OnMouseEnter, OnMouseLeave).

Implements Engine3DRadSpace.IInitializable.

◆ IsClicked()

bool Sprite::IsClicked ( ) const
noexcept

Gets whether the sprite is currently clicked.

Returns
True if clicked, false otherwise

◆ IsHovered()

bool Sprite::IsHovered ( ) const
noexcept

Gets whether the sprite is currently hovered by the mouse cursor.

Returns
True if hovered, false otherwise

◆ Load() [1/2]

void Sprite::Load ( )
overridevirtual

Loads the texture asset.

Implements Engine3DRadSpace.ILoadable.

◆ Load() [2/2]

void Sprite::Load ( const std::filesystem::path & path)
overridevirtual

Loads a texture from a specified path.

Parameters
pathImage file

Implements Engine3DRadSpace.ILoadable.

◆ operator=()

Sprite & Engine3DRadSpace.Objects.Sprite.operator= ( Sprite && )
defaultnoexcept

◆ ResetInputState()

void Sprite::ResetInputState ( )
noexcept

Resets the hover and click input state of the sprite.

◆ SetSpriteImage()

void Sprite::SetSpriteImage ( Graphics::ITexture2D * texture)

Sets the underlying texture used by this sprite.

Parameters
texturePointer to the texture

◆ Update()

void Sprite::Update ( )
overridevirtual

Updates the hover and click input state of the sprite.

Implements Engine3DRadSpace.IUpdateable.

Member Data Documentation

◆ _click

bool Engine3DRadSpace.Objects.Sprite._click
protected

◆ _hover

bool Engine3DRadSpace.Objects.Sprite._hover
protected

◆ _texture

Graphics::ITexture2D* Engine3DRadSpace.Objects.Sprite._texture
protected

◆ Image

RefTexture2D Engine3DRadSpace.Objects.Sprite.Image

Numerical reference to the texture asset used by this object.

◆ OnClick

Reflection::Event Engine3DRadSpace.Objects.Sprite.OnClick

Executes when the sprite is clicked. Return value is ignored.

◆ OnMouseEnter

Reflection::Event Engine3DRadSpace.Objects.Sprite.OnMouseEnter

Executes when the mouse cursor enters the sprite's bounds. Return value is ignored.

◆ OnMouseLeave

Reflection::Event Engine3DRadSpace.Objects.Sprite.OnMouseLeave

Executes when the mouse cursor leaves the sprite's bounds. Return value is ignored.

◆ TintColor

Tint colour applied to the sprite.

◆ UVCoordinates

Math::RectangleF Engine3DRadSpace.Objects.Sprite.UVCoordinates = Math::RectangleF(0, 0, 1, 1)

UV coordinates used to sample the sprite's texture.

Property Documentation

◆ FlipU

bool Engine3DRadSpace.Objects.Sprite.FlipU
getset

Flip the sprite horizontally.

◆ FlipV

bool Engine3DRadSpace.Objects.Sprite.FlipV
getset

Flip the sprite vertically.

◆ TextureID

uint Engine3DRadSpace.Objects.Sprite.TextureID
getset

◆ TintColor

unsafe Color Engine3DRadSpace.Objects.Sprite.TintColor
getset

The documentation for this class was generated from the following files:
  • E:/3DRadSpace/3DRadSpace_CSharp/Objects/Sprite.cs
  • E:/3DRadSpace/Engine3DRadSpace/Objects/Impl/Sprite.hpp
  • E:/3DRadSpace/Engine3DRadSpace/Objects/Impl/Sprite.cpp