Java Libgdx角色运行动画未显示

Java Libgdx角色运行动画未显示,java,android,animation,libgdx,Java,Android,Animation,Libgdx,我的运动动画未播放。我的角色仍然会显示姿势,但移动时它会保持在静态位置。动画循环似乎无法播放 我的代码如下: public class Char extends Sprite { public enum State { STANDING, RUNNING }; public State currentState; public State previousState; TextureRegion region; private TextureRegion Still;

我的
运动动画
未播放。我的角色仍然会显示姿势,但移动时它会保持在静态位置。
动画循环
似乎无法播放

我的代码如下:

public class Char extends Sprite {

  public enum State {   STANDING, RUNNING };
  public State currentState;
  public State previousState;
  TextureRegion region;
  private TextureRegion Still;
  private Animation Go;

  private float stateTimer;

  public World world;
  public Body b2body;

  public Char(World world, PlayScreen screen){
    super(screen.getAtlas().findRegion("NewRun"));

    currentState = State.STANDING;
    previousState = State.STANDING;
    stateTimer = 0;

    Array<TextureRegion> frames = new Array<TextureRegion>();

    for(int i = 1; i < 4; i++)
      frames.add(new TextureRegion(getTexture(),i* 53,0,53,48));
    Go = new Animation(0.1f, frames);

    frames.clear();

    Still = new TextureRegion(getTexture(),0,0,53,50);
    setBounds(0, 0, 50 / Game.PPM, 65 / Game.PPM);
    setRegion(Still);
    this.world = world;
    defineChar();
  }

  public void update(float dt) {
    setPosition(b2body.getPosition().x - getWidth() / 2, b2body.getPosition().y - getHeight() / 2);
    setRegion(getFrame(dt));
  }

  public TextureRegion getFrame(float dt) {
    currentState = getState();
    switch(currentState){
      case RUNNING:
        Go.getKeyFrame(stateTimer, true);
        break;
      case STANDING:
      default:
        region = Still;
        break;
    }

    stateTimer = currentState == previousState ? stateTimer + dt : 0;
    //update previous state
    previousState = currentState;
    //return our final adjusted frame
    return region;
  }

  public void defineChar(){
    BodyDef bdef = new BodyDef();
    bdef.position.set(50/ JoD.PPM, 20/ JoD.PPM);
    bdef.type =BodyDef.BodyType.DynamicBody;
    b2body = world.createBody(bdef);

    FixtureDef fdef = new FixtureDef();

    CircleShape shape =new CircleShape();
    shape.setRadius(4);

    fdef.shape= shape;
    b2body.createFixture(fdef);//.setUserData(this);
  }

  public State getState(){
    if(b2body.getLinearVelocity().x != 0)
      return State.RUNNING;
    //if none of these return then he must be standing
    else
     return State.STANDING;
  }

}
public类字符扩展了Sprite{
公共枚举状态{正在运行};
公共国家;
公共国家优先国家;
结构区;
私人区域仍然;
私人动画围棋;
专用浮点状态计时器;
公共世界;
公共机构;
公共字符(世界世界,播放屏幕){
super(screen.getAtlas().findRegion(“NewRun”);
currentState=State.STANDING;
previousState=State.STANDING;
stateTimer=0;
数组帧=新数组();
对于(int i=1;i<4;i++)
添加(新的TextureRegion(getTexture(),i*53,0,53,48));
Go=新动画(0.1f,帧);
frames.clear();
仍然=新的纹理区域(getTexture(),0,0,53,50);
挫折(0,0,50/Game.PPM,65/Game.PPM);
设置区域(静止);
这个世界=世界;
defineChar();
}
公共无效更新(浮动dt){
setPosition(b2body.getPosition().x-getWidth()/2,b2body.getPosition().y-getHeight()/2);
setRegion(getFrame(dt));
}
公共纹理区域getFrame(浮点dt){
currentState=getState();
开关(当前状态){
案件审理:
Go.getKeyFrame(stateTimer,true);
打破
案情:
违约:
区域=静止;
打破
}
stateTimer=currentState==previousState?stateTimer+dt:0;
//更新以前的状态
previousState=当前状态;
//返回我们的最终调整帧
返回区;
}
公开无效定义(){
BodyDef bdef=新的BodyDef();
bdef位置设置(50/JoD.PPM,20/JoD.PPM);
bdef.type=BodyDef.BodyType.DynamicBody;
b2body=world.createBody(bdef);
FixtureDef fdef=新的FixtureDef();
圆形形状=新的圆形形状();
形状。设置半径(4);
形状=形状;
b2body.createFixture(fdef);//.setUserData(this);
}
公共状态getState(){
if(b2body.getLinearVelocity().x!=0)
返回状态。正在运行;
//如果这些都没有回来,那么他一定是站着的
其他的
返回状态。状态;
}
}
我看过多个教程,但不明白为什么动画没有播放完。

有人能看到我遗漏了什么吗?

您是否遗漏了getFrame(float dt)方法中对区域的赋值?你画的区域总是“静止”的


您能保证精灵正在接收更新事件吗?如果已显式将状态设置为RUNNING,动画是否工作?
switch(currentState){
      case RUNNING:
        //Go.getKeyFrame(stateTimer, true);
        //Should be ...
        region = Go.getKeyFrame(stateTimer, true);
        break;
      case STANDING:
      default:
        region = Still;
        break;
    }