I made this native extension for my sidescroller game in Defold game engine.
This extinsion work only with rects and circles.
Circles and rect can be rotated
This extinsion only find fact of collision. It not found normal, overlapped areas and etc.
You can use the extension in your own project by adding this project as a Defold library dependency. Open your game.project file and in the dependencies field under project add:
https://github.com/d954mas/defold-2d-collisions-ne/archive/master.zip
The pivot point of shape is in center
Complex shape is a container for other shapes
Return width and height for rect or rad for circle.
Bit masks and groups
M.PLAYER_GROUP = bit.tobit(1)
M.ENEMY_GROUP = bit.tobit(2)
M.COLLECTABLE_GROUP = bit.tobit(4)
M.PLAYER_BULLET_GROUP = bit.tobit(8)
M.PLAYER_LAZER_GROUP = bit.tobit(16)
M.ENEMY_BULLET_GROUP = bit.tobit(32)
--player only collide with enemy, collectable, and enemy_bullets
M.PLAYER_MASK = bit.bor(M.ENEMY_GROUP, M.COLLECTABLE_GROUP, M.ENEMY_BULLET_GROUP)
Return 1 for rect, 2 for circle 3 for complex
Return x1,y1,x2,y2 (left bottom right top)
You can attach table as data for shape.
--remove from world and destroy
Only for complex shape
--return array of shapes
WORLD FUNCTIONS update all shapes(position, rotations and etc).
Return all collisions. every collision object have fields
shape_1
shape_2
type(0-no collision, 1-left, 2-right, 3-all)It depends on mask and groups
Return total shapes in world