Guest User

Untitled

a guest
Jan 17th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. import com.badlogic.gdx.graphics.g2d.Animation;
  2. import com.badlogic.gdx.graphics.g2d.TextureRegion;
  3. import com.badlogic.gdx.scenes.scene2d.ui.Image;
  4. import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
  5.  
  6. public class ImageAnimation extends Image
  7. {
  8. private Animation<TextureRegion> animation;
  9. private float time;
  10. protected float speed = 1f;
  11.  
  12. protected TextureRegionDrawable drawable = new TextureRegionDrawable();
  13.  
  14. public ImageAnimation() {
  15. super();
  16. setDrawable(drawable);
  17. }
  18.  
  19. public void setAnimation(Animation<TextureRegion> animation) {
  20. this.animation = animation;
  21. }
  22.  
  23. public void setPose(TextureRegion textureRegion) {
  24. drawable.setRegion(textureRegion);
  25. setDrawable(drawable);
  26. invalidateHierarchy();
  27. setSize(getPrefWidth(), getPrefHeight());
  28. invalidate();
  29. this.animation = null;
  30. }
  31.  
  32. @Override
  33. public void act(float delta)
  34. {
  35. time += delta * speed;
  36. if(animation != null && animation.getAnimationDuration() > 0){
  37. TextureRegion frame = animation.getKeyFrame(time, true);
  38. drawable.setRegion(frame);
  39. setDrawable(drawable);
  40. invalidateHierarchy();
  41. invalidate();
  42. }else{
  43. // setDrawable(null);
  44. }
  45. super.act(delta);
  46. }
  47. }
Add Comment
Please, Sign In to add comment