Skip to content

Latest commit

 

History

History
107 lines (93 loc) · 4.25 KB

README_en.md

File metadata and controls

107 lines (93 loc) · 4.25 KB

openfl-spine

A library for rendering Spine animations in the OpenFL engine, which can be achieved through Sprite and Tilemap for rendering processing.

Definition and Explanation of Each Version

This version is compatible with Spine runtime versions 3.8 to 4.2. Please refer to the following instructions for their runtime relationships:

Spine version Runtime Support Define
3.6 spine-hx 3.6.0+ Sprite + Tilemap render /
3.8 spine-hx 3.8.0+ Sprite + Tilemap render spine3.8
4.0 spine-hx 4.0+ Sprite + Tilemap render spine4
4.2 spine-haxe git Sprite + Tilemap render spine4.2

Dependent library

Renderer

  • Tilemap render: Has extremely fast rendering speed, but does not support meshes.
  • Sprite render: Having grid function, a single sprite has batch rendering function and expansion function, but it will consume performance.

Use

Install through command line:

haxelib install openfl-spine

如果使用Spine4.2版本,则需要安装Spine-Haxe-Git版本:spine-haxe

Configure in project.xml

<!-- opt param:spine3.8 spine4 spine4.2 -->
<define name="spine4.2"/>
<haxelib name="openfl-spine"/>

And initialize in any class

SpineManager.init(this.stage);

Sprite Render

Use Sprite to render Spine objects, which supports the following features:

    1. Mask
    1. Multi texture rendering
    1. BlendMode supports (highlight overlay, multiplication)
    1. Transparency support

Demo:

var jsonData:String = Assets.getText("assets/spineboy-pro.json");
var spineTextureAtals:SpineTextureAtalsLoader = new SpineTextureAtalsLoader("assets/spineboy-pro.atlas",["assets/spineboy-pro.png"]);
spineTextureAtals.load(function(textureAtals:SpineTextureAtals):Void{
    //Sprite格式
    var openflSprite = textureAtals.buildSpriteSkeleton("spineboy-pro",jsonData);
    this.addChild(openflSprite);
    openflSprite.y = 500;
    openflSprite.x = 500;
    openflSprite.play("walk");
    openflSprite.scaleX = 0.6;
    openflSprite.scaleY = 0.6;
},function(error:String):Void{
    trace("Load fail",error);
});

Tilemap Render

Tilemap requires a tilemap for loading, which means that Spine for the same atlas only needs to be drawn once.

Spine Event Listener

General animation event listening method:

var event:AnimationEvent = new AnimationEvent();
var spine:SkeletonAnimation;
spine.state.addListener(event);
event.addEventListener(SpineEvent.COMPLETE,(event:SpineEvent)->{
    
});

Under SpriteSpine rendering objects, you can directly listen to:

var spine:SkeletonAnimation;
spine.addEventListener(SpineEvent.COMPLETE,(event:SpineEvent)->{
    
});

Starting from version 1.8.0 of openfl-spine, SpriteSpine can be batch processed. Please note that this feature is currently not available for versions after Spine 4.2.

var batch:SkeletonSpriteBatchs = new SkeletonSpriteBatchs();
for(i in 0...100){
    var spine:SkeletonAnimation = buildSpine();
    this.addChild(spine);
    spine.x = Math.random() * 300;
    spine.y = Math.random() * 300;
}

Spine Tools

Please note that this library only supports version 3.7 or 3.8 separately; Due to the issue of inconsistent data structures in Spine, reading errors may occur. Please confirm the version of Spine that needs to be used.

When using version 4.2, it will be necessary to use spine-haxe

FAQ

  1. When a resource loading error occurs, please check if the version of Spine is consistent, for example, Spine files with version 3.8 cannot be used in version 4.0.
  • This situation requires ensuring that all Spine resource versions are consistent.