Salvatore Posted May 7, 2014 Share Posted May 7, 2014 Hi! I'm following the Tutorial: How to organize your Javascript code into classes using Phaser HTML5 game framework - Toastedware but, the body class appears "undefined" in other classes files. Using the Firefox Javascript console, this message pop in the Level.js:'ground.body is undefined'How fix this? Everything works fine, but this cracks the whole execution. P.S.: My Level.js file:Level = function(game){ this.game = game;}Level.prototype = { preload: function() { this.game.load.image('background', 'assets/game01/sky.png'); this.game.load.image('ground', 'assets/game01/platform.png'); }, create: function() { this.game.add.sprite(0, 0, 'background'); this.platforms = game.add.group(); var ground = this.platforms.create(0, game.world.height - 64, 'ground'); ground.scale.setTo(2, 2); ground.body.immovable = true; // The trouble line } } Link to comment Share on other sites More sharing options...
Heppell08 Posted May 7, 2014 Share Posted May 7, 2014 You need to enable the physics systems and then enable the physics on the ground itself. Link to comment Share on other sites More sharing options...
Heppell08 Posted May 7, 2014 Share Posted May 7, 2014 game.physics.startSystem(Phaser.Physics.ARCADE);//the groundgame.physics.arcade.enable(ground);ground.body.immovable = true; Salvatore 1 Link to comment Share on other sites More sharing options...
Salvatore Posted May 7, 2014 Author Share Posted May 7, 2014 Thanks!!!! Link to comment Share on other sites More sharing options...
Heppell08 Posted May 7, 2014 Share Posted May 7, 2014 Thanks!!!!No problem, just remember that a body will always return undefined unless you have the physics written in too. Link to comment Share on other sites More sharing options...
wildsky Posted June 27, 2014 Share Posted June 27, 2014 I'm confused. Did this issue get fixed in the sample download code? Everything works fine for me in FF, but these two lines don't appear anywhere in the code I downloaded: game.physics.startSystem(Phaser.Physics.ARCADE);game.physics.arcade.enable(ground); However, it does contain this line:ground.body.immovable = true; Is it not necessary to have those first two lines anymore? Link to comment Share on other sites More sharing options...
lewster32 Posted June 27, 2014 Share Posted June 27, 2014 game.physics.startSystem(Phaser.Physics.ARCADE);This line is usually not needed - Phaser starts with Arcade enabled by default. You do however need to enable physics on the sprites you wish to use, either by enabling it directly on the sprites or setting the group they're added to up accordingly:var group = game.add.group();group.enableBody = true;group.physicsBodyType = Phaser.Physics.ARCADE;// ... all sprites added to this group will now automatically have their body property enabled Link to comment Share on other sites More sharing options...
Recommended Posts