Inheritance #
- AudioServer
- CameraServer
- ClassDB
- DisplayServer
- EditorFileSystemDirectory
- EditorInterface
- EditorPaths
- EditorSelection
- EditorUndoRedoManager
- EditorVCSInterface
- Engine
- EngineDebugger
- FramebufferCacheRD
- GDExtensionManager
- Geometry2D
- Geometry3D
- IP
- Input
- InputMap
- JNISingleton
- JSONRPC
- JavaClassWrapper
- JavaScriptBridge
- MainLoop (1)
- Marshalls
- MovieWriter
- NativeMenu
- NavigationMeshGenerator
- NavigationServer2D
- NavigationServer3D
- Node (21)
- OS
- OpenXRExtensionWrapperExtension
- OpenXRInteractionProfileMetadata
- Performance
- PhysicsDirectBodyState2D (1)
- PhysicsDirectBodyState3D (1)
- PhysicsDirectSpaceState2D (1)
- PhysicsDirectSpaceState3D (1)
- PhysicsServer2D (1)
- PhysicsServer2DManager
- PhysicsServer3D (1)
- PhysicsServer3DManager
- PhysicsServer3DRendering
ServerHandler
- ProjectSettings
- RefCounted (121)
- RenderData (2)
- RenderSceneData (2)
- RenderingDevice
- RenderingServer
- ResourceLoader
- ResourceSaver
- ResourceUID
- ScriptLanguage (1)
- ShaderIncludeDB
- TextServerManager
- ThemeDB
- TileData
- Time
- TranslationServer
- TreeItem
- UndoRedo
- UniformSetCacheRD
- WorkerThreadPool
- XRServer
- XRVRS
- AnimationMixer (2)
- AudioStreamPlayer
- CanvasItem (2)
- CanvasLayer (1)
- EditorFileSystem
- EditorPlugin (1)
- EditorResourcePreview
- HTTPRequest
- InstancePlaceholder
- MissingNode
- MultiplayerSpawner
- MultiplayerSynchronizer
- NavigationAgent2D
- NavigationAgent3D
- Node3D (31)
- ResourcePreloader
- ShaderGlobalsOverride
- StatusIndicator
- Timer
- Viewport (2)
- WorldEnvironment
- AnimatedSprite2D
- AudioListener2D
- AudioStreamPlayer2D
- BackBufferCopy
- Bone2D
- CPUParticles2D
- Camera2D
- CanvasGroup
- CanvasModulate
- CollisionObject2D (2)
- CollisionPolygon2D
- CollisionShape2D
- GPUParticles2D
- Joint2D (3)
- Light2D (2)
- LightOccluder2D
- Line2D
- Marker2D
- MeshInstance2D
- MultiMeshInstance2D
- NavigationLink2D
- NavigationObstacle2D
- NavigationRegion2D
- Parallax2D
- ParallaxLayer
- Path2D
- PathFollow2D
- Polygon2D
- RayCast2D
- RemoteTransform2D
- ShapeCast2D
- Skeleton2D
- Sprite2D
- TileMap
- TileMapLayer
- TouchScreenButton
- VisibleOnScreenNotifier2D (1)
Table of contents
-
var centered: bool = true -
var flip_h: bool = false -
var flip_v: bool = false -
var frame: int = 0 -
var frame_coords: Vector2i = Vector2i(0, 0) -
var hframes: int = 1 -
var offset: Vector2 = Vector2(0, 0) -
var region_enabled: bool = false -
var region_filter_clip_enabled: bool = false -
var region_rect: Rect2 = Rect2(0, 0, 0, 0) -
var texture: Texture2D -
var vframes: int = 1 -
const func get_rect() -> Rect2 -
const func is_pixel_opaque(pos: Vector2) -> bool -
signal frame_changed() -
signal texture_changed()
Sprite2D #
is_instantiable, Node2D, Node, core, not_builtin_classes
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.
Members #
var centered: bool = true#
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.
var flip_h: bool = false#
If true, texture is flipped horizontally.
var flip_v: bool = false#
If true, texture is flipped vertically.
var frame: int = 0#
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.
var frame_coords: Vector2i = Vector2i(0, 0)#
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.
var hframes: int = 1#
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.
var offset: Vector2 = Vector2(0, 0)#
The texture's drawing offset.
var region_enabled: bool = false#
If true, texture is cut from a larger atlas texture. See region_rect.
var region_filter_clip_enabled: bool = false#
If true, the area outside of the region_rect is clipped to avoid bleeding of the surrounding texture pixels. region_enabled must be true.
var region_rect: Rect2 = Rect2(0, 0, 0, 0)#
The region of the atlas texture to display. region_enabled must be true.
var texture: Texture2D#
Texture2D object to draw.
var vframes: int = 1#
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.
Methods #
const func get_rect() -> Rect2#
Returns a Rect2 representing the Sprite2D's boundary in local coordinates.
Example: Detect if the Sprite2D was clicked:
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!")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)))
{
GD.Print("A click!");
}
}
}
}const func is_pixel_opaque(pos: Vector2) -> 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.
Annotations #
Constants #
Constructors #
Enums #
Operators #
Signals #
signal frame_changed()#
Emitted when the frame changes.
signal texture_changed()#
Emitted when the texture changes.