I have been trying to figure out how to detect collisions in Phaser.js 3, but I cannot find any working solutions. Here is my phaser code:
var gameState = {};
function preload() {
this.load.image('codey', 'https://content.codecademy.com/courses/learn-phaser/codey.png');
this.load.image('coin', 'coin.png');
}
function create() {
gameState.cursors = this.input.keyboard.createCursorKeys();
gameState.codey = this.add.sprite(50, 50, 'codey');
gameState.coin = this.add.sprite(Math.floor(Math.random() * 301), Math.floor(Math.random() * 301), 'coin');
}
function update() {
if (gameState.cursors.down.isDown) {
gameState.codey.y += 1;
}
if (gameState.cursors.up.isDown) {
gameState.codey.y -= 1;
}
if (gameState.cursors.left.isDown) {
gameState.codey.x -= 1;
}
if (gameState.cursors.right.isDown) {
gameState.codey.x += 1;
}
}
const config = {
width: 300,
height: 300,
backgroundColor: 0xdda0dd,
scene: {
preload,
create,
update
}
};
const game = new Phaser.Game(config);
Heres a link to the game: https://wornflamboyantpixels.frigidus5.repl.co/