我是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