Pixel-perfect collision for images with alpha

muruba

New member
CX Code Contributor
3rd Party Module Dev
Tutorial Author
Patreon Silver
Joined
Jul 5, 2017
Messages
230
Hi all,

I am wondering is there some standard way to do pixel perfect collision checks for my PNG images with alpha channel?

Thank you

Cheers
 

MikeHart

Administrator
Joined
Jun 19, 2017
Messages
3,165
Well with CX there is no standard implemented. When I think of PPCC, I think of checking against collision maps stored inside an array and compared with each other. Basically a bit by bit check. The difficult part is if this collision map needs to rotate and scale. Overall very taxing regarding computation. I would rather define several collision polygons/boxes/circles and check against these.
 

muruba

New member
CX Code Contributor
3rd Party Module Dev
Tutorial Author
Patreon Silver
Joined
Jul 5, 2017
Messages
230
Sounds good, thanks Mike!
 

dawlane

Well-known member
CX Code Contributor
Joined
Jun 21, 2017
Messages
852
There are a number of tools that allow you to define a collision hull for the use with Box2D. R.U.B.E, Phyisics Editor and Box2D Editor are the main three.

Muddy Shoes ported it over for MonkeyX back in 2011. It may need some work to bring it up to date.
You can find the project code here.
 
Last edited:

Gerry Quinn

Active member
Tutorial Author
Joined
Jun 24, 2017
Messages
152
You could just make a separate pixelated image to use for collision checking. But I agree with Mike Hart. Pixel comparisons are a bit '80s. A hitbox - or for a really collision-centric game, a region made from several shapes - may not be quite so accurate, but how important is that accuracy?
 
Top Bottom