简体   繁体   English

如何在libgdx中使“再次播放”按钮?

[英]How do you make play again button in libgdx?

I have a button on my game where it set the screen on my game screen and it's located on my menu screen. 我的游戏上有一个按钮,它在游戏屏幕上设置屏幕,并且在菜单屏幕上。 So what happens is that when my character dies it just goes back to the menu screen, what I wan't to do is when I lose there will be just a button that will let you play again and a box that shows your score and the best score, I want to know what that box is called, is it just a texture that will show up when a condition is true? 所以发生的事情是,当我的角色去世时,它只是回到菜单屏幕,我不想要做的是当我输了时,只有一个按钮可以让您再次玩耍,而一个框会显示您的得分和最好的分数,我想知道那个盒子叫什么,只是当条件为真时才会显示的纹理吗? and also how do you make those effect where the button or text will go upwards and stop when they are the correct position (or other effects when they show up on the screen). 以及如何使按钮或文本在正确的位置(或者在屏幕上显示其他效果)时向上和停止的效果。

I find it unlikely that when your character dies the game automatically goes to the main menu screen again. 我发现当您的角色去世时,游戏不太可能自动再次进入主菜单屏幕。 It's more likely you are doing some tutorial or took some code that tells the program to go back to the main menu when the character dies. 您更有可能正在做一些教程或编写了一些代码,这些代码告诉程序角色死后返回主菜单。

Anyway, in my latest game I simply had a stack actor as the first actor on my stage. 无论如何,在我最新的游戏中,我只是让堆叠演员成为舞台上的第一位演员。 There I would just put in the interface and all like someone normally would. 在那里,我只需要输入界面,就像通常的情况一样。 When I need a screen on top I would just add it to the base stack. 当我需要顶部的屏幕时,只需将其添加到基本堆栈中即可。 This could be a pause display with a unpause, restart and exit button. 这可能是带有取消暂停,重新启动和退出按钮的暂停显示。 Or this could be a game over screen where scores are calculated with exit and replay buttons. 或这可能是一个屏幕游戏,其中的得分是使用退出和重播按钮来计算的。

Stage stage;
Stack stack; //scene2D.ui.Stack
Table mainTable;
Table overlayTable;

public GameScreen()
{
  stage = new Stage();
  stack = new Stack();
  mainTable = new Table();
  overlayTable = new overlayTable();

  stage.addActor(stack);
  stack.addActor(mainTable);
  stack.addActor(overlayTable);  
}

Now just setup the mainTable like you would normally layout your interface/game. 现在,只需像通常布局界面/游戏一样设置mainTable The overlayTable is used to display stuff overlayed on your main table. overlayTable用于显示叠加在主表上的内容。 I clear it when it's not needed anymore and build it up again when the player pauses or finishes the level. 我会在不再需要它时清除它,并在玩家暂停或结束关卡时再次建立它。 You can also use separate tables for this like pauzeTable , successTable , failedTable , etc. and hide or display these on demand. 您还可以使用单独的表这个像pauzeTablesuccessTablefailedTable等,隐藏或按需显示这些。

For the effects you simply use Scene2D Actions , MoveToAction or MoveByAction specifically. 对于效果,只需使用Scene2D ActionsMoveToActionMoveByAction You can set a action for each button/actor so you have more control over them individually or just a single MoveToAction for the whole table. 您可以为每个按钮/角色设置一个动作,这样您就可以单独控制它们,也可以为整个表格仅设置一个MoveToAction。

Table actionTable = new Table();
    //position the table outside the screen
    actionTable.setPosition(stage.getWidth(), 0); //Position on the right of the stage

    MoveToAction moveAction = new MoveToAction();
    moveAction.setPosition(0, 0); //Move from right side of stage inside the stage
    moveAction.setDuration(.5f); //Duration of this action
    moveAction.setInterpolation(Interpolation.fade); //Fade the movement in and out, many interpolations are supplied by the framework.

    actionTable.addAction(moveAction); //Execute Action.     

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM