Please look at the following image:
I want to create grid positioned objects (the blue squares) only where they would overlap another object (the red circle).
How can I do this ?
You could try covering the circle's entire bounding box with a solid grid of squares, (using a pair of nested X Y loops). Once you're done, destroy any squares that are not overlapping the circle. You should be left with only the overlapping squares.
Thanks, but I want the blue squares to be grid positioned based on layer, not the object itself, the red circle would only detect the collision with these blue squares.
I tried to use a TileMap, but I can't figure how to check each tile if is colliding with the red circle ... Any idea how can I do this ?
Develop games in your browser. Powerful, performant & highly capable.
not the cleanest way, but, you could have a collision checker sprite, make it move through every cell in one tick (via loops), if it overlaps, create the tile at this position, else do not create it, might be able to pull off an exemple if you need it.
tgeorgemihai here is an exemple, the magic appears with the "place tiles" function. I execute it every 3 ticks just so you can drag n drop the circles to see it at runtime.
Thank you very much. Exactly what I needed
Aphrodite , excellent example! Thank you!
Hey again TGeorgeMihai.
I'd actually assumed you wanted it to be a layer relative grid, though I didn't realize you were also interested in using a TileMap.
What I was originally thinking was that you could paper over the object's bounding box with grid tile objects (aligned to the layer), and then, with a single condition, remove the ones that don't overlap.
With a tile map, you'll need to use an overlap-check object like Aphrodite suggested. Though you can still use the bounding box method I described, to search only the area over the circle's bounding box, instead of the entire tile map.
Although instead of looping over the bounding box to remove non-overlapping tiles, you would simply add overlapping tiles. That's because there's no way to remove all non-overlapping tiles with a single condition, when using a TileMap object. (Which is not a bad thing at all, TileMap is actually more efficient for what you want, it just doesn't natively support collision checking, as far as I know.)
So, I also built an example capx, though Aphrodite beat me to it. :3
fisholith , what's wrong with all you geniuses in this forum? Are you trying to make us (I speak for my self) feel even more stupid? Throwing around so casually amazing capxs and having no regrets on how complicated those things are for the average Joe. Have you got no mercy??? Daaaamnnnn youououou jeniuseeeeesss! ! ! ! ! ! - a lot of echo- ! ! ! ! !
Awesome I've done something like this (check only the square region of the object instead of the full layer) after I got the example from Aphrodite , but yours better and more organized.
Thank you all for your help