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.
https://godotengine.org/asset-library/asset/2716
Returns a [Rect2] representing the Sprite2D's boundary in local coordinates.
[b]Example:[/b] Detect if the Sprite2D was clicked:
[codeblocks]
[gdscript]
func _input(event):
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
if get_rect().has_point(to_local(event.position)):
print("A click!")
[/gdscript]
[csharp]
public override void _Input(InputEvent @event)
{
if (@event is InputEventMouseButton inputEventMouse)
{
if (inputEventMouse.Pressed && inputEventMouse.ButtonIndex == MouseButton.Left)
{
if (GetRect().HasPoint(ToLocal(inputEventMouse.Position)))
{
GD.Print("A click!");
}
}
}
}
[/csharp]
[/codeblocks]
Returns [code]true[/code], if the pixel at the given position is opaque and [code]false[/code] in other case. The position is in local coordinates.
[b]Note:[/b] It also returns [code]false[/code], if the sprite's texture is [code]null[/code] or if the given position is invalid.
If [code]true[/code], texture is centered.
[b]Note:[/b] 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 [code]false[/code], or consider enabling [member ProjectSettings.rendering/2d/snap/snap_2d_vertices_to_pixel] and [member ProjectSettings.rendering/2d/snap/snap_2d_transforms_to_pixel].
If [code]true[/code], texture is flipped horizontally.
If [code]true[/code], texture is flipped vertically.
Current frame to display from sprite sheet. [member hframes] or [member vframes] must be greater than 1. This property is automatically adjusted when [member hframes] or [member vframes] are changed to keep pointing to the same visual frame (same column and row). If that's impossible, this value is reset to [code]0[/code].
Coordinates of the frame to display from sprite sheet. This is as an alias for the [member frame] property. [member hframes] or [member vframes] must be greater than 1.
The number of columns in the sprite sheet. When this property is changed, [member frame] is adjusted so that the same visual frame is maintained (same row and column). If that's impossible, [member frame] is reset to [code]0[/code].
The texture's drawing offset.
If [code]true[/code], texture is cut from a larger atlas texture. See [member region_rect].
If [code]true[/code], the outermost pixels get blurred out. [member region_enabled] must be [code]true[/code].
The region of the atlas texture to display. [member region_enabled] must be [code]true[/code].
[Texture2D] object to draw.
The number of rows in the sprite sheet. When this property is changed, [member frame] is adjusted so that the same visual frame is maintained (same row and column). If that's impossible, [member frame] is reset to [code]0[/code].
Emitted when the [member frame] changes.
Emitted when the [member texture] changes.