Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / 'SetSpriteColor' not working for me...

Author
Message
Men_of_Fun
8
Years of Service
User Offline
Joined: 13th Dec 2015
Location:
Posted: 24th Nov 2017 20:46 Edited at: 24th Nov 2017 20:49
This example is very baffling to me:

It's just a very simple command, and I don't know why it's not working....
I load a red sprite image called 'red_ball,png'
I make a sprite out of it (a red sprite)
then later on I want to change the color to yellow, and it simply does not work..

Here is the code I use:

LoadImage(100,"red_ball.png")
CreateSprite(100,100)
SetSpritePosition(100,50,50)
setspritecolor(100,255,255,0,255) // on this line I try to make it turn yellow, but it doesn't

I can make it turn transparent using setspritecolor(100,255,255,0,0), but that's all I've been able to do.
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 24th Nov 2017 21:40 Edited at: 24th Nov 2017 21:42
Hi Men_of_Fun,
Try it with a completely white ball.
Maybe it doesn't turn Yellow because you can't multiply the Red which is Red(255),Green(0) and Blue(0) with Yellow which is Red(255), Green(255) and Blue(0) ...Red would be completely Red already and Green times zero is still zero.

So:
255,255,0 * 255,0,0 = 255,0,0
Red * Yellow = Red
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 26th Nov 2017 08:49
To add to what Janbo has already said, you can use greyscale images with setSpriteColor.
White is affected 100%.
Black is affected 0%
Everything in between is affected proportionally
In your example, you could then set your white ball (With greyscale shading if required) to red, yellow, or any other colour.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Dybing
12
Years of Service
User Offline
Joined: 12th Sep 2011
Location: Bergen, Norway
Posted: 26th Nov 2017 11:16 Edited at: 26th Nov 2017 11:18
Think of it this way - each color channel provides a range from 0 to a max value that setspritecolor() can work within.

So a sprite that is your basic red blob, will have a max values of 255, 0 , 0. So full range on red, no range on green or blue. So to have a sprite setspritecolor() can change to any arbitrary color, it need be full white - 255, 255, 255 - and if you want details in that sprite, you use shades of grey to paint them in. If you want to keep any color detail, you need to layer two (or more) sprites on top of each other, and just use setspritecolor() on one of the layers.
puzzler2018
User Banned
Posted: 26th Nov 2017 11:25
Or if it is just a red blob an nothing else, then can use the DrawEllipse command to create a white blob , create a sprite using getimage/render/update ccommands to create a sprite
and then color that

Doing this, will create a white blob with all the red/green/blue/alpha to be able to use

puzzler2018
User Banned
Posted: 26th Nov 2017 11:31


D

Login to post a reply

Server time is: 2024-04-20 05:23:42
Your offset time is: 2024-04-20 05:23:42