How does the pixel perfect collisions work on snap? (JS)

Look at the question

This should be in #advanced-topics:advanced-help-with-snap.

done do you know the answer

this is not going to help...
explanations plz
and provide JS code


EXPLAIN How does one line of code help

I dont see any code for collisions just comments

There is code...

Process.prototype.objectTouchingObject = function (thisObj, name) {
    // helper function for reportTouchingObject()
    // also check for temparary clones, as in Scratch 2.0,
    // and for any parts (subsprites)
    var those,

    if (this.inputOption(name) === 'mouse-pointer') {
        mouse =;
        if (thisObj.bounds.containsPoint(mouse) &&
                !thisObj.isTransparentAt(mouse)) {
            return true;
    } else {
        stage = thisObj.parentThatIsA(StageMorph);
        if (stage) {
            if (this.inputOption(name) === 'edge') {
                box = thisObj.bounds;
                if (!thisObj.costume && thisObj.penBounds) {
                    box = thisObj.penBounds.translateBy(thisObj.position());
                if (!stage.bounds.containsRectangle(box)) {
                    return true;
            if (this.inputOption(name) === 'pen trails' &&
                    thisObj.isTouching(stage.penTrailsMorph())) {
                return true;
            if (isSnapObject(name)) {
                return name.isVisible && thisObj.isTouching(name);
            if (name instanceof List) { // assume all elements to be sprites
                those = name.itemsArray();
            } else {
                those = this.getObjectsNamed(name, thisObj, stage); // clones
            if (those.some(any => any.isVisible && thisObj.isTouching(any)
                    // check collision with any part, performance issue
                    // commented out for now
                    return any.allParts().some(function (part) {
                        return part.isVisible && thisObj.isTouching(part);
                )) {
                return true;
    return =>
        this.objectTouchingObject(any, name)


In other words, he should just put it in Help With Snap!.

I already did that -_-

No, you didn't.

image is different from image.

You're supposed to put this topic in image.

I did that before
@programmer_user said to change it


you should have left it be...

Know what, nevermind. It's not like it matters anyways.

The block itself calls this function, which handles the different types of inputs you can give (sprites, lists of sprites, stage edge, etc.):

For collision between sprites, or between the sprite and pen trails, it eventually enters this function:

It gets the rectangle where the two sprites' bounding boxes (the smallest rectangles that fit the entire sprite) overlap, and searches for a spot within the rectangle where the two sprites both have a pixel. If it finds such a spot, it returns true; otherwise, false.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.