Hi, I’m having difficulty getting the overlap function to work properly. According to the docs, the event emits when at least one of the two has onOverlap set to true. I’ve messed around with a Phaser example to see if I could get it running on there, but it doesn’t seem to be working. Am I doing something wrong?
You can basically paste this:
var config = {
type: Phaser.AUTO,
antialias: false,
width: 800,
height: 600,
parent: 'phaser-example',
physics: {
default: 'arcade',
arcade: {debug: true}
},
scene: {
preload: preload,
create: create,
update: update
}
};
var sprite;
var group;
new Phaser.Game(config);
function preload ()
{
this.load.image('mushroom', 'assets/sprites/mushroom2.png');
this.load.image('ball', 'assets/sprites/shinyball.png');
}
function create ()
{
sprite = this.physics.add.image(400, 300, 'mushroom')
.setVelocity(100, 200)
.setBounce(1, 1)
.setCollideWorldBounds(true)
.setGravityY(200);
group = this.physics.add.staticGroup({
key: 'ball',
frameQuantity: 30
});
sprite.body.onOverlap = true;
Phaser.Actions.PlaceOnRectangle(group.getChildren(), new Phaser.Geom.Rectangle(84, 84, 616, 416));
group.refresh();
this.physics.world.on('overlap', function() {alert('hi')}, this);
//this.physics.add.overlap(sprite, group);
}
function update ()
{
//sprite.body.debugBodyColor = sprite.body.touching.none ? 0x0099ff : 0xff9900;
}
unto this example, http://labs.phaser.io/edit.html?src=src/physics/arcade/overlap%20collider.js&v=3.19.0
What’s wrong with the code? Why won’t it alert??