我是LibGdx的新手,在這方面我的編程如此光禿禿的。 我正在做一個pong遊戲,我想要做的是當球通過球員槳爲球回到中間(我已經完成)和一個按鈕,當我們按下它的速度的球回到它是如何(遊戲重新開始)。 我已經是一名玩家得分時重置遊戲。我添加了按鈕和actionlistener,但actionlistener不重新啓動遊戲。這裏是我的代碼:重置按鈕LibGdx
public void StartAgain(){
if(resetButton = true){
int playButtonWidth = ballPong.getBallSizeX();
int playButtonHeight = ballPong.getBallSizeY();
ResetButtonStage = new Stage();
skin = new Skin();
font = new BitmapFont(Gdx.files.internal("font.fnt"), false);
style = new LabelStyle(font, Color.WHITE);
buttonAtlas = new TextureAtlas("buttons/playButton.pack");
skin.addRegions(buttonAtlas);
playButtonStyle = new TextButtonStyle();
playButtonStyle.up = skin.getDrawable("play");
playButtonStyle.over = skin.getDrawable("play_pressed");
playButtonStyle.down = skin.getDrawable("play_pressed");
playButtonStyle.font = font;
//------------------------------------------------------------------------------- Play button
playButton = new TextButton("", playButtonStyle);
//buttonStyle.font.setScale((float) 0.5);
playButton.setWidth(playButtonWidth);
playButton.setHeight(playButtonHeight);
playButton.setPosition(100,250);
ResetButtonStage.addActor(playButton);
playButton.addListener(new InputListener(){
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
ballPong.ballVectorX = ballPong.getBallSpeed();
ballPong.ballVectorY = ballPong.getBallSpeed();
resetButton = false;
return true;
}
});
Gdx.input.setInputProcessor(ResetButtonStage);
batch = new SpriteBatch();
ResetButtonStage.act();
ResetButtonStage.draw();
}
}
什麼香港專業教育學院試圖做的是創建一個名爲resetButton布爾值,並將其設置爲false,當一個球員的得分它設置布爾爲true,從而顯示該按鈕。但是,我錯過了這個方向。我已經完成了,所以當球的位置低於槳時,遊戲重置並且StartAgain()方法顯示。但是很顯然,球的位置現在在槳的上方(因爲已經重置),所以startAgain方法不會運行。
if(ballPong.getPosition().y<= 1){
player2Score = player2Score +1;
System.out.println("bottom");
StartAgain();
resetButton = true;
if(ballPong.reset ==true){
ballPong.reset();
}
}
我在問什麼,我應該在哪裏調用此StartAgain()方法,以及如何獲取actionlistener的工作方式。
非常感謝
does not work。如果球在槳下方,則只能將其設置爲真。所以當我重新設置它會轉到槳上面的原點,所以按鈕不再顯示:( – rekoDolph 2014-09-01 18:53:15