Hello forums,
I am currently trying to create a tile game with Box2D.
There is a two dimensional array, that holds the information for the map (as integers representing the tile's type), which is then interpreted and corresponding actors are created, each containing a b2Body.
Now I sometimes got the problem to get stuck with the player over crossing tiles (he is controlled using ApplyForce on the x-axis while there is gravity downwards). This appears to happen only, if the speed is too low, so I think that it has to do with the tiny gaps between the tiles.
What's a good way to fix that getting stuck?
OK, I finally managed to get it to work somehow. This script takes a two dimensional Array and finds the groups within, drawing an outline of each tile.
I can't think of a way to find the outline for the groups yet though. Again I would be happy about any input (sorry if I'm too hasty).
Will post again if I found a further solution.
[old script removed]
I've updated the code and it is now able to find corners for the groups though it seems to be a bit buggy. Still it doesn't give you corners in the correct order.
If anyone has an idea, how to get the corners into the correct order please help.
Thanks
I've uploaded a zip containing all the needed files to compile yourself.
EDIT: Removed the source from my post, since it was too long.
From what it looks like to me, your trying to read the array the same way your placing the tiles on the screen.
I haven't looked at your code so I'm not positive. If you are, try reading from left to right or top to bottom.
Also, make sure how your storing the points can be read back in a CCW motion.
Don't forget to take in account for the maximum amount of points allowed per shape.
I think I found a way to get the algorithm to work. The picture below describes it best I think.
It should check the directions in the order given by the numbers following the colors from blue to green to orange. (Of course this only shows the first recursions.)
I'll tell you again when I wrote the solution.
Seems like I found a partly solution.
My current algorithm for sorting corners finds the outline, but it still has a major flaw. Sometimes it has problems finding corners, because it only checks one direction for a point without a limited distance and then the other (see problem_sorted.jpg attached).
I don't know how to make it search for the missing corners.
There's a bug in the corner algorithm too, so not really every corner is found (see problem_unsorted.jpg attached).
I marked the missing corners red on both pictures.
The source is attached, so you can try around and maybe help.
Would be nice if someone could contribute an idea on one of the problems described. 🙂
i don't get why people insist on using a complex physics engine for a game that needs very simple physics.
I have been looking for a game thats a great example of this(can't find it), one of those games where you click the box to remove it and all adjacent like-color boxes, more blocks fall, wash rinse repeat. the problems was that the boxes would get caught on each other and not fall correctly. and frankly, tile-based collision is super easy and efficient.
I'm sorry, I love box2d, it's bringing my paycheck, but i hate games that are overly complex, finicky, and buggy
Edit: I think i should say something productive.
for the outline what if you had TWO 2d arrays of booleans. one array for each horizontal edge formed between 2 tiles and one array for each vertical edge. For each tile you want outlined toggle the index corresponding to each of its edges. with this method adjacent tiles will cancel each other out sense you are toggling them twice. loop through the arrays and draw them if they are true.
for instance:
lets say our game has 1 row and 4 columns. Our verticle array is initialized to
00000
if you have a tile at (0,1)
01100
then (0,2)
01010
the edge between the 2 blocks was toggled twice so its false, when you loop through it isn't drawn
ill right a code because I'm bored/interested in doing this anyways