Perfect Pixel Collision

edited March 2009 in Help request
Hello again, I'm still trying this engine. I reach the collision issue. I mixed tutorial 4 with 8 in order to check animation and collision feature working together. I realize that collision is calculated base on the object shape (only box and sphere are support right now, right?) and not base on the image shape, as you can see on the picture.


I never used Box2D so I really don't know if it's possible or not. So, my question is Perfect Pixel Collision or something similar will be possible? or do I have to do my own avatar base on boxes and spheres and the "paste" the image.


  • edited March 2009

    Yes, currently the only available collision/physics plugin is based on Box2D and does not support pixel perfect collision.

    However, in the tutorial I used a simple shape (box) to describe my object (the crate). But you can combine more boxes and circles to define one object's body so as to get something close to your visual (sprite). That being said, it was a bit too limitating, and orx currently (not in the 0.9.1 version but on the current svn one) support a third primitive: convex polygons.

    So for every object, the associated body can a compound made with boxes, circles and convex polygons. Those are defined giving a list of edges using the pivot as origin.
    You can also flag the shapes with different flags (this way you can have a different shape for your attack box and your sensitive one) and specify if it should be used for collision or just for your game logic (in this case it won't affect the physics simulation, you'll just get event to know which object/shape collided with which other ones).

    You can also replace bodies on the fly using code, or even move them depending on your character state or animation, for example.

    Also, if you don't specify coordinates for a shape (radius/center for a sphere, corners for a box), the size of the graphic object will be used. The box will always fit perfectly your rectangle, whereas the sphere will use a radius of (height+width)/2 as an approximation (basically, it will only really work perfectly if you want to represent a ball in a square sprite).

    Hope this helps! =)

    - iarwain
  • edited June 2009
    sorry for bump, but perfect pixel collision would be a realy nice feature for orx. i think it would be worth the effort to include this. is this planned for future releases ?


  • edited June 2009

    Unfortunately, there are no plan on making such a plugin currently as I lack of time to do so and have other priorities right now. :(

    However it sounds like a neat idea and if someone feel like trying to write such a plugin I can give support to explain how to proceed.
    MrGreen now also knows how to to such plugins so he might be able to help anyone wanting to give a try to it.

    For the record, I also wanted very precise pixel collisions at first but it turned out that what Box2D proposes was good enough for my needs. :)
  • edited June 2009
    i agree, perfect pixel collision ( ppc ) is much to complex to be on top of priority. Maybe a smaller step, collision on irregular shapes ( concave polys ) , eg. for level collision, would be a first start. i thought about realizing some kind of jump'n run style collision, but with boxes and circles ?

    my idea was to save a level into a 1-bit collision map ( see attached image ) where black pixels represent collision.


    map 1.1K
  • edited June 2009
    Yep a collision map could be interesting to use, that's true.

    As for the concave polys, right now you can make irregular shapes on an object with compounds made of circles, boxes and convex poly. Actually the particle-test here and the turorial #11 both use compounds made of convex shapes.

    That might help you for now. :)
Sign In or Register to comment.