2014-08-30 5 views
3

ActorGestureListener를 사용하여 LibGdx의 액터에 제스처를 구현하려고합니다. 다음 코드는 액터를 그리지 만 팬 메서드가 호출되지 않습니다. 내가 놓친 게 있니?LibGdx : 액터에 제스처를 구현하는 방법

저는 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(); 
     } 
    } 
+0

당신은 원에게 setBounds 또는 setWidth/신장을 통해 크기를 제공 했습니까? – DHa

답변

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); 
관련 문제