Rgb() doesn't work

Link to the project or level: https://studio.code.org/projects/gamelab/54j7mD6Gdq_17Fcia6ouIweuialttb3xUjK4pwcp-4c/edit (line 103)
What I expect to happen: I expect the sprite speedScrollElement to get tinted to the rgb I’ve set
What actually happens: speedScrollElement doesn’t change its color to what I’ve set, and won’t even if I place normal numbers in the rgb()
What I’ve tried: I’ve tried replacing the value I’ve set to blue in rgb to a normal number.

Hi @IMPixel,

This is a really cool project! Is this something one of your middle schoolers designed?

As far as the question you asked is concerned, I’ve noticed in line 77 you set up a sprite named “speedScrollElement” and then in line 103, you try to subtract speedScrollElement from the blue value within the RGB. I think that may be confusing Game Lab; perhaps if you try renaming it, it will work better.

If you read the documentation for sprite.tint, you’ll see that it puts an overlay on the image, rather than changing the entire color. It’s possible that this overlay is hard to see, especially if the variable you’re subtracting from 300 is less than 45 (as rgb will round anything over 255 down to 255).

I must confess, this project is beyond my skill set as a CS Discoveries facilitator & educator. Perhaps someone else here will be able to assist further?

–Michael K.

@IMPixel that is a great game! There is one error on line 103…

      speedScrollElement.tint = rgb(0, 0, 300 - speedScrollElement);

You are trying to subtract the sprite itself (speedScrollElement) from 300 rather than the .x value (or another property), but even when I correct that, you are correct, the rgb doesn’t work with the tint.

I have seen others try that in the past and not get it to work. I alerted the folks @code.org to the potential bug and you can log it yourself by emailing support@code.org, but it appears tint isn’t currently working with rgb colors for some reason.

Too bad, because I like what you were trying to do with it!


Thanks for responding, your response helped me figure out how to do this! Thanks! If you’re interested in how to I did that, well I searched up on Google how to turn rgb to hex, and i found a function allowing you to do that (you have to code the function it’s not created by default) and now I did it! thanks!

And now I learned something as well. I’m filing away the rgbtohex function for later use!

Looks great!


1 Like