-
Notifications
You must be signed in to change notification settings - Fork 42
Collisions
mini2Dx provides several classes for storing collision data depending on how you want to handle collisions.
The PointQuadTree and CollisionPoint classes are useful if all your objects are moving freely and their collision area is represented by a point coordinate.
QuadTree<CollisionPoint> collisions = new PointQuadTree<>(4, 2, 0, 0, 640, 320);
// Add some points
collisions.add(new CollisionPoint(1, 1));
collisions.add(new CollisionPoint(4, 4));
// Get all points in an area
List<CollisionPoint> collisionsInArea = new ArrayList<CollisionPoint>();
collisions.getElementsWithinArea(collisionsInArea, new CollisionBox(2, 2, 6, 6));The RegionQuadTree and CollisionBox classes are useful if all your objects are moving freely and their collision area is represented by a rectangle.
RegionQuadTree<CollisionBox> collisions = new RegionQuadTree<CollisionBox>();
//Add a collision
collisions.add(new CollisionBox(4f, 4f, 2f, 2f));
//Get all collisions in an area
List<CollisionBox> collisionsInArea = new ArrayList<CollisionBox>();
collisions.getElementsWithinRegion(collisionsInArea, new Rectangle(0f, 0f, 2f, 2f));
//collisionsInArea now has a list of collisions intersecting or within the rectangle's areaIf you are using an entity-component-system pattern, a good approach for associating a CollisionShape with an entity is to pass the entity ID into the constructor of the CollisionShape (which can be returned via getId()) and then looking up the entity by id when resolving collisions.
Getting Started
Graphics
Gameplay
Data
- Asset Management
- Saving and loading player data
- Converting objects to/from JSON
- Converting objects to/from XML
User Interfaces / HUDs
Structuring your code
Releasing your game