Jump to content

p2 physics changing drawing point


Recommended Posts

Hello, I am new to the forum so first thank you for welcoming me. 

Okay, so here is my question. I am working with Phaser's p2 physics, and to start I wanted to just make a ground with a character falling onto the ground. However, I ran into a problem. Using the code below: 

var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });function preload() {	game.load.image('sky', 'assets/sky.png');	game.load.image('ground', 'assets/platform.png');}function create() {	game.physics.startSystem(Phaser.Physics.P2JS);	game.physics.p2.gravity.y = 100;	game.add.sprite(0, 0, 'sky');	platforms = game.add.group();	platforms.enableBody = true;	platforms.physicsBodyType = Phaser.Physics.P2;	var ground = platforms.create(0, game.world.height - 64, 'ground');	ground.scale.setTo(2, 2);	//game.physics.p2.enable(ground);	//ground.body.static = true;}function update() {}

I get this: 




Which is great! However, you can see that I have the line that enables ground for the p2 system commented out. When I uncomment this line and the one below it, I get this:




Which is super weird! However, I can fix the problem by changing my code where I create the ground to this. 

var ground = platforms.create(game.world.width/2, game.world.height - 32, 'ground');

This to me implies that enabling the variable for the p2 physics system changes the drawing point system somehow. If anyone can explain to me why this is happening, it would be greatly appreciated. 

Thank you



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

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.


  • Recently Browsing   0 members

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