Sign in to follow this  
Pax

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.

Share this post


Link to post
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.

 

http://docs.phaser.io/Phaser.Sprite.html#body

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.