日期:2014-05-20  浏览次数:20672 次

关于屏幕切换的问题
我是新手,模仿别人的代码,做了个测试。
新建了一个MIDlet 子类,算是主类把。
然后开始游戏,
Display.getDisplay(this).setCurrent(gameclass);
然后我在这个gameclass里,开始游戏,,游戏有关卡,我想过一关卡,就出现一个“恭喜过关”的屏幕提示,
我大概写了如下

gameclass里,有个success()方法,过关就调用他,然后过几秒就自动进入游戏下一关。
我写了
  if(passgate == null)
  passgate = new PassGate(this);
  Display.getDisplay(parent).setCurrent(passgate); //parent是主类
  passgate.start();
然后我在 passgate 类里
public PassGate(GameScreen g)
{
super(false);
gamescreen = g;
}

public void run()
{
long startTime = System.currentTimeMillis();
long timeTaken = System.currentTimeMillis() - startTime;
while(timeTaken<4000L)
{
timeTaken = System.currentTimeMillis() - startTime;
repaint();
}
this.stop();
  Display.getDisplay(parent).setCurrent(gameclass);
   
  gamescreen.repaint();

}
synchronized void start()
  {
myThread = new Thread(this);
myThread.start();
  }

  synchronized void stop()
  {
  myThread = null;
  }
  public void paint()
{}

现在,提示画面掉出来了,可是不自动反回去啊。请问问题在那里,谢谢。。

------解决方案--------------------

你也说了:“gameclass里,有个success()方法,过关就调用他,然后过几秒就自动进入游戏下一关。 ”
那是几秒呢?? 代码帖完整些吧。


注意状态值得转变!!

------解决方案--------------------
恩,用TIMER类实现可能会更方便些
------解决方案--------------------
API如下: 
void setCurrent(Alert alert, Displayable nextDisplayable)
Requests that this Alert be made current, and that nextDisplayable be made current after the Alert is dismissed.
------解决方案--------------------
程序太长了.///
------解决方案--------------------
多线程去处理啊,弄个canvas的提示的类,搞个线程测时间,当时间到了就换另一个出来显示啊
------解决方案--------------------
我觉得最好是不要去用Timer,可以自己去线程去处理这种事情,并且自己起线程 的话,睡眠的时候是可以动态
更改的,灵活性会更大