# Phaser 2 Uncaught TypeError in x

**URL:** <https://phaser.discourse.group/t/phaser-2-uncaught-typeerror-in-x/665>\
**Category:** Phaser 2 / CE\
**Created:** [January 8, 2019, 6:52pm UTC](https://phaser.discourse.group/t/phaser-2-uncaught-typeerror-in-x/665 "2019-01-08T18:52:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Miguel\_Zhefan\_Ye](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/miguel_zhefan_ye/32/444_2.png) [@Miguel\_Zhefan\_Ye](https://phaser.discourse.group/u/Miguel_Zhefan_Ye)\
**Post date:** [January 8, 2019, 6:52pm UTC](https://phaser.discourse.group/t/phaser-2-uncaught-typeerror-in-x/665/1 "2019-01-08T18:52:18Z")

</div>

![image](https://global.discourse-cdn.com/free1/uploads/phaser1/original/1X/982d43f3fbccc6f0f6e23d9c14e3f7efba264107.png)

I want my diamonds and player to collide with the platforms but I just cannot fix the error that it appears since I believe I dont touch the x in anywhere, getting pretty tilted not gonna lie.

all the sprites and images are loaded in another js and it all works fine, just to add up.

I was told to add beside platforms this line of code ==\> **this.platforms.physicsBodyType = Phaser.Physics.Arcade;** it works when it comes to fixing the error but this error pops up

![image](https://global.discourse-cdn.com/free1/uploads/phaser1/original/1X/165ca4427ed14109d94da893c3a474b900033d01.png)

Hopefully my question is clear, my first post here, 2 days till the exam!  
Here is the code:

```
'use strict';

  var player;
  var PlayScene = {
  create: function () {
    /*var logo = this.game.add.sprite(
      th﻿is.game.world.centerX, this.game.world.centerY, 'logo');
    logo.anchor.setTo(0.5, 0.5);*/
    this.game.physics.startSystem(Phaser.Physics.ARCADE);
    this.game.add.sprite(0,0,'sky'); 
    this.platforms = this.game.add.group();
    this.platforms.enableBody = true;

    this.ground = this.platforms.create(0,this.game.world.height-64,'ground');
    this.ground.scale.setTo(2,2);
    this.ground.enableBody = true;
    this.ground.body.inmovable = true;

    this.ledge = this.platforms.create(400,450,'ground');
    this.ledge.body.inmovable = true;
    this.ledge = this.platforms.create(-75,350,'ground');
    this.ledge.body.inmovable = true;
    
    player = this.game.add.sprite(32,this.game.world.height -120,'dude');
    this.game.physics.arcade.enable(player);
    player.body.gravity.y = 800;
    player.body.collideWorldBounds = true;

    player.animations.add('left',[0,1],10,true);
    player.animations.add('right',[2,3],10,true);
    
    this.diamonds = this.game.add.group();
    this.diamonds.enableBody = true;

    for(var i = 0; i <14; i++){
      this.diamond = this.diamonds.create(i* 70,0,'diamond');
      this.diamond.body.gravity.y = 1000;
      this.diamond.body.bounce.y = 0.3+ Math.random()*0.2;
      this.diamond.body.collideWorldBounds = true;
      console.log('diamantes');
    }
    this.scoreText = this.game.add.text(16,16,'',{fontSize:'32px',fill:'#000'}) 
    this.cursors = this.game.input.keyboard.createCursorKeys();

  },
  update: function(){
    self = this;
    this.game.physics.arcade.collide(self.diamonds, self.platforms);
    self.game.physics.arcade.collide(self.player, self.diamonds);﻿﻿﻿﻿
}
```

---

<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:** [January 8, 2019, 7:59pm UTC](https://phaser.discourse.group/t/phaser-2-uncaught-typeerror-in-x/665/2 "2019-01-08T19:59:14Z")

</div>

> [@Miguel\_Zhefan\_Ye](#):
>
> I was told to add beside platforms this line of code ==\> **this.platforms.physicsBodyType = Phaser.Physics.Arcade;**

No. The default value (Phaser.Physics.ARCADE) is already correct and the new value is not.

If you look at the stack trace for the error you’ll see that it comes from a `collide` call. The first line from your script is _bundle.js:98_. Click on that. It’s likely there’s a problem with one of the values you pass into `collide()`.

From the code you posted it looks like `self.player` is undefined. It should be `player`. I doubt that’s causing the error, in `collide`, though.

> this.ground.enableBody = true;

Remove this. Only groups have an `enableBody` property, not sprites.

> this.ledge.body.inmovable = true;

This is misspelled and should be `immovable`.

---

<div class="post-metadata">

**Author:** ![Miguel\_Zhefan\_Ye](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/miguel_zhefan_ye/32/444_2.png) [@Miguel\_Zhefan\_Ye](https://phaser.discourse.group/u/Miguel_Zhefan_Ye)\
**Post date:** [January 8, 2019, 9:15pm UTC](https://phaser.discourse.group/t/phaser-2-uncaught-typeerror-in-x/665/3 "2019-01-08T21:15:49Z")

</div>

Thanks for your response!  
I fixed the mispell and also removed the _enableBody_ of ground but the line:

`this.game.physics.arcade.collide(player,this.platforms);`  
doesnt seem to work still.

I tried using `this.game.physics.arcade.collide(player,this.ground);` and it workds perfectly fine  
so the problem is within the group()?

---

<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:** [January 8, 2019, 10:09pm UTC](https://phaser.discourse.group/t/phaser-2-uncaught-typeerror-in-x/665/4 "2019-01-08T22:09:50Z")

</div>

This works for me:

https://codepen.io/samme/embed/preview/xmJOWo?height=300&slug-hash=xmJOWo&default-tabs=js,result&host=https://codepen.io
