Phaser 2 Uncaught TypeError in x

image

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

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(
      this.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);
}

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.

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()?

This works for me: