2013-09-23 44 views
0

我正試圖在LibGDX 0.9.8版本中實現一個簡單的按鈕,它將更改TouchUp事件上的屏幕。但是,Eclipse向我展示了我的覆蓋TouchUp方法的黃色下劃線,表示它不在任何地方使用。LibGDX覆蓋TouchUp

public void resize(int width, int height) { 

    //Setting up stage failsafe 
    if(_stage == null){ 
     _stage = new Stage(width, height, true); 
    } 

    _stage.clear(); 

    Gdx.input.setInputProcessor(_stage); 

    TextButtonStyle style = new TextButtonStyle(); 
    style.up = _buttonSkin.getDrawable("buttonUp"); 
    style.down = _buttonSkin.getDrawable("buttonDown"); 
    style.font = _font; 

    _startButton = new TextButton("START GAME" , style); 
    _exitButton = new TextButton("EXIT", style); 

    /// 
    ///PLACING BUTTONS 
    /// 

    //start button 
    _startButton.setWidth(Gdx.graphics.getWidth()/3); 
    _startButton.setHeight(Gdx.graphics.getHeight()/4); 

    _startButton.setX((Gdx.graphics.getWidth()/8) * 3); 
    _startButton.setY((Gdx.graphics.getHeight()/5) * 3); 

    _startButton.setTouchable(Touchable.enabled); 

    _startButton.addListener(new InputListener(){ 

     public boolean touchUp(InputEvent event, float x, float y, int pointer, int button) { 
       _game.setScreen(new World(_game)); 
       System.out.print("up"); 
       return true; 
     } 

    }); 


    //adding buttons to scene 
    _stage.addActor(_startButton); 
    //_stage.addActor(_exitButton); 

我做了網絡上一些研究,有一些文章說,在一些版本LibGDX本次活動的方法是不存在的,所以我沒有檢查庫,發現我需要的方法在那裏。

In InputListener class :/** Called when a mouse button or a finger touch goes up anywhere, but only if touchDown previously returned true for the mouse 
* button or touch. The touchUp event is always {@link Event#handle() handled}. 
* @see InputEvent */ 
public void touchUp (InputEvent event, float x, float y, int pointer, int button) { 
} 

任何人都可以看到我做錯了什麼?我使用com.badlogic.gdx.scenes.scene2d.ui.TextButton中的textbutton;

+0

將「@Override」註釋添加到您希望覆蓋其父類中的某些方法(例如「@Override public boolean touchUp ...」)。 Eclipse應該給你一個關於錯誤的更好的暗示。 –

回答

2

libgdx javadocs,似乎你正在尋找is.-

public boolean touchUp(int screenX, int screenY, int pointer, int button) 

不帶參數InputEvent event的方法。確保刪除了額外的參數,將方法聲明爲public,並將標籤@Override添加爲@ P.T。建議.-

@Override 
public boolean touchUp(int screenX, int screenY, int pointer, int button) { 
    super.touchUp(screenX, screenY, pointer, button); 
    // Do your stuff here 
}