Utility library for game programming.
Currently works only with heaps.
Requires Haxe 4 (developed with v4.1.3).
See also https://github.com/fal-works/broker-sample for a usage example.
Provides a base class for game entities, from which you can generate AoSoA classes.
See also: AoSoA generator of banker library.
2D AABB collision detection.
Abstraction of gamepad input.
Reflects any kind of physical input device (gamepad, keyboard, touch... depending on your implementation)
and provides you an integrated virtual gamepad.
Elements of scene trees.
- Basic classes for game scenes.
- Classes for managing transition between game scenes.
Classes for loading image data.
Tile
Atlas
FrameTiles
- etc.
Classes for drawing graphics.
TileDraw
BatchDraw
,BatchSprite
DrawArea
Basic classes for pseudo-asynchronous processing.
Some classes for abstracting sound features from heaps.
Menu UI.
Some abstract types for representing colors.
Quite unstable!
First create your collision space by implementing broker.collision.CollisionSpace
and providing metadata.
This adds several static fields, such as partitionLevel
of getCellIndex()
.
@:broker.leftTop(0, 0) // Left-top coordinates of the entire space
@:broker.rightBottom(800, 600) // Light-bottom coordinates of the entire space
@:broker.partitionLevel(3) // Depth of quadtrees. The greater, the deeper/finer
class YourSpace implements broker.collision.CollisionSpace {}
The entire space will be recursively devided; the leaf (deepest/finest) level will have pow(4, partitionLevel)
cells.
Then prepare your collision detector object by either:
createIntraGroup()
(detects within a single collider group) orcreateInterGroup()
(detects between two collider groups)
final yourDetector = broker.collision.CollisionDetector.createIntraGroup(
YourSpace.partitionLevel,
maxNumberOfColliders
);
A collision detector has quadtree(s) for left/right collider groups (stored at variables leftQuadtree
/rightQuadtree
).
Remarks:
- Quadtrees can also be provided externally when creating a detector.
- Left and right are the same if intra-group.
Finally,
- Each of your collidable objects should be associated with a
Collider
instance. - Colliders should be loaded to your
Quadtree
before running collision detection process.
AQuadtree
consists of multipleCell
s. Use yourCollisionSpace
class for determining the cell index to load your collider. - After loading, use your
CollisionDetector
to run detection with anyonOverlap
callback function. - You should manually reset your
Quadtree
before re-loading colliders.
An example would be:
class YourCollidableObject {
final collider: broker.collision.Collider;
public function new() { /* ... */ }
public function updatePosition() { /* ... */ }
public function loadCollider(quadtree: broker.collision.Quadtree) {
// Get bounds (leftX, topY, rightX, bottomY) here somehow
this.collider.setBounds(leftX, topY, rightX, bottomY);
final cellIndex = YourSpace.getCellIndex(leftX, topY, rightX, bottomY);
quadtree.loadAt(cellIndex, this.collider);
}
}
class YourSystem {
final objects: Array<YourCollidableObjects>;
final collisionDetector: broker.collision.CollisionDetector;
final onOverlap: (a: Collider, b: Collider) -> Void;
public function new() { /* ... */ }
public function run() {
// update position of objects
for (object in objects) object.updatePosition();
// reset & reload quadtree
final quadtree = collisionDetector.leftQuadtree;
quadtree.reset();
for (object in objects) object.loadCollider(quadtree);
// run collision detection
collisionDetector.detect(onOverlap);
}
}
library | flag | description |
---|---|---|
broker | broker_generic_disable | Disables @:generic meta. |
broker | broker_catch_disable | Disables try-catch in App class. |
- sinker v0.5.0 or compatible
- prayer v0.1.3 or compatible
- sneaker v0.11.0 or compatible
- ripper v0.4.0 or compatible
- banker v0.7.0 or compatible
See also: FAL Haxe libraries
- heaps v1.8.0 or compatible