2013-12-16 34 views
1

噢,好吧...我有一個問題,我不知道什麼是錯的。使用InputListener檢測滾動

我有一個桌子裏面有幾塊瓷磚(128x128大小的方形演員)。

我想要做的是,當我向上滾動時,相機縮小,當我向下滾動時,相機放大。 我閱讀了libgdx文檔並想出了一種嘗試做這種工作的方法,但是..有些東西丟失,我不知道它是什麼,有點看起來像InputListener沒有得到我的滾動操作。

爲了測試它,我試着只是將一些關於滾動動作的信息輸出到控制檯,但那並不奏效。

這裏是我的InputListener:

private class MouseEvents extends InputListener{ 

    public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) { 
     setDrawable(new TextureRegionDrawable(new TextureRegion(selected))); 
    } 

    public void exit(InputEvent event, float x, float y, int pointer, Actor fromActor) { 
     setDrawable(new TextureRegionDrawable(new TextureRegion(unselected))); 
    } 

    public boolean scrolled(InputEvent event, float x, float y, int amount){ 
     System.out.println("ZoomValue: " + amount + " at " + x + "x" + y); 
     return true; 
    } 

} 

的進入和退出方法很好地工作,但滾動一個沒有,如果我這個監聽器添加到瓷磚或收聽剛剛與滾動()方法到舞臺,甚至與瓷磚表,沒有任何反應。

我的想法是將其添加到舞臺以放大和縮小視口,但是......好吧,有什麼想法?

預先感謝您。

回答

-1

考慮使用mouseWheelMoved方法。它內置於Java,並且應該爲你找到你想要的東西。考慮到here,我可以提供更深入的教程。

+0

'mouseWheelMoved'是AWT控制的方法,該問題是關於[libgdx](http://libgdx.badlogicgames.com/)。 – Thomas

1

您必須使用InputProcessor

public class MyInputProcessor implements InputProcessor { 

    @Override 
    public boolean scrolled (int amount){ 
     //Use the ammount wisely! 
     return false; 
    } 

    @Override public boolean keyDown (int keycode) { return false; } 
    @Override public boolean keyUp (int keycode) { return false; } 
    @Override public boolean keyTyped (char character) { return false; } 
    @Override public boolean touchDown (int x, int y, int pointer, int button) { return false; } 
    @Override public boolean touchUp (int x, int y, int pointer, int button) { return false; } 
    @Override public boolean touchDragged (int x, int y, int pointer) { return false; } 
    @Override public boolean touchMoved (int x, int y) { return false; } 
} 

不要忘記設置:

MyInputProcessor inputProcessor = new MyInputProcessor(); 
Gdx.input.setInputProcessor(inputProcessor); 

參考:Event Handling