Per Pixel collision.

  ... the case you feel the need for a new feature or want to submit one.

Per Pixel collision.

Postby Drone » Fri Sep 03, 2010 5:25 pm

Hi,

I just would like per pixel collisions that cares of the sprite alpha. Basically, you would check if at position (x, y) of the sprite being tested for collisions, there is a pixel with alpha equal to 0.

So, you should create firstly a matrix containing each pixel info of the sprite that you are interested in checking collision, and that's like a start method of the game.

Then, a pixel with alpha equal to 0, should be wrote in the matrix as 0 (zero), and other pixels with alpha > 0 should be wrote as 1.

At the update method, when two sprites should be tested for collision, the engine checks firstly if the two sprites overlap, then scans in a for-loop the matrices of the sprites tested, and checks if in the overlap region there are pixels of each sprite that overlaps, thanks to the matrices, because at position x, y of the collision, it's true that the matrices have a 1, and not a 0.

I don't know how to implement it in the engine, but the dev should at least try something like that.
Drone
 
Posts: 10
Joined: Fri Sep 03, 2010 2:48 am

Re: Per Pixel collision.

Postby Mimminito » Sun Sep 05, 2010 6:07 pm

Well for starters Per Pixel Collision is going to be very performance intensive. So its not really an implementation that would be high up Nicolas's list. But, with the right optimizations you should be able to get it working ok.

With regards to actually implementing it, I dont know myself how to actually do this. But a quick search found a lot of results that should get you started:

Pixel Perfect Collision
Pixel Perfect Collision Java
---------------------------------------
Adam Goodchild
Your AndEngine Forum Moderator!
My Tutorials List
http://www.adam-goodchild.co.uk
---------------------------------------
Mimminito
 
Posts: 360
Joined: Wed Jul 21, 2010 3:08 pm
Location: Chelsmford, UK


Return to Features

Who is online

Users browsing this forum: No registered users and 4 guests