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.

AppGameKit Classic Chat / [SOLVED] Color of sprites

Author
Message
george++
AGK Tool Maker
17
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 30th Dec 2020 13:59 Edited at: 30th Dec 2020 14:30
Hi, Is there any easy way to make a group of sprites grey?
I am looking for a solution that does not require aditional resurces. I work on my personal 2d editor, and I have orginized the sprites in layers. Every time I select a layer, I would like to make the others grey.

The author of this post has marked a post as an answer.

Go to answer

n00bstar
20
Years of Service
User Offline
Joined: 9th Feb 2004
Location: Montreal, Canada.
Posted: 30th Dec 2020 21:20
I might be mistaken, but there doesn't seem to be a native way to do this. I think the simplest way would be to either download or code a pixel shader and apply it to the sprites.

If you're not completely sold to the grayscale idea however, you could easily just "dim" the unselected layers by using SetSpriteColor commands. You'd have to do it for each of the RGB channels, but it's certainly a quick and dirty option for you.
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 31st Dec 2020 11:11 Edited at: 31st Dec 2020 11:14
The simplest solution would be to change your desired outcome. You could use SetSpriteColorAlpha(xx, xx) to fade the non-selected sprites.
But, if you really need them to be grey then you need to play with the image on a per-pixel basis which means converting to and from a memblock.

Off the top of my head I would probably average each of the RGB values and set each channel to the average but I'd need to try it to be sure. It might be better to use one of the channels as the grey value instead.
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 31st Dec 2020 11:45
This post has been marked by the post author as the answer.
Here's an example I've just knocked up:

I used the attached image which is FREE on craftpix.net but it works with any image

Attachments

Login to view attachments
Kevin Cross
21
Years of Service
User Offline
Joined: 15th Nov 2003
Location: London, UK
Posted: 31st Dec 2020 12:30 Edited at: 31st Dec 2020 13:13
How about dropping a full screen layer underneath the sprite(s) when the layer is selected (set it as semi transparent black), so all other layers below it will appear darker. That has to be quicker than changing the colours or alpha settings for all sprites in all layers below the selected layer.

Just remove/delete the semi transparent when a specific layer isn't selected.

Realised after quickly testing this that it doesn't work if you select a layer in the middle. You'd have to move the selected layer depth up to the highest level before adding a semi transparent black sprite below it

Attachments

Login to view attachments
george++
AGK Tool Maker
17
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 31st Dec 2020 19:43
Thank you guys for your responses. You gave me some ideas.
@Scraggle: I am not familiar with memblocks and your code will also help me to learn about them.
I wish you all a happy new year
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 31st Dec 2020 21:57
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 1st Jan 2021 02:31 Edited at: 1st Jan 2021 22:02
The below code and shader will do that (ps modified shader so it dont change the alpha channel now transparency works)


this SetShaderConstantByName(1,"factor",0,0,0,0) command in main loop may be set to what you desire
float values between 0 and 1 only experiment a little
eg this mod time#=1 ///Timer()

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 1st Jan 2021 03:01
Nice one!
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 1st Jan 2021 04:44 Edited at: 1st Jan 2021 04:51
Thanks blink
Sometimes a memblock is better and sometimes a shader

The memblock method ide use
uses the formula Gray = 0.2126×Red + 0.7152×Green + 0.0722×Blue



the formula came from https://entropymine.com/imageworsener/grayscale/#:~:text=and%20you%20want%20to%20convert%20it%20to%20a,you%20do%20that%2C%20this%20is%20what%20you%E2%80%99ll%20get%3A

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
george++
AGK Tool Maker
17
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 1st Jan 2021 07:01 Edited at: 1st Jan 2021 07:20
I suppose a shader is faster. Thank you both!

EDIT: But how can I apply this shader to specific sprite and not to the whole screen?

EDIT: Sorry my mistake: I noriced the SetSpriteShader( 1,1 ) later...
george++
AGK Tool Maker
17
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 1st Jan 2021 07:35 Edited at: 1st Jan 2021 07:36
@fubarpk
What the

does?
I created a clone of sprite 1 and realized that the sprite 1 is not transparent. I set the alpha value between 0 and 1 but the sprite 1 remains not transparent
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 1st Jan 2021 08:05 Edited at: 1st Jan 2021 08:06
apologies should be able to remove it safely was left over from copy and pasting code which i do allot of espesh with my lack of finger movement which is on the improve btw
i think it may have been left over from a blend two sprites thing i did

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
george++
AGK Tool Maker
17
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 1st Jan 2021 08:44 Edited at: 1st Jan 2021 08:44
Quote: "..was left over from copy and pasting code.."

I understand. This is also happens to me

@Scraggle
I tested your function. It is excellent!
Whish I could make it shader for speed purposes only.
I'll use it though, since it gives me a lot of options
Arch-Ok
AGK Developer
5
Years of Service
User Offline
Joined: 11th Jul 2019
Location: Bursa/TÜRKIYE
Posted: 12th Jan 2021 20:44 Edited at: 12th Jan 2021 21:34
Memblocks are already disappointingly slow, using bytes won't make it any faster.



Edit: RGBA changed to BGRA

Login to post a reply

Server time is: 2024-11-24 05:51:25
Your offset time is: 2024-11-24 05:51:25