Pax Posted March 19, 2014 Share Posted March 19, 2014 Hi everyone, i followed the tutorial on http://www.photonstorm.com/phaser/tutorial-making-your-first-phaser-game, till World Building. There i got the issue that ground.body.immovable = true; can not be set, since ground.body is null. I am using version 2.0 of phaser, maybe that is part of the problem. I hope someone can help me out, thanks in advance. Link to comment Share on other sites More sharing options...
Mike Posted March 19, 2014 Share Posted March 19, 2014 It's a bit old. With 2.0 physic must be enabled. By default Sprites won't add themselves to any physics system and their physics body will be null. To enable them for physics you need to call game.physics.enable(sprite, system) wheresprite is this object and system is the Physics system you want to use to manage this body. Once enabled you can access all physics related properties via Sprite.body.Important: Enabling a Sprite for P2 or Ninja physics will automatically set Sprite.anchor to 0.5 so the physics body is centered on the Sprite. If you need a different result then adjust or re-create the Body shape offsets manually, and/or reset the anchor after enabling physics. http://docs.phaser.io/Phaser.Sprite.html#body Link to comment Share on other sites More sharing options...
Pax Posted March 19, 2014 Author Share Posted March 19, 2014 Ahhh, i see! That solved my issue perfectly.Thank you for your quick answer. Link to comment Share on other sites More sharing options...
captbrogers Posted March 24, 2014 Share Posted March 24, 2014 (edited) I seem to be having a similar issue. In my code I have:var myGuy = game.add.sprite(32, 32, 'myGuy');game.physics.enable(myGuy, 'arcade'); myGuy.body.bounce.y = 0.2;And I still get that an error that body is null, and I can confirm that in Chrome dev tools. Edited to add: I was not being explicit in my creation of 'myGuy', I needed to add width and height along with the number of frames. So now I have:var myGuy = game.load.spritesheet('myGuy', 'assets/sprites/guy.png', 32, 32, 9);In my preload and it works. Edited March 24, 2014 by captbrogers Link to comment Share on other sites More sharing options...
Recommended Posts