Jump to content

I have a issue with the Tutorial


Recommended Posts

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

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.



Link to comment
Share on other sites

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 by captbrogers
Link to comment
Share on other sites


  • Recently Browsing   0 members

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