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 / Make a sprite flash white

Author
Message
GH69
5
Years of Service
User Offline
Joined: 9th Nov 2018
Location:
Posted: 7th Mar 2019 09:45
Try as I might I cannot come up with a method of getting a sprite to flash white when hit, a la shoot em up style arcade games.

Well that's not exactly true I have managed to do it by having a 'hit' state sprite in the animation but only switching to it when it is hit, but that would entail lots of extra frames for animated sprites so there is a white one for each possible frame.
I've tried setting the sprite colour, but that only seems to be able to take away colour that's there not add to it.

Is there an easy way of doing this, or do I just have to go with creating 'white' versions of all enemy sprites?
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 7th Mar 2019 12:20
The easiest way to achieve this is to use a grayscale sprite
and use set color to color it as you need

the other method is to use a shader like this

you will notice in the above snippet there is two ways the shader can be used to set color one is commented out I hope that helps
fubar
GH69
5
Years of Service
User Offline
Joined: 9th Nov 2018
Location:
Posted: 7th Mar 2019 13:48
Thanks for the reply.
I guessed that shaders would crop up, but I do not have the first clue about them. I will however look at your example and try having a play. I'll look into the greyscale option too.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 7th Mar 2019 14:03
you could also use a sprite sheet and set the frame to the color one you want and use the timer() to flash between the set frames

Note if you go down using my shader method if you want to color tint the image red you would increase the color of the red channel
and subtract the color of the green and blue channels by an amount you specify with the MyColor shader call

Goodluck
fubar
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 7th Mar 2019 15:58 Edited at: 7th Mar 2019 16:19
You could just flash the sprite white by changing the sprites image to a copy of the original one with Alpha channel copied to the colour channels.

This copy of the original image is effectively what you said...a pure white version of your sprite frames but with the alpha left intact. Its only 4 lines of code to create the white copy....

If you want to test the code below you will need a image with alpha channel info in it (partly transparent) called "2.png"



A shader is a really good option.

Even without a shader you could slowly modulate how much white is added by using additive blending and a second sprite with its colour modulated so you would get a controlled smooth amount of white added.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 7th Mar 2019 22:50
Very clever Mr Gizmo. Very clever indeed
GH69
5
Years of Service
User Offline
Joined: 9th Nov 2018
Location:
Posted: 8th Mar 2019 08:41
I wish I was at a level where I could realise that Bengismo's solution was very clever … they all are clever IMO.

Had a play with the shader option and whilst I don't really understand how it works, I think I can use it. Seems to be a lot less work than creating and colourising greyscale sprites.
If I can't get that to work I'll try the 'very clever' option

Cheers all
Graham

Login to post a reply

Server time is: 2024-03-29 11:58:25
Your offset time is: 2024-03-29 11:58:25