@zhobo63/zlui-ts-spine
v0.1.1
Published
zlSpine is a spine plugin of zlui-ts.
Readme
zlui-ts-spine README
Brief of zlUISpine.ts
zlUISpine.ts extends the zlui-ts library by integrating the Spine 2D animation runtime, allowing zlui-ts applications to display and control Spine animations.
Key Features and Extensions:
Spine Integration:
- It imports Spine 3.8 runtime components (
SPINE38) for handling skeleton data, animation states, and rendering. - Introduces
zlUISpineclass which inherits fromzlUIWin(the basezlui-tsUI component), making Spine animations behave like any other UI element.
- It imports Spine 3.8 runtime components (
Spine Animation Loading and Control:
spine <atlas_name> <skeleton_name>: This is a new parsing command forzlUISpinecomponents. It loads a Spine atlas (.atlasfile) and skeleton data (.jsonor.skelfile) for the animation.ani <animation_name>: Plays a specified animation from the loaded Spine data.xy <x> <y>: Sets the position of the Spine skeleton within its UI component bounds.premultipliedalpha <bool>: Controls whether premultiplied alpha is used for rendering the Spine animation.
Rendering Backend Extension:
- It extends the
BackendImGui(anzlui-tsbackend) with aPaintSpineclass. This class is responsible for drawing Spine animations directly within the ImGui rendering context. - It uses
SPINE38.SkeletonRendererandSPINE38.PolygonBatcherto render the Spine skeletons. - Includes logic for drawing individual bones for debugging purposes (if
draw_boneis enabled inPaintSpine).
- It extends the
Asset Management:
- A
Rendererclass, inheriting fromSPINE38.AssetManager, is introduced to handle loading Spine assets (atlas, skeleton files). It includesLoadandWaitmethods for asynchronous loading. Renderer.Registerstatically registers thezlUISpinecomponent with thezlUIMgr(UI Manager) and hooks into thezlui-tsrendering pipeline.
- A
Coordinate Transformation:
- Provides helper functions like
toImVec2andtoMat4to convertzlui-ts'sVec2andTransformobjects to Spine'sImGui.Vec2andSPINE38.Matrix4formats, ensuring correct positioning and scaling of Spine animations within thezlui-tsUI.
- Provides helper functions like
In essence, zlUISpine.ts acts as a bridge, allowing zlui-ts to render complex 2D Spine animations as native UI elements, managed by the existing zlui-ts layout and event system.
Example
Initialize
this.ui=new UIMgr;
this.ui.backend=new BackendImGui(ImGui.GetBackgroundDrawList());
SPINE.Renderer.Register(this.ui, 'assets/');Loading
Object Spine
{
Name spineboy
RectWH 250 895 0 0
Spine spineboy-pma.atlas spineboy-pro.skel
Ani walk
}