通过命令行安装(Install via command line)
haxelib install openfl-spine
在project.xml中配置(Configure in project.xml)
<haxelib name="openfl-spine"/>
并且在任意类中进行初始化(And initialize in any class)
SpineManager.init(this.stage);
使用Sprite渲染Spine对象,使用SpriteSpine渲染已支持以下特性:
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);
openflSprite.isCache = true; // 可提高一定的性能,如果有多个相同的Spine的情况下
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("加载失败:",error);
});
[注意] 从openfl-spine1.6.4版本开始,将启用isNative
以及multipleTextureRender
的支持,使用SpriteSpine渲染时,将自动支持多纹理渲染。
Tilemap需要一个tilemap进行装载,这意味着一样的图集的Spine只需要1drawcall。Tilemap requires a tilemap to load, which means that Spine of the same atlas only needs 1 drawcall.
通用的动画事件侦听方法:
var event:AnimationEvent = new AnimationEvent();
var spine:SkeletonAnimation;
spine.state.addListener(event);
event.addEventListener(SpineEvent.COMPLETE,(event:SpineEvent)->{
});
在SpriteSpine渲染对象下,可以直接侦听:
var spine:SkeletonAnimation;
spine.addEventListener(SpineEvent.COMPLETE,(event:SpineEvent)->{
});
在openfl-spine1.8.0版本开始,SpriteSpine可以被批处理(Starting from version 1.8.0 of openfl-spine, SpriteSpine can be batch processed):
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;
}
请注意,该库只单独支持3.7或者3.8版本;因Spine的数据结构不完全一致的问题会导致读取错误,请确认需要使用的Spine版本。 Please note that this library only supports version 3.7 or 3.8 separately; the incomplete data structure of Spine will cause reading errors. Please confirm the version of Spine you need to use.
库当前默认是使用3.7版本,默认指向spine-hx3.6.0版本。如果需要使用3.8+版本,需要在库之前定义版本号: The library currently uses version 3.7 by default and points to version spine-hx3.6.0 by default. If you need to use version 3.8+, you need to define the version number before the library:
<define name="spine3.8"/>
<haxelib name="openfl-spine"/>
在2021年10月13日,开始支持Spine4.0,如果需要使用4.0,需要在库之前定义版本号: On October 13, 2021, spine4.0 will be supported. If 4.0 needs to be used, the version number needs to be defined before the Library:
<define name="spine4"/>
<haxelib name="openfl-spine"/>