Collecting Coins

Im new with Phaser 3 and i have a question.

I’m doing a simple endless Runner Game right now. The player runs at the same spot on a platform, he only needs to jump. The background moves continuously.

Now i want to add coins that float randomly through the gamearea and that I can collect it. I just want to add a coin that appears again and again even if the player has already collected it. I have already tried it with tweens but it didn’t come back when I picked it up.

Any tips?

Welcome D_ka,
I would suggest enabling overlap in your physics engine between the coin and the player. Then simply spawn the coin on the left or right side of the screen and move it towards your player at the same pace as your ground. Once the coin is collected, destroy it and repeat.

1 Like

This solution works great for just about any kind of collectible in any game. Because you can specify a function that can virtually do anything you want it to once the overlap takes place. Super powerful!

You could also use disableBody on the coin when it’s touched, then reverse the effect after a certain time.
I highly recommend looking at the following tutorials: