I too was originally surprised when I saw that the collision system is very basic, but a test involving a few hundred entities shooting bullets at each other showed me that the rendering system is much slower than the collision system, and for normal games rendering will always be the bottleneck, especially if you use the type
parameter correctly (of course, should FP move to Stage3d this will be different).
Anyway, the way I see the multiple collision mask situation is this : you have “passive” masks and “active” masks. A passive mask is how other entities see you - your hitbox, or whatever. Active masks are masks you use to collide with other things, that the rest of the world doesn’t really need to know about.
Multiple passive masks are the real problem - say for example you want localised damage so your head is more vulnerable than your body. You could either create a sub-entity for the head and forward collision messages on to the main entity, or have a single passive mask and separate the cases out yourself - both require additional code (less for the latter, but unlike the former wouldn’t allow a different entity to selectively target the head - useful if you’re handling a big boss character where the head is very far from the rest of the body).
Multiple active masks, on the other hand, are easy-peasy. Since the outside world doesn’t need to know about them, just hold an internal reference and swap your mask
property around before calling the collide function, then swap back to your passive mask at the end of the update function:
public class SnifferThing extends Entity {
private var passiveMask: Mask; // The area we can get hit in
private var sniffMask: Mask; // The area we can smell stuff in
private var personalSpaceMask: Mask; // How far away we want to stay from things
override public function update():void {
var e:Entity;
if (feelsLikeSniffing()) {
mask = sniffMask;
if (e = collide("smelly", x, y)) {
// We can smell something
}
}
// Handle movement
mask = personalSpaceMask;
moveBy(dx, dy, "solid", true);
// Set mask back so other entities can collide with us
mask = passiveMask;
}
}
Note that if you just wanted OOBB hitboxes you could store your masks as Rect
s and use setHitboxTo
, it would work the same way.