SHARE
TWEET

Untitled

a guest Oct 21st, 2015 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         public class MyActor extends Actor{
  2.                 private Texture texture;
  3.                 private TextureRegion[] animationFrames;
  4.                 private AnimatedSprite animatedSprite;
  5.                 public AnimatedBox2DSprite animatedBox2DSprite;
  6.                 private Animation animation;
  7.                 private float stateTime = 0f;
  8.                 TextureRegion  currentFrame;
  9.                
  10.                 public MyActor(){
  11.                         texture = Assets.manager.get(Assets.gulubi, Texture.class);    
  12.                         splitAnimation();
  13.                         animation = new Animation(1f/35f, animationFrames);
  14.                         setPosition(0,0);      
  15.                 }
  16.                
  17.                  public void splitAnimation(){
  18.                          TextureRegion[][] tmpFrames = TextureRegion.split(texture, 240, 314);
  19.                          animationFrames = new TextureRegion[4 * 5];
  20.                          int index = 0;          
  21.                          for (int i = 0; i < 4; ++i){
  22.                                  for (int j = 0; j < 5; ++j){
  23.                                          animationFrames[index++] = tmpFrames[i][j];
  24.                                  }
  25.                          }
  26.                  }
  27.                 @Override
  28.                 public void act(float delta) {
  29.                 stateTime += delta;           // #15
  30.                 currentFrame = animation.getKeyFrame(stateTime, true);  // #16
  31.                 }
  32.  
  33.                 @Override
  34.                 public void draw(Batch batch, float parentAlpha) {
  35.                         // TODO Auto-generated method stub                        // #14
  36.                 batch.draw(currentFrame,0,0);
  37.                 }
  38.                
  39.         }
  40.  
  41.  
  42. then in my Stage class I call:
  43.             container = new Table();
  44.             MoveToAction moveAction = new MoveToAction();
  45.              moveAction.setPosition(300f, 0f);
  46.              moveAction.setDuration(10f);
  47.              MyActor ac = new MyActor();
  48.              ac.addAction(moveAction);
  49.              stage.addActor(container);
  50.  
  51.         @Override
  52.         public void render(float delta) {
  53.           Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  54.           stage.act(delta);
  55.            stage.draw();
  56.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top