Jump to content

Getting a sprite body


Outrider
 Share

Recommended Posts

Hello hello,

 

I'm using Phaser-tiled to render collision objects/bodies and I have a sprite I control manually that runs around a level. 

 

The goal is to have the sprite be able to remove a collision object/body. Currently I am using getTile and passing x,y coordinates but getTile doesnt return the physics body that is set in phaser-tiled.

 

Is there a way to get a sprite body via x and y coordinates? 

 

 

Link to comment
Share on other sites

Alright I was able to solve myself, but logging it here in case anyone needs/stumbled upon this. 

First I get the location of my sprite character:

 

var myPoint = new Phaser.Point(this.sprite.x +32, this.sprite.y); 

 

my tilesize is 32 so I add this to get the tile to the right of my sprite -> Then I do a hittest and store it in a variable called collisionBody.

 

this.collisionBody = this.game.physics.p2.hitTest(myPoint);

this.game.physics.p2.removeBody(this.collisionBody[0].parent);

 

Then I remove the Body by calling the parent of the collisionBody. Will need to turn off the optimization part for collisionBodies in the phaser-tiled call though... if I had a group of 3 sprites together it would remove the collision for all of them.  

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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