Issue with touching color block

I wanted to add a small area of colour to use as an sprite collision detector (used technique many times in Scratch) but it didn't work

image

image

image

By playing around with the size of the black square - I found it works if its 9x9 size (or greater) but doesn't work if 8x8 (or smaller)

Interesting. Good to know.

The problem with this technique of very small "sensor" dots is antialiasing. Since antialiasing affects the edges of a shape it may affect the whole shape if that becomes smaller. Better to use nested sprites and collision detection for small sensors.

Now that you've said this - I rermember that there is an alisiasing issue - I'd just forgotton about it :frowning:

I'll have a play with that technique

Another - much more precise - technique if you want to check for color collision is to use the hue at _ reporter. you can check the color at a specific single point. That way you can find colors that escape color collision detection.

before I start on this - does touching sprite block directly check each sprite against each others pixels rather than how they end up aliased on the canvas?
[edit] looking into hue at approach first

hue at block approach works :slight_smile:

image

(I'm trying to detect a white explosion near, but not touching, the red pixels of my sprite in my real project hence the 255,255,255,255)

Touching color is rather slow imho. I prefer use nested sprites for such tasks. A small sprite behind main one. You can even use several "part-sprites" to detect head-collisions, feet-collisions etc.

Have you got a little project to demonstrate this technique I could have a look at?

Yes, take a look: https://snap.berkeley.edu/snap/snap.html#present:Username=pavelbel&ProjectName=parts%20touching
Use arrow keys to move Alonzo.

Got it now :slight_smile:

You ask the nested sprite if its touching :slight_smile:

image

that's "color[black] touching [yellow]"
you need "color[red] touching [yellow]"

Exactly. These nested sprites are small so their touching check is very fast. And they are hidden behind the main sprite.

My sensor is external to my main sprite so I've had to hide the sensor.

Luckily, hidden sprites can still detect if they touch shown sprites so it works for me as well :slight_smile:

I've hit an issue with using hidden nested sprite - it doesn't stay hidden if I try and use it as a clone and its parent is showing.

I can't think of a way of getting a reference to the nested sprite and therefore can't tell it to hide or ask it if its touching another sprite
[edit - I've discovered my parts reporter so trying that out]
[edit :slight_smile:
I can get a reference to the clones nested sprite and then tell it hide (and use reference to ask it if its touching other sprites later

image
]