Jump to content

Cannot read property 'body' of undefined


lucasg07
 Share

Recommended Posts

Hi,

I'm really really really new to Phaser and for school we need to make a game in only 2 weeks. I'm making a game based on doodle jump. I searched a long time for some examples but I can only find Phaser 2 examples. 

This makes it really hard for me to actually understand Phaser 3. I'm learning it with very small steps but can't seem to understand why I'm getting this error:

//preload class: I tried both spritesheet and image
this.load.spritesheet(`tile`, `./assets/tile.png`,{ frameWidth: 32, frameHeight: 48 });

//this is a copied Phaser 2 example that I'm trying to convert
platformsCreateOne(x, y, width) {
    //When a tile leaves the screen - returns a sprite with false property
    const platform = this.platforms.getFirstDead({
      key: 'tile'
    });

    //I added this myself because the sprite didn't have a body, not sure if this is correct
    platform.body = true;

    console.log(platform); //returns a sprite
    console.log(platform.body); //returns true

    //told me that platform.reset is not a function, agian not sure if this is correct, not even sure why i use .physics.body guess I just tried something I saw online, again i'm really new to phaser
    platform.physics.body.reset(x, y); //returns error "Cannot read property 'body' of undefined"
    
    //also tried this   
    /*platform.physics.body.reset({
      x: x,
      y: y
    });*/

    platform.scale.x = width;
    platform.scale.y = 16;
    platform.body.immovable = true;
    return platform;
  }

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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