让变化成为计划的一部分

欢迎大家探讨本Blog涉及的所有软件课题。我的Google Talk ID:zhengyun(at)gmail.com。

我最希望软件带给用户的感受是:美好的体验、舒适感、简约、干净...

posts - 32, comments - 8, trackbacks - 0, articles - 0
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

比如你的游戏正在进行中,却突然一个电话,那么你能保证你的游戏不死机吗?
解决来电问题,唯一需要做的就是重载Canvas的hideNotify()方法。

just like this:

boolean gameIsPaused;
 
protected void showNotify() {  gameIsPaused = false;
}

 
protected void hideNotify() {
  gameIsPaused 
= true;
}

 
private void theMainGameLoop() {
  
while (gameIsRunning) {
    
if (!gameIsPaused) {
      
// process events and update the screen
    }

  }

}

不过,正像下面的帖子中谈到的,Nokia 7650机型的问题是无法克服的,当你接电话时关闭了游戏,那么电话打完后你也无法启动游戏了,除非重启手机。


可供参考的帖子:
http://forum.java.sun.com/thread.jspa?forumID=76&threadID=581789
http://forum.java.sun.com/thread.jspa?forumID=76&threadID=376907


评论

# re: [JavaME]解决来电问题(Incoming Call)  回复  更多评论   

2005-11-16 23:17 by 让变化成为计划的一部分
参考的资料《Nokia 中的暂停功能》:
实际上,当MIDlet 隐藏时,它总是处于暂停状态。这在游戏应用软件中尤其重要,因为,如果在游
戏被隐藏时没有立刻暂停,游戏者可能会输掉游戏。
可以用类Displayable 的方法isShown()或者类Canvas 或CustomItem 的方法 hideNotify() 来暂停MIDlet。
在Canvas 对象离开显示屏后,方法hideNotify()将被立刻调用。在方法hideNotify()中创建
一个自动暂停机制,用来暂停线程、关闭计时器、保存重要数值等。参见下面的代码范例:
protected void hideNotify()
{
//执行暂停时的操作
remainingTime = endTime – System.currentTimeMillis();
myThread.stop();
autoPaused = true;
repaint();
// Include a pause test in paint() method to check if paused
// paint a pause message on screen if autoPaused true
}
protected void paint(Graphics g)
{
// paint game screen here
if (autoPaused == true) {
// paint pause message
}
}
暂停之后的操作是继续,故需要把Continue 选项显示给用户。

只有注册用户登录后才能发表评论。


网站导航: