heisenthurg Posted May 8, 2016 Share Posted May 8, 2016 I have a game where items fall from the top of the screen at intervals. Currently this interval is set using a timing loop (at 5 seconds): timerPos = game.time.events.loop(Phaser.Timer.SECOND * 5, positiveBall); I would like to change the timing depending on what the score is, e.g. if the score is greater than 20, change the loop to every 4 seconds instead. I tried setting a time in a variable (spawnRate), and using the update function, like so var spawnRate = 5; create: function() [ timerPos = game.time.events.loop(Phaser.Timer.SECOND * spawnRate, positiveBall); }, update: function() { if (score > 20) { spawnRate = 4; } } This has had no effect though. I assume as the loop is set in the create function, it can't be changed like this? How else could I tackle this? Thanks Link to comment Share on other sites More sharing options...
drhayes Posted May 9, 2016 Share Posted May 9, 2016 You're right: the timing of the loop is set in create, so you can't do it that way. "events.loop" hands back a TimerEvent. You can use that object to cancel the existing timer ("game.time.events.remove(savedTimerEvent);") and make a new one. heisenthurg 1 Link to comment Share on other sites More sharing options...
heisenthurg Posted May 10, 2016 Author Share Posted May 10, 2016 I have found that you can actually adjust the loop delay using a property like so: timerPos.delay = 2000; So I am checking in my update function for the score and updating the delay as required. Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts