SkeletonDrawable class
A SkeletonDrawable bundles loading, updating, and rendering an Atlas, Skeleton, and AnimationState into a single easy to use class.
Use the fromAsset, fromFile, or fromHttp methods to construct a SkeletonDrawable. To have multiple skeleton drawable instances share the same Atlas and SkeletonData, use the constructor.
You can then directly access the atlas, skeletonData, skeleton, animationStateData, and animationState to query and animate the skeleton. Use the AnimationState to queue animations on one or more tracks via AnimationState.setAnimation or AnimationState.addAnimation.
To update the AnimationState and apply it to the Skeleton call the update function, providing it a delta time in seconds to advance the animations.
To render the current pose of the Skeleton, use the rendering methods render, renderToCanvas, renderToPictureRecorder, renderToPng, or renderToRawImageData, depending on your needs.
When the skeleton drawable is no longer needed, call the dispose method to release its resources. If the skeleton drawable was constructed from a shared Atlas and SkeletonData, make sure to dispose the atlas and skeleton data as well, if no skeleton drawable references them anymore.
Constructors
- SkeletonDrawable.new(Atlas atlas, SkeletonData skeletonData, bool _ownsAtlasAndSkeletonData)
-
Constructs a new skeleton drawable from the given (possibly shared) Atlas and SkeletonData. If
the atlas and skeleton data are not shared, the drawable can take ownership by passing true for
_ownsAtlasAndSkeletonData
. In that case a call to dispose will also dispose the atlas and skeleton data.
Properties
- animationState ↔ AnimationState
-
latefinal
- animationStateData ↔ AnimationStateData
-
latefinal
- atlas → Atlas
-
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- skeleton ↔ Skeleton
-
latefinal
- skeletonData → SkeletonData
-
final
Methods
-
dispose(
) → void - Disposes the skeleton drawable's resources. If the skeleton drawable owns the atlas and skeleton data, they are disposed as well. Must be called when the skeleton drawable is no longer in use.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
render(
) → List< RenderCommand> - Renders to current skeleton pose to a list of RenderCommand instances. The render commands can be rendered via Canvas.drawVertices.
-
renderToCanvas(
Canvas canvas) → List< RenderCommand> -
Renders the skeleton drawable's current pose to the given
canvas
. Does not perform any scaling or fitting. -
renderToPictureRecorder(
double width, double height, int bgColor) → PictureRecorder -
Renders the skeleton drawable's current pose to a PictureRecorder with the given
width
andheight
. UsesbgColor
, a 32-bit ARGB color value, to paint the background. Scales and centers the skeleton to fit the within the bounds ofwidth
andheight
. -
renderToPng(
double width, double height, int bgColor) → Future< Uint8List> -
Renders the skeleton drawable's current pose to a PNG encoded in a Uint8List, with the given
width
andheight
. UsesbgColor
, a 32-bit ARGB color value, to paint the background. Scales and centers the skeleton to fit the within the bounds ofwidth
andheight
. -
renderToRawImageData(
double width, double height, int bgColor) → Future< RawImageData> -
Renders the skeleton drawable's current pose to a
RawImageData
, with the givenwidth
andheight
. UsesbgColor
, a 32-bit ARGB color value, to paint the background. Scales and centers the skeleton to fit the within the bounds ofwidth
andheight
. -
toString(
) → String -
A string representation of this object.
inherited
-
update(
double delta) → void -
Updates the AnimationState using the
delta
time given in seconds, applies the animation state to the Skeleton and updates the world transforms of the skeleton to calculate its current pose.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
fromAsset(
String atlasFile, String skeletonFile, {AssetBundle? bundle}) → Future< SkeletonDrawable> -
Constructs a new skeleton drawable from the
atlasFile
andskeletonFile
from the root asset bundle or the optionally providedbundle
. -
fromFile(
String atlasFile, String skeletonFile) → Future< SkeletonDrawable> -
Constructs a new skeleton drawable from the
atlasFile
andskeletonFile
. -
fromHttp(
String atlasUrl, String skeletonUrl) → Future< SkeletonDrawable> -
Constructs a new skeleton drawable from the
atlasUrl
andskeletonUrl
.