Sprite2D

package
v0.0.0-...-357ca8a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2025 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Advanced

type Advanced = class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

type Any

type Any interface {
	gd.IsClass
	AsSprite2D() Instance
}

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension

func (*Extension[T]) AsCanvasItem

func (self *Extension[T]) AsCanvasItem() CanvasItem.Instance

func (*Extension[T]) AsNode

func (self *Extension[T]) AsNode() Node.Instance

func (*Extension[T]) AsNode2D

func (self *Extension[T]) AsNode2D() Node2D.Instance

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

func (*Extension[T]) AsSprite2D

func (self *Extension[T]) AsSprite2D() Instance

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.Sprite2D

Instance of the class with convieniently typed arguments and results.

var Nil Instance

Nil is a nil/null instance of the class. Equivalent to the zero value.

func New

func New() Instance

func (Instance) AsCanvasItem

func (self Instance) AsCanvasItem() CanvasItem.Instance

func (Instance) AsNode

func (self Instance) AsNode() Node.Instance

func (Instance) AsNode2D

func (self Instance) AsNode2D() Node2D.Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AsSprite2D

func (self Instance) AsSprite2D() Instance

func (Instance) Centered

func (self Instance) Centered() bool

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".

func (Instance) FlipH

func (self Instance) FlipH() bool

If true, texture is flipped horizontally.

func (Instance) FlipV

func (self Instance) FlipV() bool

If true, texture is flipped vertically.

func (Instance) Frame

func (self Instance) Frame() int

Current frame to display from sprite sheet. Hframes or Vframes must be greater than 1. This property is automatically adjusted when Hframes or 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.

func (Instance) FrameCoords

func (self Instance) FrameCoords() Vector2i.XY

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

func (Instance) GetRect

func (self Instance) GetRect() Rect2.PositionSize

Returns a Rect2.PositionSize representing the Sprite2D's boundary in local coordinates.

Example: Detect if the Sprite2D was clicked:

Input := func(event InputEvent.Instance) {
	if inputEventMouse, ok := Object.As[InputEventMouseButton.Instance](event); ok {
		if Rect2.HasPoint(sprite.GetRect(), sprite.AsNode2D().ToLocal(inputEventMouse.AsInputEventMouse().Position())) {
			fmt.Println("A click!")
		}
	}
}

func (Instance) Hframes

func (self Instance) Hframes() int

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

func (Instance) ID

func (self Instance) ID() ID

func (Instance) IsPixelOpaque

func (self Instance) IsPixelOpaque(pos Vector2.XY) bool

Returns true, if the pixel at the given position is opaque and false in other case. The position is in local coordinates.

Note: It also returns false, if the sprite's texture is null or if the given position is invalid.

func (Instance) Offset

func (self Instance) Offset() Vector2.XY

The texture's drawing offset.

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

func (Instance) OnFrameChanged

func (self Instance) OnFrameChanged(cb func(), flags ...Signal.Flags)

Emitted when the Frame changes.

func (Instance) OnTextureChanged

func (self Instance) OnTextureChanged(cb func(), flags ...Signal.Flags)

Emitted when the Texture changes.

func (Instance) RegionEnabled

func (self Instance) RegionEnabled() bool

If true, texture is cut from a larger atlas texture. See RegionRect.

Note: When using a custom Shader on a Sprite2D, the UV shader built-in will refer to the entire texture space. Use the REGION_RECT built-in to get the currently visible region defined in RegionRect instead. See CanvasItem shaders for details.

func (Instance) RegionFilterClipEnabled

func (self Instance) RegionFilterClipEnabled() bool

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

func (Instance) RegionRect

func (self Instance) RegionRect() Rect2.PositionSize

The region of the atlas texture to display. RegionEnabled must be true.

func (Instance) SetCentered

func (self Instance) SetCentered(value bool)

SetCentered sets the property returned by [IsCentered].

func (Instance) SetFlipH

func (self Instance) SetFlipH(value bool)

SetFlipH sets the property returned by [IsFlippedH].

func (Instance) SetFlipV

func (self Instance) SetFlipV(value bool)

SetFlipV sets the property returned by [IsFlippedV].

func (Instance) SetFrame

func (self Instance) SetFrame(value int)

SetFrame sets the property returned by [GetFrame].

func (Instance) SetFrameCoords

func (self Instance) SetFrameCoords(value Vector2i.XY)

SetFrameCoords sets the property returned by [GetFrameCoords].

func (Instance) SetHframes

func (self Instance) SetHframes(value int)

SetHframes sets the property returned by [GetHframes].

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) SetOffset

func (self Instance) SetOffset(value Vector2.XY)

SetOffset sets the property returned by [GetOffset].

func (Instance) SetRegionEnabled

func (self Instance) SetRegionEnabled(value bool)

SetRegionEnabled sets the property returned by [IsRegionEnabled].

func (Instance) SetRegionFilterClipEnabled

func (self Instance) SetRegionFilterClipEnabled(value bool)

SetRegionFilterClipEnabled sets the property returned by [IsRegionFilterClipEnabled].

func (Instance) SetRegionRect

func (self Instance) SetRegionRect(value Rect2.PositionSize)

SetRegionRect sets the property returned by [GetRegionRect].

func (Instance) SetTexture

func (self Instance) SetTexture(value Texture2D.Instance)

SetTexture sets the property returned by [GetTexture].

func (Instance) SetVframes

func (self Instance) SetVframes(value int)

SetVframes sets the property returned by [GetVframes].

func (Instance) Texture

func (self Instance) Texture() Texture2D.Instance

Texture2D object to draw.

func (Instance) Vframes

func (self Instance) Vframes() int

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

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL