Sprite2D
General-purpose sprite node.
Sprite2D.swift:17class Sprite2D
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.
This object emits the following signals:
Superclasses
class Node2D
A 2D game object, inherited by all 2D-related nodes. Has a position, rotation, scale, and Z index.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Type members
Instance members
var centered: Bool
If
true
, texture is centered.var flipH: Bool
If
true
, texture is flipped horizontally.var flipV: Bool
If
true
, texture is flipped vertically.var frame: Int32
Current frame to display from sprite sheet.
hframes
orvframes
must be greater than 1.var frameChanged: SimpleSignal
Emitted when the
frame
changes.var frameCoords: Vector2i
Coordinates of the frame to display from sprite sheet. This is as an alias for the
frame
property.hframes
orvframes
must be greater than 1.var hframes: Int32
The number of columns in the sprite sheet.
var offset: Vector2
The texture’s drawing offset.
var regionEnabled: Bool
If
true
, texture is cut from a larger atlas texture. SeeregionRect
.var regionFilterClipEnabled: Bool
If
true
, the outermost pixels get blurred out.regionEnabled
must betrue
.var regionRect: Rect2
The region of the atlas texture to display.
regionEnabled
must betrue
.var texture: Texture2D?
Texture2D
object to draw.var textureChanged: SimpleSignal
Emitted when the
texture
changes.var vframes: Int32
The number of rows in the sprite sheet.
func getRect(
) -> Rect2 Returns a
Rect2
representing the Sprite2D’s boundary in local coordinates. Can be used to detect if the Sprite2D was clicked.func isPixelOpaque(pos: Vector2
) -> Bool Returns
true
, if the pixel at the given position is opaque andfalse
in other case.