0
我正在开发一款游戏。在我的游戏中,我有一个对话框来关闭和恢复游戏。我想要的是当我按下对话框的“否”按钮,然后开始从3到0计数,然后恢复游戏。 请告诉我如何在游戏屏幕中心以透明文本视图实现CountDown计时器,以及在3秒后计时器不可见。 请通过编辑我的代码来解决我的问题。 这里是我的AlertDialogCountDown计时器在游戏屏幕中央显示透明textview
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
GamePanel.thread.setRunning(false);
// in the next line of code we also style the dialog through xml which i put in styles
AlertDialog alertDialog = new AlertDialog.Builder(this,R.style.myBackgroundStyle).create();
alertDialog.setTitle("Exit Alert");
alertDialog.setMessage("Do you really want to exit the Game?");
alertDialog.setButton("Yes", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which) {
//Best way is firstly use finish() and after that use System.exit(0) to clear static variables. It will give you some free space.
// A lot of applications leave working processes and variables what makes me angry. After 30 minutes of using memory is full and i have to run Task Manager - Lvl 2 clear memory
finish();
System.exit(0);
return;
} });
alertDialog.setButton2("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
GamePanel.thread.setRunning(true);
return;
}});
alertDialog.show();
return true;
}
return super.onKeyDown(keyCode, event);}
任何帮助,将不胜感激的代码。谢谢!
当我按下我的“否”按钮游戏被卡住,没有响应。 –
popupwindow是否显示?如果你不使用asynctask,游戏是否响应? – xxxzhi
不,没有弹出窗口。当我按下对话框的“否”按钮时,我的游戏刚刚停止并且没有响应。如果您对我的问题有任何想法,请编辑我的代码谢谢。 –