0
开始按钮 - >game.class
- >gameview.class
然后再次循环game.class
当玩家完成第一个级别时,它会调用gameview.class
再次生成第二个级别。我的问题是我的计时器也会在第二级时重新生成并重新启动。如何让我的计时器暂停并恢复到这种游戏流程?onDraw上的定时器
public void onCreate(Bundle savedInstanceState) {
timeCounter = new TimeCounter();
super.onCreate(savedInstanceState);
Intent intent = getIntent();
Bundle extras = intent.getExtras();
this.maze = (Maze) getLastNonConfigurationInstance();
if (this.maze == null) {
this.maze = (Maze) extras.get("maze");
}
gview = new GameView(this);
gview.setTimeCounter(timeCounter);
gview.setMaze(this.maze);
setContentView(gview);
和我GameView.Class:
我Game.Classprotected void onDraw(Canvas canvas) {
if (startTimer) {
timeCounter.start();
invalidate();
int secondss = timeCounter.getTimeSeconds();
String text = String.format("%02d:%02d", secondss/60,
secondss % 60);
timer.getTextBounds(text, 0, text.length(), textBounds);
canvas.drawText(text, (this.getWidth() - textBounds.right) - 5,
(this.getHeight() - textBounds.bottom) - 5, timer);
}
,当第一级完成,它会调用这个方法:
void shownextmaze() {
Random rand = new Random();
Intent game = new Intent(context, Game.class);
nextmaze = rand.nextInt(6) + 1;
Maze maze = MazeCreator.getMaze(nextmaze);
game.putExtra("maze", maze);
context.startActivity(game);
timeCounter.resume();
}
如何让我的定时器运行,直到4级被清除?
我怎样才能做到这一点?你能分享一下这位先生@Misagh的代码吗? – icecream 2014-09-21 04:16:32
你的意思是你只调用onDraw方法来改变级别?那么onCreate方法被调用一次? – 2014-09-21 04:23:48
第一级完成后,GameView类中的shownextmaze方法将调用Game.Class,然后Game.class将调用绘制onDraw方法的GameView.Class。 – icecream 2014-09-21 04:27:53