您的位置:首页 > 编程语言

在libGDX中使用Spine骨骼动画

2016-11-24 14:19 537 查看

在libGDX中使用Spine骨骼动画

首先,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://www.cnblogs.com/mignet/p/libGDX_Spine.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  libgdx 动画 github