如何在 libgdx scene2d 上拖放演员?

2024-04-16

我正在使用 libGDX 开发游戏,我想知道如何拖放 Actor。我已经搭建了舞台并绘制了演员,但我不知道如何触发该事件。

请尝试帮助我使用我自己的架构。

public class MyGame implements ApplicationListener 
{
    Stage stage;
    Texture texture;
    Image actor;

    @Override
    public void create() 
    {       
        texture = new Texture(Gdx.files.internal("actor.png"));
        Gdx.input.setInputProcessor(stage);
        stage = new Stage(512f,512f,true);

        actor = new Image(texture);
        stage.addActor(actor);
    }

    @Override
    public void render() 
    {       
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
        stage.draw();
    }
}

如果你不想使用DragAndDrop类,你可以使用这个:

actor.addListener(new DragListener() {
    public void drag(InputEvent event, float x, float y, int pointer) {
        actor.moveBy(x - actor.getWidth() / 2, y - actor.getHeight() / 2);
    }
});

编辑:方法drag反而touchDragged

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 libgdx scene2d 上拖放演员? 的相关文章

随机推荐