Canvas Components, Controls and more!
ZIM 4.4.0 has launched with an update to its hitTests to greatly improve SPEED. Pictured above is hitTestCircle() acting on 1000 droids at 60 FPS. The trick to performance was to add a hitTestBounds() first as a FILTER for all the hitTests that rely on shape-to-point hit tests.
The hitTestCircle(), for example, checks 8 points around the circle by default and the center of the circle against a shape of the droid. And it does so for each droid so in the past, this would bog. Our advice was to turn to the MATHEMATICAL hitTestBounds() which does a lightning fast equation to see if rectangles are hitting – but then we lose accuracy. Well… after a realizing that we don’t need to test any of the points unless the bounds are hitting… we emerged with a WIN/WIN scenario: just add a hitTestBounds() before we do the hitTestCircle()! Now we have performance, and then if we are inside the bounds we do a shape test for accuracy.
This technique has been added to hitTestCircle() and hitTestRect(). hitTestReg() and hitTestPoint() now check to see if the point is in the bounds (if there are bounds) and this speeds up the point check too!
If you want to see the ZIM droids in action, watch the MID Level Tutorials on ZIM LEARN.