reckfellENGINE

Sprite2D

General-purpose sprite node.

On this page
class Sprite2DReckfellSharpInherits Entity2D

General-purpose sprite node.

A node that displays a 2D texture. The texture displayed can be a region from a larger atlas texture, or a frame from a sprite sheet animation.

Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.

Constructors1

Sprite2DConstructor
# Sprite2D
C#
public Sprite2D();

Properties12

CenteredProperty
# Centered
C#
public bool Centered { get; set; }

If true, texture is centered. Note: For games with a pixel art aesthetic, textures may appear deformed when centered. This is caused by their position being between pixels. To prevent this, set this property to false, or consider enabling ProjectSettings.rendering/2d/snap/snap_2d_vertices_to_pixel and ProjectSettings.rendering/2d/snap/snap_2d_transforms_to_pixel.

FlipHProperty
# FlipH
C#
public bool FlipH { get; set; }

If true, texture is flipped horizontally.

FlipVProperty
# FlipV
C#
public bool FlipV { get; set; }

If true, texture is flipped vertically.

FrameProperty
# Frame
C#
public int Frame { get; set; }

Current frame to display from sprite sheet. Sprite2D.Hframes or Sprite2D.Vframes must be greater than 1. This property is automatically adjusted when Sprite2D.Hframes or Sprite2D.Vframes are changed to keep pointing to the same visual frame (same column and row). If that's impossible, this value is reset to 0.

FrameCoordsProperty
# FrameCoords
C#
public Vector2I FrameCoords { get; set; }

Coordinates of the frame to display from sprite sheet. This is as an alias for the Sprite2D.Frame property. Sprite2D.Hframes or Sprite2D.Vframes must be greater than 1.

HframesProperty
# Hframes
C#
public int Hframes { get; set; }

The number of columns in the sprite sheet. When this property is changed, Sprite2D.Frame is adjusted so that the same visual frame is maintained (same row and column). If that's impossible, Sprite2D.Frame is reset to 0.

OffsetProperty
# Offset
C#
public Vector2 Offset { get; set; }

The texture's drawing offset. Note: When you increase Sprite2D.Offset.y in Sprite2D, the sprite moves downward on screen (i.e., +Y is down).

RegionEnabledProperty
# RegionEnabled
C#
public bool RegionEnabled { get; set; }

Enables sampling RegionRect instead of the full texture. RegionRect uses source texture pixels. In the tested shader path, UV already includes the region; do not apply its offset again.

RegionFilterClipEnabledProperty
# RegionFilterClipEnabled
C#
public bool RegionFilterClipEnabled { get; set; }

If true, the area outside of the Sprite2D.RegionRect is clipped to avoid bleeding of the surrounding texture pixels. Sprite2D.RegionEnabled must be true.

RegionRectProperty
# RegionRect
C#
public Rect2 RegionRect { get; set; }

Source rectangle in Texture pixels, used when RegionEnabled is true. It is neither the normalized shader REGION_RECT nor the scaled sprite size. Hframes/Vframes further divide the selected rectangle into frames.

TextureProperty
# Texture
C#
public Texture2D Texture { get; set; }

Texture2D object to draw.

VframesProperty
# Vframes
C#
public int Vframes { get; set; }

The number of rows in the sprite sheet. When this property is changed, Sprite2D.Frame is adjusted so that the same visual frame is maintained (same row and column). If that's impossible, Sprite2D.Frame is reset to 0.

Methods26

GetFrameint
# GetFrame
C#
public int GetFrame();
Returns int
GetFrameCoordsVector2I
# GetFrameCoords
C#
public Vector2I GetFrameCoords();
Returns Vector2I
GetHframesint
# GetHframes
C#
public int GetHframes();
Returns int
GetOffsetVector2
# GetOffset
C#
public Vector2 GetOffset();
Returns Vector2
GetRectRect2
# GetRect
C#
public Rect2 GetRect();

Returns a Rect2 representing the Sprite2D's boundary in local coordinates. Example: Detect if the Sprite2D was clicked:

C#
public override void _Input(InputEvent @event)
{
    if (@event is InputEventMouseButton inputEventMouse)
    {
        if (inputEventMouse.Pressed && inputEventMouse.ButtonIndex == MouseButton.Left)
        {
            if (GetRect().HasPoint(ToLocal(inputEventMouse.Position)))
            {
                ReckfellApi.Print("A click!");
            }
        }
    }
}
Returns Rect2
GetRegionRectRect2
# GetRegionRect
C#
public Rect2 GetRegionRect();

