Eg it might be quite coarse like 3x3 and A is in cell (1,2) and B is in cell (3,3). If the rectangles overlapped then you have to do the detailed calculation to see if the objects overlapped.Īnother approach is to divide the game area into a grid and assign each object to one cell in the grid. If those rectangles didn't overlap, then no collision took place and you can skip to the next pairing. But you can be sure they didn't collide if you consider the rectangle that encloses eg A and B. Eg if A, B, C, D are all strangely shaped objects (polygons) then checking a collision involves some complex mathematics for each pair. In principle there is no way to check if object A collided with any other objects (B, C, D etc) without looping over B, C, D and checking each one. I don't have much to add beyond the excellent suggestions above, but just take a step back to look at the theory of it. You can also just call reset() if you just want to clear the generated data. Subsequent calls to createRectangles() will remove any previously added collision rectangles from the bump world. Finally it adds the created rectangles to the bump collision world. NOTE that the function treats any non zero tile as solid. Each rectangle is created with a isWall bool variable to make it easy to differentiate them from other collision objects in bump. The function its-self It makes two passes over the layer, with the 1st pass creating vertical rectangles, and the 2nd pass creating horizontal rectangles. map is a loaded tiled map and name is the name of the layer you want to make rectangles from. The main function you will call is createRectangles(map, name). Subsequent calls to render() will attempt to dispose of any previously created resources.ĬollisionMaker - Creates collision rectangles from a tiled map and adds them to a bump collision world. It just draws tilemaps and in the code it has placeholder code for processing object and image layers as well. This class is based on the Desert example. If you are going to use a tilemap with Bump then maybe you will find this example project of use. My current experiment in Gideros uses Bump for collisions.
0 Comments
Leave a Reply. |