gpt4 book ai didi

java - Actor 在 screen2d 中不动

转载 作者:行者123 更新时间:2023-12-02 08:50:54 25 4
gpt4 key购买 nike

我想使用 moveToAction 并移动 Actor 。但如果我使用 moveToAction 它就不会移动。如果在绘制方法中更改 x,y 它可以工作,但不能使用 movetoaction

public class Aks extends Actor {
private State state;
private MainGame game;

private TextureAtlas movingAtlas;
private Animation movingAnimation;

private float elapsedTime = 0f;

public Aks(MainGame game) {
this.game = game;

movingAtlas = new TextureAtlas(Gdx.files.internal("atlas/myaltas/atlas.atlas"));
movingAnimation = new Animation(1f/15f, movingAtlas.getRegions());

TextureRegion texture = (TextureRegion) movingAnimation.getKeyFrame(elapsedTime, true);
setBounds(getX(),getY(),texture.getRegionWidth(),texture.getRegionHeight());

MoveToAction moveAction = new MoveToAction();
moveAction.setPosition(300f, 300f);
moveAction.setDuration(10f);
this.addAction(moveAction);


addListener(new ActorGestureListener(){
@Override
public void tap(InputEvent event, float x, float y, int count, int button) {
Gdx.app.log("Tag", "Actor touched x = " );
super.tap(event, x, y, count, button);

}
});

}

@Override
public void draw(Batch batch, float alpha){
drawFlying(batch);
}

void drawFlying(Batch batch){
TextureRegion texture = (TextureRegion) movingAnimation.getKeyFrame(elapsedTime, true);
setBounds(getX(),getY(),texture.getRegionWidth(),texture.getRegionHeight());
Gdx.app.log("Tag", "x =" + getX() + " y =" + getY() );
batch.draw(texture, getX(),getY(),50,50);
}

@Override
public void act(float delta){
elapsedTime = elapsedTime+delta;
}

}

最佳答案

需要调用super.act(delta),在actor类中,act方法控制所有的 Action ,所以如果不调用它, Action 就不会发生,反之则不需要调用super.draw() 这是因为 Actor 类只是为实体的逻辑部分创建的,您必须定义它在需要时绘制的内容。

希望对您有帮助!

关于java - Actor 在 screen2d 中不动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60779720/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com