Hi
I wanna to do something when two objects are starting overlap and stop it when they are not over on them
i write this code but just first log was log in console(Player and platform are overlapping!)
for (let g_info of this.games_info) {
const portal_info = maps.games.find(p => p.name === g_info.name);
if (portal_info == undefined) continue
this.card = this.add.image(portal_info.asset1.x, portal_info.asset1.y, portal_info.asset1.name)
.setScrollFactor(1, 1)
.setScale(portal_info.asset1.scale)
if (g_info.banner) {
// ask the LoaderPlugin to load the texture
this.load.image(g_info.name, g_info.banner)
this.load.once(Phaser.Loader.Events.COMPLETE, () => {
// texture loaded so use instead of the placeholder
this.card.setTexture(g_info.name)
this.card.setDisplaySize(75, 150, 0.5)
})
}
let graphic = this.physics.add.image(portal_info.asset2.x, portal_info.asset2.y + 100, portal_info.asset2.name).setScale(portal_info.asset2.scale);
this.physics.add.existing(graphic);
graphic.body.checkCollision.right = false;
graphic.body.checkCollision.left = false;
graphic.body.checkCollision.up = false;
graphic.body.checkCollision.down = false;
graphic.body.setImmovable(true);
graphic.body.allowGravity = false;
graphic.setVisible(true);
graphic.setInteractive()
graphic.setDepth(0)
graphic.info = g_info
this.physics.add.overlap(this.o.player, graphic, overlapGameAndPlayerHandler, null, this);
this.o.platform_garphics.push(graphic)
}
function overlapGameAndPlayerHandler(player, platform) {
console.log('Player and platform are overlapping!', this.physics.world);
// Register the overlapStart event
this.physics.world.on('overlapstart', function (bodyA, bodyB, shapeA, shapeB, contact) {
if ((bodyA === this.o.player.body && bodyB === graphic.body) || (bodyA === graphic.body && bodyB === this.o.player.body)) {
console.log('Overlap started between player and platform!');
}
}, this);
// Register the overlapEnd event
this.physics.world.on('overlapend', function (bodyA, bodyB, shapeA, shapeB) {
if ((bodyA === this.o.player.body && bodyB === graphic.body) || (bodyA === graphic.body && bodyB === this.o.player.body)) {
console.log('Overlap ended between player and platform!');
}
}, this);
}