Skip to main content
edited body
Source Link
Fooble
  • 320
  • 1
  • 9

Here is an official Spine 2D example where they load Spineboy into a game.

https://github.com/EsotericSoftware/spine-superspineboy

The following 34 lines are used to read a texture atlas and skeleton data as well as making some animation state data.

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);

You also need a spritebatch and a skeleton renderer object.

SpriteBatch batch = new SpriteBatch();
SkeletonRenderer skeletonRenderer = new SkeletonRenderer();

The skeleton data and animation state data can then be used to create a new Skeleton and Animation State object.

Skeleton skeleton = new Skeleton(playerSkeletonData);
AnimationState animationState = new AnimationState(playerAnimationData);

You then play animations like so.

animationState.setAnimation(0, "walk", true); // trackIndex, name, loop

Then each render call, you update the animation state with delta time and apply the animation state to the skeleton.

animationState.update(delta);
animationState.apply(skeleton);

After applying the animation state to the skeleton, you can now render the skeleton.

batch.begin();
skeletonRenderer.draw(batch, skeleton);
batch.end();

Here is an official Spine 2D example where they load Spineboy into a game.

https://github.com/EsotericSoftware/spine-superspineboy

The following 3 lines are used to read a texture atlas and skeleton data as well as making some animation state data.

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);

You also need a spritebatch and a skeleton renderer object.

SpriteBatch batch = new SpriteBatch();
SkeletonRenderer skeletonRenderer = new SkeletonRenderer();

The skeleton data and animation state data can then be used to create a new Skeleton and Animation State object.

Skeleton skeleton = new Skeleton(playerSkeletonData);
AnimationState animationState = new AnimationState(playerAnimationData);

You then play animations like so.

animationState.setAnimation(0, "walk", true); // trackIndex, name, loop

Then each render call, you update the animation state with delta time and apply the animation state to the skeleton.

animationState.update(delta);
animationState.apply(skeleton);

After applying the animation state to the skeleton, you can now render the skeleton.

batch.begin();
skeletonRenderer.draw(batch, skeleton);
batch.end();

Here is an official Spine 2D example where they load Spineboy into a game.

https://github.com/EsotericSoftware/spine-superspineboy

The following 4 lines are used to read a texture atlas and skeleton data as well as making some animation state data.

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);

You also need a spritebatch and a skeleton renderer object.

SpriteBatch batch = new SpriteBatch();
SkeletonRenderer skeletonRenderer = new SkeletonRenderer();

The skeleton data and animation state data can then be used to create a new Skeleton and Animation State object.

Skeleton skeleton = new Skeleton(playerSkeletonData);
AnimationState animationState = new AnimationState(playerAnimationData);

You then play animations like so.

animationState.setAnimation(0, "walk", true); // trackIndex, name, loop

Then each render call, you update the animation state with delta time and apply the animation state to the skeleton.

animationState.update(delta);
animationState.apply(skeleton);

After applying the animation state to the skeleton, you can now render the skeleton.

batch.begin();
skeletonRenderer.draw(batch, skeleton);
batch.end();
added 1 character in body
Source Link
Fooble
  • 320
  • 1
  • 9

Here is an official Spine 2D example where they load Spineboy into a game.

https://github.com/EsotericSoftware/spine-superspineboy

The following 3 lines are used to read a texture atlas and skeleton data as well as making some animation state data.

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);

You also need a spritebatch and a skeleton renderer object.

SpriteBatch batch = new SpriteBatch();
SkeletonRenderer skeletonRenderer = new SkeletonRenderer();

The skeleton data and animation state data can then be used to create a new Skeleton and Animation State object.

Skeleton skeleton = new Skeleton(playerSkeletonData);
AnimationState animationState = new AnimationState(playerAnimationData);

You then play animations like so.

animationState.setAnimation(0, "walk", true); *// trackIndex, name, loop

Then each render call, you update the animation state with delta time and apply the animation state to the skeleton.

animationState.update(delta);
animationState.apply(skeleton);

After applying the animation state to the skeleton, you can now render the skeleton.

batch.begin();
skeletonRenderer.draw(batch, skeleton);
batch.end();

Here is an official Spine 2D example where they load Spineboy into a game.

https://github.com/EsotericSoftware/spine-superspineboy

The following 3 lines are used to read a texture atlas and skeleton data as well as making some animation state data.

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);

You also need a spritebatch and a skeleton renderer object.

SpriteBatch batch = new SpriteBatch();
SkeletonRenderer skeletonRenderer = new SkeletonRenderer();

The skeleton data and animation state data can then be used to create a new Skeleton and Animation State object.

Skeleton skeleton = new Skeleton(playerSkeletonData);
AnimationState animationState = new AnimationState(playerAnimationData);

You then play animations like so.

animationState.setAnimation(0, "walk", true); * trackIndex, name, loop

Then each render call, you update the animation state with delta time and apply the animation state to the skeleton.

animationState.update(delta);
animationState.apply(skeleton);

After applying the animation state to the skeleton, you can now render the skeleton.

batch.begin();
skeletonRenderer.draw(batch, skeleton);
batch.end();

Here is an official Spine 2D example where they load Spineboy into a game.

https://github.com/EsotericSoftware/spine-superspineboy

The following 3 lines are used to read a texture atlas and skeleton data as well as making some animation state data.

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);

You also need a spritebatch and a skeleton renderer object.

SpriteBatch batch = new SpriteBatch();
SkeletonRenderer skeletonRenderer = new SkeletonRenderer();

The skeleton data and animation state data can then be used to create a new Skeleton and Animation State object.

Skeleton skeleton = new Skeleton(playerSkeletonData);
AnimationState animationState = new AnimationState(playerAnimationData);

You then play animations like so.

animationState.setAnimation(0, "walk", true); // trackIndex, name, loop

Then each render call, you update the animation state with delta time and apply the animation state to the skeleton.

animationState.update(delta);
animationState.apply(skeleton);

After applying the animation state to the skeleton, you can now render the skeleton.

batch.begin();
skeletonRenderer.draw(batch, skeleton);
batch.end();
Source Link
Fooble
  • 320
  • 1
  • 9

Here is an official Spine 2D example where they load Spineboy into a game.

https://github.com/EsotericSoftware/spine-superspineboy

The following 3 lines are used to read a texture atlas and skeleton data as well as making some animation state data.

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);

You also need a spritebatch and a skeleton renderer object.

SpriteBatch batch = new SpriteBatch();
SkeletonRenderer skeletonRenderer = new SkeletonRenderer();

The skeleton data and animation state data can then be used to create a new Skeleton and Animation State object.

Skeleton skeleton = new Skeleton(playerSkeletonData);
AnimationState animationState = new AnimationState(playerAnimationData);

You then play animations like so.

animationState.setAnimation(0, "walk", true); * trackIndex, name, loop

Then each render call, you update the animation state with delta time and apply the animation state to the skeleton.

animationState.update(delta);
animationState.apply(skeleton);

After applying the animation state to the skeleton, you can now render the skeleton.

batch.begin();
skeletonRenderer.draw(batch, skeleton);
batch.end();