LibGdx: 如何在Actor上实现手势操作

3
我正在尝试使用ActorGestureListener在LibGdx中实现角色手势。以下代码绘制了角色,但pan方法未被调用。我错过了什么吗?
我使用的是LibGdx 1.3.1版本。
   public class MyApp extends ApplicationAdapter {

        private Stage stage;

        @Override
        public void create() {
            stage = new Stage(new ExtendViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()));
            Gdx.input.setInputProcessor(stage);

            final Shape circle = new Circle(); // Actor that draws a texture
            stage.addActor(circle);

            circle.addListener(new ActorGestureListener(){
                public void pan (InputEvent event, float x, float y, float deltaX, float deltaY) {
                    Gdx.app.log("", "pan");
                    event.getTarget().moveBy(deltaX, deltaY);
                }
            });

            circle.setTouchable(Touchable.enabled);
        }


        @Override
        public void render() {
            Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
            stage.act(Gdx.graphics.getDeltaTime());
            stage.draw();
        }
    }

你是否通过setBounds或setWidth/Height为Circle设置了大小? - DHa
1个回答

0
    If you inherit from Actor, you need to set the bounds or it will not be click/touch-able!.
    Simply set the bounds to match the texture your Actor contains.

    //add this Set bounds the x, y, width, and height
                circle.setBounds(0, 0,texture.getWidth(),
texture.getHeight());
    //add this Sets the origin position which is relative to the actor's bottom left corner.
                circle.setOrigin(0, 0);   


            stage.addActor(circle);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接