首先,github是个宝库,实践流的读者可以直接看例子进行学习
1.这是Spine官方给出的例子
https://github.com/EsotericSoftware/spine-superspineboy
2.我推荐这个,很棒的例子及使用合集
https://github.com/EsotericSoftware/spine-runtimes/tree/master/spine-libgdx
下面,我详细说明一下使用步骤:
首先是读取纹理地图集和骨骼数据,这些骨骼数据也包含动画状态数据.
TextureAtlas playerAtlas = new TextureAtlas(Gdx.files.internal("spineboy/spineboy.atlas")); SkeletonJson json = new SkeletonJson(playerAtlas); SkeletonData playerSkeletonData = json.readSkeletonData(Gdx.files.internal("spineboy/spineboy.json")); AnimationStateData playerAnimationData = new AnimationStateData(playerSkeletonData);
然后需要一个spriteBatch和骨骼渲染对象.(如同tmx地图需要tmx渲染对象一样)
SpriteBatch batch = new SpriteBatch(); SkeletonRenderer skeletonRenderer = new SkeletonRenderer();
接着,用第一步读取的骨骼数据和动画状态数据创建一个骨骼和动画状态对象
Skeleton skeleton = new Skeleton(playerSkeletonData); AnimationState animationState = new AnimationState(playerAnimationData);
获取动画的方式如下:
animationState.setAnimation(0, "walk", true); // 序号, 动画名称, 循环
在每个update环节调用
animationState.update(delta);
animationState.apply(skeleton);
然后render:
batch.begin();
skeletonRenderer.draw(batch, skeleton);
batch.end();
预览
http://esotericsoftware.com/files/runtimes/spine-libgdx/raptor/
原文:http://www.cnblogs.com/mignet/p/libGDX_Spine.html