libgdx 中的重播按钮如何制作?
How do you make play again button in libgdx?
我的游戏上有一个按钮,它在我的游戏屏幕上设置屏幕,它位于我的菜单屏幕上。所以发生的事情是,当我的角色死亡时,它只是返回到菜单屏幕,我不想做的是当我输了时,只有一个按钮可以让你再次玩,还有一个框显示你的分数和最好的分数,我想知道那个盒子叫什么,它只是一个在条件为真时会出现的纹理吗?以及如何制作按钮或文本在正确位置时向上移动并停止的效果(或当它们出现在屏幕上时的其他效果)。
我发现当你的角色死亡时游戏不太可能自动再次进入主菜单屏幕。您更有可能正在做一些教程或使用一些代码告诉程序在角色死亡时返回主菜单。
无论如何,在我最新的游戏中,我只是让一个stack actor作为我舞台上的第一个演员。在那里我会像通常的人一样放入界面。当我需要一个屏幕在顶部时,我会把它添加到基础堆栈中。这可能是一个带有取消暂停、重新启动和退出按钮的暂停显示。或者这可能是游戏结束屏幕,其中使用退出和重播按钮计算分数。
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);
}
现在只需像通常布局 interface/game 一样设置 mainTable
。 overlayTable
用于显示覆盖在主 table 上的内容。我在不再需要它时清除它,并在玩家暂停或完成关卡时重新构建它。您还可以为此使用单独的 table,例如 pauzeTable
、successTable
、failedTable
等,并根据需要隐藏或显示它们。
对于效果,您只需专门使用 Scene2D
Actions
、MoveToAction
或 MoveByAction
。您可以为每个 button/actor 设置一个动作,这样您就可以更好地单独控制它们,或者只为整个 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.
我的游戏上有一个按钮,它在我的游戏屏幕上设置屏幕,它位于我的菜单屏幕上。所以发生的事情是,当我的角色死亡时,它只是返回到菜单屏幕,我不想做的是当我输了时,只有一个按钮可以让你再次玩,还有一个框显示你的分数和最好的分数,我想知道那个盒子叫什么,它只是一个在条件为真时会出现的纹理吗?以及如何制作按钮或文本在正确位置时向上移动并停止的效果(或当它们出现在屏幕上时的其他效果)。
我发现当你的角色死亡时游戏不太可能自动再次进入主菜单屏幕。您更有可能正在做一些教程或使用一些代码告诉程序在角色死亡时返回主菜单。
无论如何,在我最新的游戏中,我只是让一个stack actor作为我舞台上的第一个演员。在那里我会像通常的人一样放入界面。当我需要一个屏幕在顶部时,我会把它添加到基础堆栈中。这可能是一个带有取消暂停、重新启动和退出按钮的暂停显示。或者这可能是游戏结束屏幕,其中使用退出和重播按钮计算分数。
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);
}
现在只需像通常布局 interface/game 一样设置 mainTable
。 overlayTable
用于显示覆盖在主 table 上的内容。我在不再需要它时清除它,并在玩家暂停或完成关卡时重新构建它。您还可以为此使用单独的 table,例如 pauzeTable
、successTable
、failedTable
等,并根据需要隐藏或显示它们。
对于效果,您只需专门使用 Scene2D
Actions
、MoveToAction
或 MoveByAction
。您可以为每个 button/actor 设置一个动作,这样您就可以更好地单独控制它们,或者只为整个 table.
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.