Touching Once
self.isTouchingOnce(otherId) is like isTouching(), but it only fires once per contact — true for exactly the one frame two shapes start overlapping, then false again next frame even while they're still touching, until they separate and touch again.
Use this for anything that should happen once per hit, not sixty times a second — a coin disappearing, a point being scored, a level going up:
export function update(self) {
if (self.isTouchingOnce("coin")) {
self.score += 1;
}
}
Compare that to plain isTouching(), which would add a point on every frame the two shapes stayed overlapped — thousands of points in a couple of seconds, not what you want for a one-time pickup.
The rule of thumb:
isTouching()— for something that should keep happening the whole time contact lasts (losing health while standing in fire).isTouchingOnce()— for something that should happen exactly once per hit (score, level up, picking something up).
Under the hood,
isTouchingOnce() remembers whether you were already touching last frame, so it can tell the difference between "still touching" and "just started touching." You don't need to track that yourself.