演员不在screen2d中移动

问题描述 投票:0回答:1

我想使用moveToAction并移动actor。但如果我使用moveToAction,它就不会移动。如果在draw方法中更改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;
    }

}
java libgdx scene2d
1个回答
0
投票

您的绘制函数需要调用super.draw(batch,alpha)才能影响子动作。

© www.soinside.com 2019 - 2024. All rights reserved.