Guest User

Untitled

a guest
Oct 11th, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.98 KB | None | 0 0
  1.  
  2. package com.esotericsoftware.spine.html5;
  3.  
  4. import com.badlogic.gdx.ApplicationAdapter;
  5. import com.badlogic.gdx.Gdx;
  6. import com.badlogic.gdx.graphics.GL20;
  7. import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch;
  8. import com.badlogic.gdx.graphics.g2d.TextureAtlas;
  9. import com.esotericsoftware.spine.AnimationState;
  10. import com.esotericsoftware.spine.AnimationStateData;
  11. import com.esotericsoftware.spine.Skeleton;
  12. import com.esotericsoftware.spine.SkeletonData;
  13. import com.esotericsoftware.spine.SkeletonJson;
  14. import com.esotericsoftware.spine.SkeletonRenderer;
  15.  
  16. public class SpineHtml5 extends ApplicationAdapter {
  17.     PolygonSpriteBatch batch;
  18.     SkeletonRenderer renderer;
  19.     Skeleton skeleton;
  20.     AnimationState state;
  21.  
  22.     public void create () {
  23.         batch = new PolygonSpriteBatch();
  24.  
  25.         renderer = new SkeletonRenderer();
  26.         renderer.setPremultipliedAlpha(true);
  27.  
  28.         SkeletonJson json = new SkeletonJson(new TextureAtlas(Gdx.files.internal("raptor.atlas")));
  29.         json.setScale(0.6f);
  30.         SkeletonData skeletonData = json.readSkeletonData(Gdx.files.internal("raptor.json"));
  31.  
  32.         skeleton = new Skeleton(skeletonData);
  33.  
  34.         AnimationStateData stateData = new AnimationStateData(skeletonData);
  35.         stateData.setDefaultMix(0.2f);
  36.  
  37.         state = new AnimationState(stateData);
  38.         //play(new String[] {"idle", "walk", "jump", "run"}, new float[] {0, 2, 1.75f, 0});
  39.         play(new String[] {"walk"}, new float[] {0});
  40.     }
  41.  
  42.     void play (String[] names, float[] delays) {
  43.         state.setAnimation(0, names[0], true);
  44.         for (int i = 1, n = names.length; i < n; i++)
  45.             state.addAnimation(0, names[i], true, delays[i]);
  46.     }
  47.  
  48.     public void render () {
  49.         state.update(Gdx.graphics.getDeltaTime());
  50.         state.apply(skeleton);
  51.         skeleton.updateWorldTransform();
  52.  
  53.         skeleton.setPosition(Gdx.graphics.getWidth() / 2, 20);
  54.  
  55.         Gdx.gl.glClearColor(0, 0, 0, 1);
  56.         Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  57.  
  58.         batch.begin();
  59.         renderer.draw(batch, skeleton);
  60.         batch.end();
  61.     }
  62.  
  63.     public void resize (int width, int height) {
  64.         batch.getProjectionMatrix().setToOrtho2D(0, 0, width, height);
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment