what i mean by how to your game detect that you had a Collisions is i whant to make a function that checks if the Collisions state of two objets is true if it is true it will call a function if it is false it will not so in my case if the two boxs have a Collision it schold call on a function to make the play buttion apperir
const gameState = {}
function preload() {
// load our 'incredib/* */le' sound here!
this.load.image('intro1','/images/Screenshot 2023-10-20 10.20.39 AM.png');
this.load.image('intro2','/images/Screenshot 2023-10-20 10.23.58 AM.png');
this.load.audio('madcityintro', '/audio/a357cdfe-4a46-452f-a536-c41f8d57f35c.mp3')
}
function create() {
// add our 'incredible' sound to our scene here!
gameState.madcitysound = this.sound.add('madcityintro')
gameState.madcitysound.play()
gameState.intro1 = this.physics.add.image(-100, 200, 'intro1')
gameState.intro1.setVelocityX(500);
gameState.intro2 = this.physics.add.image(1230, 200, 'intro2')
gameState.intro2.setVelocityX(-500);
gameState.block = this.physics.add.collider(gameState.intro1, gameState.intro2);
}
function update(){
}
const config = {
type: Phaser.AUTO,
width: 999,
height: 500,
backgroundColor: "0xFF3300",
physics: {
default: 'arcade',
arcade: {
gravity: { y: 0 },
enableBody: true,
}
},
scene: {
preload,
create,
update
}
};
const game = new Phaser.Game(config);
it just did not work
2
Answers
You don’t need to build the check yourself, the
collider
function has this features builtin. Checkout the documentationSimply add the function into the
collider
function as the third parameter.here a short demo: