Jump to content

Getting a sprite body


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);



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

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...