Help (detect color channel value)

function circle1:touch()

  If circle.fillColor == “(1, 0, 0)” then 

   score = score + 1;

   playerScore.text = "Score: " … score

  end

end

 circle1:addEventListener(“touch”,circle1)

I want just only give score if circle1 color is red? Please help?   

Hi @tokosbex,

The correct approach would be to check the “r” (red) channel value of the circle’s fill:

[lua]

if circle.fill.r == 1 then

[/lua]

Of course, you can check the other channels as well, and you might need to if the circle might possibly have a red channel value of 1 and a blue or green channel higher than 0 (so obviously the circle would not be red in that case, but instead purple or orange or something else).

[lua]

if ( circle.fill.r == 1 and circle.fill.g == 0 and circle.fill.b == 0 ) then

[/lua]

Best regards,

Brent

Hi @tokosbex,

The correct approach would be to check the “r” (red) channel value of the circle’s fill:

[lua]

if circle.fill.r == 1 then

[/lua]

Of course, you can check the other channels as well, and you might need to if the circle might possibly have a red channel value of 1 and a blue or green channel higher than 0 (so obviously the circle would not be red in that case, but instead purple or orange or something else).

[lua]

if ( circle.fill.r == 1 and circle.fill.g == 0 and circle.fill.b == 0 ) then

[/lua]

Best regards,

Brent