Source rectangle in Texture pixels, used when RegionEnabled is true. It is neither the normalized shader REGION_RECT nor the scaled sprite size. Hframes/Vframes further divide the selected rectangle into frames.

Returns Rect2

The stored Rect2 in texture pixels, even when RegionEnabled is disabled.

GetTextureTexture2D
# GetTexture
C#
public Texture2D GetTexture();
Returns Texture2D
GetVframesint
# GetVframes
C#
public int GetVframes();
Returns int
IsCenteredbool
# IsCentered
C#
public bool IsCentered();
Returns bool
IsFlippedHbool
# IsFlippedH
C#
public bool IsFlippedH();
Returns bool
IsFlippedVbool
# IsFlippedV
C#
public bool IsFlippedV();
Returns bool
IsPixelOpaquebool
# IsPixelOpaque
C#
public bool IsPixelOpaque(Vector2 pos);

Returns true if the pixel at the given position is opaque, false otherwise. Also returns false if the given position is out of bounds or this sprite's Sprite2D.Texture is null. pos is in local coordinates.

Parameters
NameTypeDefault
posVector2—
Returns bool
IsRegionEnabledbool
# IsRegionEnabled
C#
public bool IsRegionEnabled();

Enables sampling RegionRect instead of the full texture. RegionRect uses source texture pixels. In the tested shader path, UV already includes the region; do not apply its offset again.

Returns bool

true when source selection uses RegionRect.

IsRegionFilterClipEnabledbool
# IsRegionFilterClipEnabled
C#
public bool IsRegionFilterClipEnabled();
Returns bool
SetCenteredvoid
# SetCentered
C#
public void SetCentered(bool centered);
Parameters
NameTypeDefault
centeredbool—
SetFlipHvoid
# SetFlipH
C#
public void SetFlipH(bool flipH);
Parameters
NameTypeDefault
flipHbool—
SetFlipVvoid
# SetFlipV
C#
public void SetFlipV(bool flipV);
Parameters
NameTypeDefault
flipVbool—
SetFramevoid
# SetFrame
C#
public void SetFrame(int frame);
Parameters
NameTypeDefault
frameint—
SetFrameCoordsvoid
# SetFrameCoords
C#
public void SetFrameCoords(Vector2I coords);
Parameters
NameTypeDefault
coordsVector2I—
SetHframesvoid
# SetHframes
C#
public void SetHframes(int hframes);
Parameters
NameTypeDefault
hframesint—
SetOffsetvoid
# SetOffset
C#
public void SetOffset(Vector2 offset);
Parameters
NameTypeDefault
offsetVector2—
SetRegionEnabledvoid
# SetRegionEnabled
C#
public void SetRegionEnabled(bool enabled);

Enables sampling RegionRect instead of the full texture. RegionRect uses source texture pixels. In the tested shader path, UV already includes the region; do not apply its offset again.

Parameters
NameTypeDefault
enabledbool—
enabled

true to use RegionRect.

SetRegionFilterClipEnabledvoid
# SetRegionFilterClipEnabled
C#
public void SetRegionFilterClipEnabled(bool enabled);
Parameters
NameTypeDefault
enabledbool—
SetRegionRectvoid
# SetRegionRect
C#
public void SetRegionRect(Rect2 rect);

Source rectangle in Texture pixels, used when RegionEnabled is true. It is neither the normalized shader REGION_RECT nor the scaled sprite size. Hframes/Vframes further divide the selected rectangle into frames.

Parameters
NameTypeDefault
rectRect2—
rect

Offset and size in source texture pixels, before sprite scaling.

SetTexturevoid
# SetTexture
C#
public void SetTexture(Texture2D texture);
Parameters
NameTypeDefault
textureTexture2D—
SetVframesvoid
# SetVframes
C#
public void SetVframes(int vframes);
Parameters
NameTypeDefault
vframesint—

Signals and events2

FrameChangedEvent
# FrameChanged
C#
public event Action FrameChanged;

Emitted when the Sprite2D.Frame changes.

TextureChangedEvent
# TextureChanged
C#
public event Action TextureChanged;

Emitted when the Sprite2D.Texture changes.

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.