Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Phaser 2 Uncaught TypeError


MiguelZh
 Share

Recommended Posts

image.png.71c4500e6b542ba2ace0480ceebbef6f.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.png.c0428350919d46a8ecf4d2a50de5e06c.png

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

'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);

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...