Faizy Posted April 17, 2017 Share Posted April 17, 2017 Can someone tell me why "body" is undefined? Console tells me: "Uncaught TypeError: Cannot set property 'enable' of undefined" function create() { game.stage.backgroundColor = '#3598db' this.cursor = this.input.keyboard.createCursorKeys(); this.player = this.add.image(200, 75, 'tank') this.physics.arcade.enable(this.player); this.player.body.enable = true; this.player.body.collideWorldBounds = true; for (var i = 0; i < enemiesTotal; i++) { enemies.push(new EnemyTank()); } } Can someone help me out? Link to comment Share on other sites More sharing options...
scheffgames Posted April 17, 2017 Share Posted April 17, 2017 this.physics.arcade.enable doesn't exist, you should try game.physics.arcade.enable. Also game.add.image, not this.add.image. this refers to the scope of the function create(), whereas game it's a variable that has the functions you want. Probably should also read about JS scope to avoid future pain. Link to comment Share on other sites More sharing options...
Faizy Posted April 17, 2017 Author Share Posted April 17, 2017 Thanks scheffgames. I changed it, but I still run into the exact same problem. function create() { game.stage.backgroundColor = '#3598db' this.cursor = game.input.keyboard.createCursorKeys(); this.player = game.add.image(200, 75, 'tank') game.physics.arcade.enable(this.player); this.player.body.enable = true; this.player.body.collideWorldBounds = true; for (var i = 0; i < enemiesTotal; i++) { enemies.push(new EnemyTank()); } } Edit: I fixed it. I used images instead of sprites...images dont support physics. scheffgames 1 Link to comment Share on other sites More sharing options...
Recommended Posts