Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.esotericsoftware.spine.html5;
- import com.badlogic.gdx.ApplicationAdapter;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.graphics.GL20;
- import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch;
- import com.badlogic.gdx.graphics.g2d.TextureAtlas;
- import com.esotericsoftware.spine.AnimationState;
- import com.esotericsoftware.spine.AnimationStateData;
- import com.esotericsoftware.spine.Skeleton;
- import com.esotericsoftware.spine.SkeletonData;
- import com.esotericsoftware.spine.SkeletonJson;
- import com.esotericsoftware.spine.SkeletonRenderer;
- public class SpineHtml5 extends ApplicationAdapter {
- PolygonSpriteBatch batch;
- SkeletonRenderer renderer;
- Skeleton skeleton;
- AnimationState state;
- public void create () {
- batch = new PolygonSpriteBatch();
- renderer = new SkeletonRenderer();
- renderer.setPremultipliedAlpha(true);
- SkeletonJson json = new SkeletonJson(new TextureAtlas(Gdx.files.internal("raptor.atlas")));
- json.setScale(0.6f);
- SkeletonData skeletonData = json.readSkeletonData(Gdx.files.internal("raptor.json"));
- skeleton = new Skeleton(skeletonData);
- AnimationStateData stateData = new AnimationStateData(skeletonData);
- stateData.setDefaultMix(0.2f);
- state = new AnimationState(stateData);
- //play(new String[] {"idle", "walk", "jump", "run"}, new float[] {0, 2, 1.75f, 0});
- play(new String[] {"walk"}, new float[] {0});
- }
- void play (String[] names, float[] delays) {
- state.setAnimation(0, names[0], true);
- for (int i = 1, n = names.length; i < n; i++)
- state.addAnimation(0, names[i], true, delays[i]);
- }
- public void render () {
- state.update(Gdx.graphics.getDeltaTime());
- state.apply(skeleton);
- skeleton.updateWorldTransform();
- skeleton.setPosition(Gdx.graphics.getWidth() / 2, 20);
- Gdx.gl.glClearColor(0, 0, 0, 1);
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
- batch.begin();
- renderer.draw(batch, skeleton);
- batch.end();
- }
- public void resize (int width, int height) {
- batch.getProjectionMatrix().setToOrtho2D(0, 0, width, height);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment