Page 1 of 1

One instance touching a colour

Posted: Jul 5th, '17, 17:25
by SimpleSi
Anyone know how to test if an instance is touching a particular colour?

Tried this approach
col.PNG

Re: One instance touching a colour

Posted: Jul 9th, '17, 01:00
by JohnM
GP doesn't have the "color touching" feature of Scratch. Color touching turns out to be a very expensive operation when working with textures (reading the pixels out of the GPU can be extremely slow on some hardware). It's also prone to false positives due to the blending colors created by antialiasing. Such errors are difficult to avoid and very hard to discover when they do occur (as we discovered when we introduced anti-aliasing in Scratch 2.0).

GP does have a "touching" block. So what you can do is to create a "sensor" object of the correct shape and test whether some object is touching it. You can set the alpha of the sensor object to 0.01 so that it's effectively invisible.

Hope that helps!

Re: One instance touching a colour

Posted: Jul 9th, '17, 10:34
by SimpleSi
OK

I'll try playing with alpha settings on object image and just test for touching object - I'm just looking to detect touching the outer grey ring of the pool in my sim

Re: One instance touching a colour

Posted: Jul 9th, '17, 11:01
by JohnM
Oh, I see what you need to do. What I would do is to make the pool out of two separate objects (of two different classes) -- Pool and Rim. The Rim's costume would be an open circle, the Pool's costume would be a filled, solid colored circle of the same diameter. You can combine those into a single composite object by putting the Rim on the Pool and selecting "attach..." from the shift-right-click menu. This will present a menu of objects to which you can attach the Rim. Select Pool. Now the Pool + Rim acts like a single object. But because the Rim is actually it's own object, other objects can test whether they are touching the Rim.

The notes for the "Ferris Wheel" example project in the latest version talk a bit more about how to build composite objects in GP.

I read about your pool challenge. Good luck making a simulation of it in GP!

-- John

Re: One instance touching a colour

Posted: Jul 9th, '17, 11:56
by SimpleSi
I've done this - hadn't read your post but extra info very useful :)
poolring.png
poolring.png (11.34 KiB) Viewed 11674 times

Re: One instance touching a colour

Posted: Jul 12th, '17, 06:20
by SvenJ
Just in case you'd like to know more about it:
The concept John explained is called "sprite nesting": Essentially, it creates a hierarchical structure between two objects/sprites by making one the owner (or "anchor" in Snap), and the other one a part. It's a concept that exists in Snap as well, but Scratch does not support it.
The objects can reference each other using the reporter blocks "owner" (reports owner of block), and "parts" (reports list of parts); they can be found in the "structure" submenu when developer mode is activated.

in Snap, you can nest sprites into each other by dragging one sprite's thumbnail from the sprite palette onto the other sprite on the stage.
You can read more about Nested Sprites here, on page 9.

Re: One instance touching a colour

Posted: Jul 12th, '17, 12:24
by SimpleSi
Ta :)

I've used nested sprites in BYOB in past - never really used Snap, as always seen it as Scratch for University under-graduates - but please don't tell Jens that otherwise he'll stop talking to me :)