......
public void run() {
while (true) {
if (ispause) {
pauseGame();
}
if (!ispause) {
wakeUp();
}}}
// 暂停游戏
public void pauseGame() {
timer.cancel();
synchronized (this) {
try {
wait();
System.err.println("mb.ispause============"+mb.isIspause());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
// 重新开始游戏
public void wakeUp() {
timer = new Timer();
MouseMoveTask mtask = new MouseMoveTask(vc, hammer, score);
timer.schedule(mtask, 0, 1000);
synchronized (this) {
notify();
}
}
// 监听cmd
public void commandAction(Command c, Displayable arg1) {
// 暂停游戏
if (c == pauseCommand) {
ispause = true;
}
// 继续游
if (c == continueCommand) {
ispause = false;
}
}
现在的问题是一直进入wakeup()方法啊你上面本来就是个死循环吧?
public void run() {......
while (true) {
if (ispause) {
pauseGame();
}
if (!ispause) {
wakeUp();
}
}
}
public void run() {
while (true) {
if (ispause) {
pauseGame();
}
if (!ispause) {
wakeUp();
}}}
应该有个跳出的条件吧!总是走wakeUp()说明你的ispause总是为false那你要检查一下你的变量是否正确!