Just once (collision)

How to make the sprite’s player collide with another sprite and add 5 points to score, but only do it once.

Collisions will keep firing as long as the two things are touching. Depending on your situation, you need to do something like kill one of the sprites, have the two sprites bounce apart or set a timer as a process callback to only allow a second collision after a certain amount of time. More details needed and your current code…

I want to make this:

_Add 5 points to player
_Subtract 5 points to enemy
_Destroy object “base”
_Create sprite (50, 100, ‘sword’)
_Wait 1 second // I don’t understand this part
_And then set Player.y = 600

Could someone help me with the time event?

Let timer = scene.time.delayedCall(delay, callback, args, scope); // delay in ms

So for example
let timer = scene.time.delayedCall(1000, () => {this.player.y = 600}, [], this) ; // delay in ms

https://photonstorm.github.io/phaser3-docs/Phaser.Time.Clock.html

I solved!

this.time.addEvent({callback: () => {jugador.y = 600}, delay: 1000, callbackScope: this, loop: true})

1 Like

Unless you want jugador’s y position to be set to 600 every second indefinitely, then I suggest changing loop to false :blush:

1 Like