This is a question more for the developers than the Scratch community at large. Using the sensor "touch" to find out if 2 sprites are touching, I noticed that the collision detection is pixel perfect!
I've always had a hard time getting pixel perfect collision detection on sprites that can be arbitrarily rotated/scaled.
Does Scratch use masks to accomplish this?
Offline
Hi, D-Nos.
It's sort of like using a mask. The rotation/scaling algorithm decides if a given output pixel is transparent or not. Scratch only supports binary transparency, so a pixel is either fully opaque or fully transparent. The intersection algorithm uses the scaled, rotated, and possibly image-filtered versions of the costumes for two sprites being tested. It goes over the overlapping region looking for a location where the pixels are opaque in both costumes. If it finds one, the sprites touch. If not, they don't. (Of course, if there is no overlapping region--that is, if the bounding boxes of the two sprites do not overlap--then they can't be touching and there's no need to test further.)
-- John
Last edited by johnm (2007-09-06 22:38:37)
Offline