Imagine I have a circle shape in .png format and a maze also in .png format. I have stored them inside two sprites. The circle can move inside the maze. I want to know if circle has touched the maze walls. What should I do?
apparently simple collision tests wont help me here (because the maze is not a simple rectangle shape). something like pixel-based collision tests seem to work there. I have searched a lot and finally concluded I should learn box2d to handle such a test. I started that and there I found a "b2TestOverLap" function which I didn't find replace for it in gideros. the only thing that I have found in gideros is b2Contact. but I didnt understand how to use it. The documentations of the gideros are not clear enough for me in this case and I didnt find any other explanation for b2contact. so help me. how can i use b2contact to know if two sprites have touched each other? Or is there a better way to find such a collision?
Comments
everything I know to check collisions uses "objects/shapes" (every wall of your maze should be a "single object" so that its boundaries are clearly defined).
You can check:
http://giderosmobile.com/forum/discussion/2286/v2-a-new-tool-tiled-as-a-level-and-box2d-world-physics-editor-for-gideros/p1
for box2d and tiled map editor (should be easy to draw a maze with tiled, but maybe using box2d just for collisions is a bit too much)
tnt collision engine - really fast plugin for gideros by gregBug
http://www.tntparticlesengine.com/?cat=15
this seems to be promising, full lua, but I never tried it
https://github.com/kikito/bump.lua
or you can check between circle shape and maze walls (not walls as one big sprite, but each wall as a single sprite) with Sprite:collidesWith() by gregBug / ar2rsawseen (I lost who wrote it )
Likes: aimoi
Thank you for your meek answer. (:
In fact I thought there would be other than "objects/shapes" ways for detecting collisions. In fact my maze is a big sprite with walls inside it. look at attachments (every black line is a wall and the ball shall not be passed through them). but according to the circular shapes of the walls, I don't know how to break my wall to little objects to use common collision tests with.
Also about using hitTestPoint(), is there a way to find all the points that a sprite has covered? So then I can loop over them and see if user has touched one of them or not.
that's tricky
I think that you may use some snippet from this discussion:
http://giderosmobile.com/forum/discussion/218/how-to-get-spritehittestpoint-to-ignore-transparent-areas-of-image/p1
if you draw a raw shape over the maze (keep it invisible, just to check on less vertices than using "real" circles), theoretically you can check if it is "overlapping" with another shape; maybe to keep the collisions to a higher definition it's better to split the maze in some smaller shapes and check only the one you have to deal with (using the distance from the center of the maze?).
I don't know if it is the best approach, just guessing
Likes: aimoi
There is another interesting lua collision library that might be of interest to you. I didn;t read much about it but it does polygons and circles and stuff so maybe it could be of help..
http://vrld.github.io/HardonCollider/
Likes: aimoi
Well, I gave a try to checking pixel by pixel collisions, but it was inefficient. In fact beside the "Processor Insensitivity" issues, I faced a lot of problems with breaking my maze into simple rectangles. At last (with a little embarrassment) I found using the "hitTestPoint()" the best approach into my case.
Likes: antix
I ask because I thought you could have your maze defined as rings (from inner to outer) and each ring could be split into segments. Then you could use a simple "point in circle" function to limit the players movement, if you get what I'm trying to say
Likes: aimoi
well, "hitTestPoint()" worked, but not so satisfying.
Next time I'll give a try to what you said. seems like it is a better approach.
(:
I have collisions registering with pixel precision but resolution is a bugger so I'm trying to kludge Hardon Collider into my code in order to resolve that issue.
Likes: aimoi