Scratch for Java

Sprite::isTouchingColor()

Checks whether the sprite is touching a colour: whether anything it paints lies over that colour on the stage - on the backdrop, on what the pen drew, or on another sprite.

As in Scratch, colours that are nearly the same count, so anti-aliased edges still match. Only what is under the painted part of the costume counts, not the empty space around it, and not the hitbox.

if (this.isTouchingColor(HtmlColor.RED)) {
   this.say("Ouch!");
 }

The time it takes grows with the size of the sprite, not of the stage.

Examples

View on GitHub

Syntax

Java

.isTouchingColor(color)
.isTouchingColor(r, g, b)

Scratch

<touching color [#ff0000]?>

Parameters

Name Data Type Description
color Color the colour to look for
r double the red part [0...255]
g double the green part [0...255]
b double the blue part [0...255]

Return

boolean

isTouchingColor()

Create Shareable URL

Select Sections