Jump to content

New physics and tilemap question?


Heppell08
 Share

Recommended Posts

The next problem i have is the sprite.body.x position coming back with this error for me:

Uncaught TypeError: Cannot read property 'position' of null

 

Is there any reason why the sprite position is throwing me out? Which physics is best to use for tilemap?

Can i use multiple physics systems at once? I was hoping to use p2 physics on the player?

Link to comment
Share on other sites

Some iteration on this then from NINJA tilemap example...

var slopeMap = { '32': 1, '77': 1, '95': 2, '36': 3, '137': 3, '140': 2 };// Whats being sloped, whats these numbers for?

Then whats going on here:

 

for (var i = 0; i < tiles.length; i++)    {        sprite1.body.circle.collideCircleVsTile(tiles[i].tile);    }

I get the premise but there is very minimal comment on this in the example. Any help?

Link to comment
Share on other sites

if you use p2 on the player everything that should collide with the player needs p2 too.. but if it makes sense somehow you could use p2 for some collisions and arcade for others that do not need to collide with each other...

you probably forgot to enable the physics body? hard to tell with so little code...

game.physics.p2.enable(player);

Link to comment
Share on other sites

I got the 2 physics systems working now. I was looking at the examples and working on the code at the same time. Heres is what i have done...

 

this.physics.startSystem(Phaser.Physics.ARCADE);this.physics.startSystem(Phaser.Physics.P2JS);
// then this.physics.p2.gravity.y = +500;        this.physics.p2.defaultRestitution = 0.8;
this.physics.enable(player);this.physics.p2.enable(player);
this.physics.arcade.collide(player, layer);

With this in my setPlayer() function

this.physics.enable(player);

Took some doing but i eventually got it. Just working out the gravity in p2 and testing the jumps and stuff out.

 

Thanks for the reply :)

 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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