• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Partially coloring sprites

G

GlitchCrew

Guest
I have a sea level in my game and I want my player's sprite to partially appear blue (only those parts that are actually underwater). How can I achieve this?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
You have two options... use a shader or use a duplicate sprite. With a shader you will have complete control over what is coloured, where and how, but it can be complicated to set up if you are new to game making. However the sprite approach is really easy to set up! Just make a copy of the sprite in the IDE and erase the parts that are going to be above the water, then colour the parts that you want to appear "below" the water blue (or tint them or whatever). Now in the actual instance you need to set a variable for when in water and set it to true or false depending (there are multiple ways this can be done) and then finally draw this "water" sprite in the draw event...

Code:
// CREATE EVENT
in_water = false;

// STEP EVENT
if place_meeting(x, y, obj_Water)
{
in_water = true;
}
else in_water = false;

// DRAW EVENT
draw_self();
if in_water
{
draw_sprite(spr_InWater, image_index, x, y);
}
That's the easiest way to do it that I know. :)
 
G

GlitchCrew

Guest
Thanks everyone, I solved it by drawing the sprite twice, the second time it has low image_alpha value.
 
Top