# Overlap doesn't work

**URL:** <https://phaser.discourse.group/t/overlap-doesnt-work/6039>\
**Category:** Phaser 3\
**Created:** [April 22, 2020, 3:44pm UTC](https://phaser.discourse.group/t/overlap-doesnt-work/6039 "2020-04-22T15:44:57Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Felicia\_Debye](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/felicia_debye/32/3220_2.png) [@Felicia\_Debye](https://phaser.discourse.group/u/Felicia_Debye)\
**Post date:** [April 22, 2020, 3:44pm UTC](https://phaser.discourse.group/t/overlap-doesnt-work/6039/1 "2020-04-22T15:44:57Z")

</div>

Hi everybody  
i try to make an mini jump 'n run game where the Player have to collect cake.  
Everything works fine, until i add the overlap-method.

Here is my code:

var player;  
var cursors;  
var muffins;

class Level extends Phaser.Scene {

```
constructor() {

	super("Level");
	
}		

/*init(data){
	this.playerImageKey = data.playerImageKey;
}*/

create(){
	this.physics.world.setBounds(0, 0, 3000, 450);
	
	//set background
	var bg = this.add.image(0, 0, "background");
	bg.setOrigin(0.0, 0.0);
	
	//add cursors
	cursors = this.input.keyboard.createCursorKeys();
	
	//add platforms
	var platforms = this.physics.add.staticGroup();
	platforms.create(1500, 412, "underground");
    platforms.create(423.93912, 296.82156, "platform");
    platforms.create(846.91864, 211.04117, "platform");
	platforms.create(1272.8494, 234.70657, "platform");
	platforms.create(2089.235, 255.41022, "platform");
	platforms.create(2515.173, 157.80673, "platform");
	platforms.create(2956.3782, 155.90817, "platform");
	
	//add player
	player = this.physics.add.sprite(90,0, "char1-side-0");
	player.setScale(0.04,0.04);
	player.anims.play("char1-run");
	
	player.setBounce(0.2);
	player.setCollideWorldBounds(true);

	//add camera
	this.cameras.main.setBounds(0, 0, 3000, 450);
	this.cameras.main.startFollow(player, true);
	this.cameras.main.followOffset.set(-300, 0);
	
	//add muffins
	muffins = this.physics.add.group({
        key: "muffin",
        repeat: 20,
        setXY: { x: 300, y: 0, stepX: 130 }
	});
	
	muffins.children.iterate(function (child) {
    	child.setBounceY(Phaser.Math.FloatBetween(0.4, 0.6));
	});
	
	//collide the player and the muffins with the platforms
	this.physics.add.collider(player, platforms);
	this.physics.add.collider(muffins, platforms);
	
	// if i add this method, the scene doesn't even get loaded
	this.physics.add.overlap(player, muffins, collectMuffin, null, this);
}

collectMuffin(player, muffin) {
    muffin.disableBody(true, true);
}

update() {
    if(cursors.right.isDown) {
		player.setVelocityX(100);
		this.cameras.main.followOffset.x = -300;
	} else if (cursors.right.isUp) {
		player.setVelocityX(0);
	} 
	
	if(cursors.up.isDown) {
      player.setVelocityY(-200);
    }
}

```

}

And here is my configuration:

```
var game = new Phaser.Game({
"title": "infoteam-Universe",
"width": 800,
"height": 450,
"type": Phaser.AUTO,
"backgroundColor": "#88F",
"parent": "game-container",
"physics": {
    default: 'arcade',
    arcade: {
        gravity: { y: 300 },
        debug: false
    }
},
"scale": {
    "mode": Phaser.Scale.FIT,
    "autoCenter": Phaser.Scale.CENTER_BOTH
}
});

```

Can anybody help me to fix it?  
Thank you!

---

<div class="post-metadata">

**Author:** ![ReydVires](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/reydvires/32/939_2.png) [@ReydVires](https://phaser.discourse.group/u/ReydVires)\
**Post date:** [April 22, 2020, 3:55pm UTC](https://phaser.discourse.group/t/overlap-doesnt-work/6039/2 "2020-04-22T15:55:46Z")

</div>

Is there any particular error that show on you console log?

---

<div class="post-metadata">

**Author:** ![Felicia\_Debye](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/felicia_debye/32/3220_2.png) [@Felicia\_Debye](https://phaser.discourse.group/u/Felicia_Debye)\
**Post date:** [April 22, 2020, 5:53pm UTC](https://phaser.discourse.group/t/overlap-doesnt-work/6039/3 "2020-04-22T17:53:57Z")

</div>

I am working with Phaser Editor and being new in this whole Framework and IDE. How can i see the errors?

---

<div class="post-metadata">

**Author:** ![UltimateProGrammer](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/ultimateprogrammer/32/3069_2.png) [@UltimateProGrammer](https://phaser.discourse.group/u/UltimateProGrammer)\
**Post date:** [April 22, 2020, 8:24pm UTC](https://phaser.discourse.group/t/overlap-doesnt-work/6039/4 "2020-04-22T20:24:05Z")

</div>

I have used Phaser Editor before. Click play in the top left. Then you can use your preferred browser’s devtools. If it says you have an error when you click play, your code has an error that Phaser Editor saw. It should show up as a red underline in the file.

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [April 22, 2020, 8:42pm UTC](https://phaser.discourse.group/t/overlap-doesnt-work/6039/5 "2020-04-22T20:42:25Z")

</div>

What goes wrong?

---

<div class="post-metadata">

**Author:** ![Felicia\_Debye](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/felicia_debye/32/3220_2.png) [@Felicia\_Debye](https://phaser.discourse.group/u/Felicia_Debye)\
**Post date:** [April 23, 2020, 7:07am UTC](https://phaser.discourse.group/t/overlap-doesnt-work/6039/6 "2020-04-23T07:07:41Z")

</div>

It doesn’t say, i have an error. It works until i came to the Scene “Level” in which i would like to check the overlap and then stop playing. If i uncomment this line, even the Level-Scene works fine but the muffins are still visible when the Player overlap with them.

---

<div class="post-metadata">

**Author:** ![Felicia\_Debye](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/felicia_debye/32/3220_2.png) [@Felicia\_Debye](https://phaser.discourse.group/u/Felicia_Debye)\
**Post date:** [April 23, 2020, 7:57am UTC](https://phaser.discourse.group/t/overlap-doesnt-work/6039/7 "2020-04-23T07:57:03Z")

</div>

Here are two recordings: One with the “overlap-line” uncommented and the other on with the “overlap-line” active. [https://drive.google.com/open?id=1uDzWDeQfaH0y7SGqeN8gpQS9rL7ifT0m](https://drive.google.com/open?id=1uDzWDeQfaH0y7SGqeN8gpQS9rL7ifT0m)

---

<div class="post-metadata">

**Author:** ![UltimateProGrammer](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/ultimateprogrammer/32/3069_2.png) [@UltimateProGrammer](https://phaser.discourse.group/u/UltimateProGrammer)\
**Post date:** [April 23, 2020, 12:57pm UTC](https://phaser.discourse.group/t/overlap-doesnt-work/6039/8 "2020-04-23T12:57:39Z")

</div>

So what errors are you getting when you have the line running?  
[Here is a tutorial on how to open the console. Make sure you switch to the console tab to see the errors.](https://www.hostinger.com/tutorials/website/how-to-inspect-and-change-style-using-google-chrome)

---

<div class="post-metadata">

**Author:** ![Felicia\_Debye](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/felicia_debye/32/3220_2.png) [@Felicia\_Debye](https://phaser.discourse.group/u/Felicia_Debye)\
**Post date:** [April 23, 2020, 1:38pm UTC](https://phaser.discourse.group/t/overlap-doesnt-work/6039/9 "2020-04-23T13:38:11Z")

</div>

Ahh: “Uncaught ReferenceError: collectMuffin is not defined”.  
But i still don’t know why 😅

---

<div class="post-metadata">

**Author:** ![BlunT76](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/blunt76/32/1454_2.png) [@BlunT76](https://phaser.discourse.group/u/BlunT76)\
**Post date:** [April 23, 2020, 1:41pm UTC](https://phaser.discourse.group/t/overlap-doesnt-work/6039/10 "2020-04-23T13:41:45Z")

</div>

try with:  
this.collectMuffin  
or  
this.collectMuffin(player, muffin)  
or  
(player, muffin) =\> this.collectMuffin(player, muffin);

---

<div class="post-metadata">

**Author:** ![Felicia\_Debye](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/felicia_debye/32/3220_2.png) [@Felicia\_Debye](https://phaser.discourse.group/u/Felicia_Debye)\
**Post date:** [April 23, 2020, 1:46pm UTC](https://phaser.discourse.group/t/overlap-doesnt-work/6039/11 "2020-04-23T13:46:46Z")

</div>

It works! Thank you!! 🙂
