SpriteNode<T> class

Draws one frame of a Sprite at a time, and animates along its row.

add(
  SpriteNode(
    sprite: SpriteSheet('assets/fire.png', .new(32, 48), fps: 12),
  ),
);

A sprite takes its size from the frame, so anchor, hit testing and layout all work off the frame rather than the image. How fast it plays and whether it loops belong to the sprite. speed scales the rate, and play chooses which row is playing.

Inheritance
Implemented types
Available extensions

Constructors

SpriteNode({required Sprite<T> sprite, Paint? paint, double? speed, bool? cleanup, Vector2? position, Vector2? scale, double? angle, Anchor? anchor, bool? enabled, int? priority, Iterable<Node> children = const []})
Creates a node that draws sprite.

Properties

absolutePosition MVector2
This node's position in scene space.
no setterinherited
ancestors Iterable<Node>
This node's ancestors in the tree.
no setterinherited
anchor Anchor
Where this node's area sits relative to position. Defaults to topLeft.
getter/setter pairinherited
angle double
This node's clockwise rotation, in radians. Defaults to 0.
getter/setter pairinherited
children Iterable<Node>
This node's direct children.
no setterinherited
cleanup bool
Whether to detach once finished. Defaults to false.
getter/setter pair
descendants Iterable<Node>
This node's descendants in depth-first preorder.
no setterinherited
enabled bool
Whether this node updates and renders. Defaults to true.
getter/setter pairinherited
flex LayoutFlex
The share of a flex layout's leftover space this node asks for.
no setterinherited
frame int
The frame currently drawn, counted from the start of row.
no setter
hashCode int
The hash code for this object.
no setterinherited
hasParent bool
True if this node has a non-null parent.
no setterinherited
height double
This node's height.
no setterinherited
isFinished bool
Whether a non-looping animation has reached its final frame.
no setter
isMounted bool
True while this node is part of a mounted tree.
no setterinherited
localTransform MMatrix3
This node's local transform.
no setterinherited
loops bool
Whether the row currently playing starts over after its final frame.
no setter
onFinish Signal0
Emitted when a non-looping animation reaches its final frame.
final
onFrame Signal1<int>
Emitted when animation advances to a new frame.
final
onLoop Signal0
Emitted when a looping animation wraps to the start of its row.
final
onMount Signal0
Emitted when this node is added to a scene.
finalinherited
onSceneResize Signal1<Vector2>
Emitted when the scene resizes, and once at mount.
finalinherited
onUnmount Signal0
Emitted when this node is removed from a scene.
finalinherited
paint Paint
The default paint.
no setter
palette Palette
This node's registered paints.
final
parent Node?
The parent that owns this node, or null when it is parentless.
no setterinherited
position MVector2
This node's position. Defaults to (0, 0).
finalinherited
priority int
This node's order in updating and rendering in its parent. Defaults to 0.
getter/setter pairinherited
renderTransform Float64List
This node's render transform. Equivalent to localTransform, except that it's stored in a Canvas-friendly typed_data structure for performance reasons.
no setterinherited
row int
The row currently playing, indexed into sprite.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scale MVector2
This node's scale. Defaults to (1, 1).
finalinherited
scene Scene<Node>
This node's owning scene. Only valid while isMounted.
no setterinherited
size Vector2
The size of one frame of the row currently playing.
no setteroverride
speed double
How fast this sprite plays, as a multiple of the rate its sprite states.
getter/setter pairoverride
sprite Sprite<T>
What this sprite draws.
no setter
width double
This node's width.
no setterinherited

Methods

absoluteTransform([Node? upTo]) MMatrix3
This node's transform composed with every TransformNode ancestor, stopping at (but not including) upTo.
inherited
add<T extends Node>(T node) → T
Adds node to this node. The node is returned.
inherited
addAll(Iterable<Node> nodes) → void
Adds all nodes to this node.
inherited
attach(Node node) → void
Adds this node to the target node.
inherited
build() → void
Declares this node's children and behavior.
override
contains(Node other) bool
Checks if this node contains the other node in its tree.
inherited
containsPoint(Vector2 point) bool
Whether this node's hit area contains point.
inherited
cycles(Node node) bool
True if node is (or soon will be) an ancestor of this node.
inherited
debugDraw(DebugDraw draw) → void
Draws to the debug overlay every frame, in the same space as draw.
inherited
debugRender(Canvas canvas) → void
Renders the subtree under this node's transform, marking position with a 2-pixel cross before anything this node or its children draw.
inherited
debugRenderSelf(Canvas canvas) → void
Runs this node's debugDraw callbacks, in the same space as renderSelf.
inherited
detach() bool
Removes this node from its parent, or from the parent it is on its way to.
inherited
disable() → void
Disables this node, so it stops updating and rendering.
inherited
distance(TransformNode other) double
The distance between this node's absolute position and other's.
inherited
distance2(TransformNode other) double
The squared distance between this node's absolute position and other's.
inherited
draw(Draw draw) → void
Draws to canvas every frame, in this node's own coordinate space.
inherited
enable() → void
Enables this node, so it resumes updating and rendering.
inherited
hitTest(Vector2 point) Iterable<Node>
Finds every enabled node in this subtree whose hit area contains point, per containsPoint, topmost first.
inherited
layout(LayoutConstraints constraints) → void
A plain SizedNode can't lay itself out, so its size stands whatever constraints say.
inherited
mount() Scene<T>

Available on T, provided by the Mount extension

Mounts this node as the root of a new Scene and returns it.
nearest<T extends TransformNode>([Node? within]) → T?
The nearest T to this node among within's descendants, or null if there is none.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
owns(Node other) bool
Checks if this node owns the other node.
inherited
play({T? key, int row = 0, int frame = 0, bool? loop}) → void
Plays row from the given frame, or whichever row key names.
provide<T>(T value) → void
Provides value as this node's instance of T, overwriting any value previously provided for T.
inherited
query<T extends Node>() Iterable<T>
This node's direct children of type T, in priority order.
inherited
read<T>() → T
Reads the nearest instance of T provided by this node or an ancestor, checking this node first.
inherited
readOrNull<T>() → T?
Reads the nearest instance of T provided by this node or an ancestor, checking this node first. Returns null if none was provided.
inherited
reassemble() → void
Re-resolves sprite through Sprite.reload, so an image replaced in the cache reaches the screen without rebuilding this node.
override
rebuild() → void
Re-derives this node by running build again over the wreckage of the last one.
inherited
remove(Node node) bool
Removes the child node.
inherited
removeAll() → void
Removes all children.
inherited
render(Canvas canvas) → void
Renders this node and its children to canvas.
inherited
renderSelf(Canvas canvas) → void
Draws in a coordinate space where (0, 0) is width/height's anchor-adjusted top-left corner. Children keep the untranslated space.
inherited
scenePosition([Node? upTo]) MVector2
This node's position, composed with the transform of every TransformNode ancestor, stopping at (but not including) upTo.
inherited
tick(Tick tick) → void
Calls tick with the elapsed seconds on every frame.
inherited
toString() String
A string representation of this object.
inherited
trash(Cleanup cleanup) → void
Defers cleanup until this build stops being current.
inherited
update(double dt) → void
Updates this node and its children by dt seconds.
inherited
worldBounds(Shape shape, Matrix3 transform) Aabb2
This node's world-space AABB for shape, given its already-computed transform (see absoluteTransform).
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited