Jump to content

PhaserJS Timer/Counter


xronn
 Share

Recommended Posts

Hi, 

I want to have a timer running in the background of my game to keep my game fresh and sort of random, I'm not sure if phaser can help with this or I should just use normal javascript, the timer would be used for these functions;

After 10 - 15 seconds display story overlay 

After 20 - 30 seconds spawn 2 monsters 

After 35 - 40 seconds spawn 5 monsters 

After 40 - 60 seconds show second story overlay

I would use Math.floor & Math.random to generate your player profile before you start the game so all these variables would be set and just be waiting for the timer to tick to that desired time. 

 

 

Thanks!
 

Note using: v1.1.3 - Built at: Fri Nov 29 2013 18:20:59

 

Link to comment
Share on other sites

You could use a timer variable and game.time.elapsed.

Add elapsed on each frame, and compare it to the predetermined values, and fire off the function needed at that time.

var timer = 0;update: function(){timer += game.time.elapsed;if (timer >= 10) //value 1    displayStoryOverlay();else if (timer >= 20)    spawnTwoMobs();else if (timer >= 30)    spawnFiveMobs();else if (timer >= 40){    displayStoryOverlayTwo();    timer = 0; //reset timer after the last event...}

The latest Phaser has a Timer object where you can set delays and attach callbacks, but you did mention you are using 1.1.3.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...