Reputation: 631
I'm using Phaser.io
I'm making a simple game. I want my 'enemies' to fall from the top of the screen:
const enemies = this.physics.add.group();
function enemyGen(){
const xCoord = Math.random()*gameState.w;
enemies.create(xCoord, 10, 'enemy');
}
const enemyGenLoop = this.time.addEvent({
callback: enemyGen,
delay: ......,
callbackScope: this,
loop: true
})
I would like to decrease the delay when a player reach a certain score (which is stored in gameState.score).
I was thinking about having a variable stored in gameState.delay and then updating it from update(). The problem is that even if the gameState.delay is changed the addEvent still uses the previous value of gameState.delay.
Upvotes: 2
Views: 322
Reputation: 6312
You can store the addEvent delay into a variable & set it to another value afterwards like so:
delayTimer = this.time.addEvent({
delay: 2000,
callback: ()=>{
// calls a function here
},
loop: true
})
delayTimer.delay = 1000;
Upvotes: 1