Vote count:
0
start button -> game.class
-> gameview.class
then loop again on game.class
when player finish the 1st level to generate again the 2nd level on gameview.class
. My problem is that my timer will also regenerate and restarts when going on the 2nd level. How can I make my timer pause and resume in this kind of flow of game?
on my Game.Class:
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);
and on my GameView.Class:
protected 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);
}
and when the 1st level finish it will call this method:
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();
}
How can I make my timer run until the 4 levels are cleared?
asked 22 secs ago
Timer on onDraw
Aucun commentaire:
Enregistrer un commentaire