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 ¶
- type Advanced
- type Any
- type Extension
- type ID
- type Instance
- func (self Instance) AsCanvasItem() CanvasItem.Instance
- func (self Instance) AsNode() Node.Instance
- func (self Instance) AsNode2D() Node2D.Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) AsSprite2D() Instance
- func (self Instance) Centered() bool
- func (self Instance) FlipH() bool
- func (self Instance) FlipV() bool
- func (self Instance) Frame() int
- func (self Instance) FrameCoords() Vector2i.XY
- func (self Instance) GetRect() Rect2.PositionSize
- func (self Instance) Hframes() int
- func (self Instance) ID() ID
- func (self Instance) IsPixelOpaque(pos Vector2.XY) bool
- func (self Instance) Offset() Vector2.XY
- func (self Instance) OnFrameChanged(cb func(), flags ...Signal.Flags)
- func (self Instance) OnTextureChanged(cb func(), flags ...Signal.Flags)
- func (self Instance) RegionEnabled() bool
- func (self Instance) RegionFilterClipEnabled() bool
- func (self Instance) RegionRect() Rect2.PositionSize
- func (self Instance) SetCentered(value bool)
- func (self Instance) SetFlipH(value bool)
- func (self Instance) SetFlipV(value bool)
- func (self Instance) SetFrame(value int)
- func (self Instance) SetFrameCoords(value Vector2i.XY)
- func (self Instance) SetHframes(value int)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) SetOffset(value Vector2.XY)
- func (self Instance) SetRegionEnabled(value bool)
- func (self Instance) SetRegionFilterClipEnabled(value bool)
- func (self Instance) SetRegionRect(value Rect2.PositionSize)
- func (self Instance) SetTexture(value Texture2D.Instance)
- func (self Instance) SetVframes(value int)
- func (self Instance) Texture() Texture2D.Instance
- func (self Instance) Vframes() int
- func (self Instance) Virtual(name string) reflect.Value
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 Extension ¶
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]) AsSprite2D ¶
type 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.
type Instance ¶
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 (Instance) AsCanvasItem ¶
func (self Instance) AsCanvasItem() CanvasItem.Instance
func (Instance) AsSprite2D ¶
func (Instance) Centered ¶
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) Frame ¶
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 ¶
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 ¶
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) IsPixelOpaque ¶
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 ¶
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 ¶
Emitted when the Frame changes.
func (Instance) OnTextureChanged ¶
Emitted when the Texture changes.
func (Instance) RegionEnabled ¶
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 ¶
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 ¶
SetCentered sets the property returned by [IsCentered].
func (Instance) SetFrameCoords ¶
SetFrameCoords sets the property returned by [GetFrameCoords].
func (Instance) SetHframes ¶
SetHframes sets the property returned by [GetHframes].
func (Instance) SetRegionEnabled ¶
SetRegionEnabled sets the property returned by [IsRegionEnabled].
func (Instance) SetRegionFilterClipEnabled ¶
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 ¶
SetTexture sets the property returned by [GetTexture].
func (Instance) SetVframes ¶
SetVframes sets the property returned by [GetVframes].