PixelOverlapping

class PixelOverlapping(threshold: Float) : Overlapping

Checks that actors bounding rectangles overlap, and then checks if any pixels overlap. i.e. any non-transparent pixels of actorA are in the same place as any non-transparent pixels of actorB.

This is quite expensive (slow) when Actors are nearly-touching. When far away, the bounds-check (which is relatively fast) returns false, so the slower pixel-detection isn't executed.

As with all collision detections, it is often possible to perform quick tests first. For example, this is often a good first heuristic :

val distance : Vector2 = actor1.position - actor2.position
if (abs(distance.x) > SOME_THRESHOLD) return false
if (abs(distance.y) > SOME_THRESHOLD) return false
// Now perform the more expensive test.

Where SOME_THRESHOLD is based on the maximum size of the actors. Scenery is often larger than moving objects, but if you put them in a different Stage, you can check them separately, without the heuristic.

On the up-side, PixelOverlapping is easy to use, no setup is required and it is pixel-perfect.

Constructors

Link copied to clipboard
constructor(threshold: Float)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open override fun overlapping(actorA: Actor, others: Iterable<Actor>): Boolean

Do any of others overlap actorA.

open override fun overlapping(actorA: Actor, actorB: Actor): Boolean

Note. overlapping( actor1, actor2 ) can be quicker/slower than overlapping( actor2, actor1 ) If actor1 is axis-aligned actor2 is rotated, place=ing actor2 first may be slower, because the bounds check will catch more cases (and therefore the pixel-tests aren't needed).