Here’s a simple program to create an image to flash a Sprite. Uncomment the saveImage() line to save the flash image for later use if you want. Try changing the sprite name in readImage() to try other sprites. You can also change the flash color for the effect you want. Tap the screen to show the flash.
function setup()
-- this code is used only to create the flash image
img=readImage("Tyrian Remastered:Boss B")
iw=img.width
ih=img.height
img1=image(iw,ih)
for x=1,iw do
for y=1,ih do
r,g,b,a=img:get(x,y)
if a>0 then
img1:set(x,y,255,255,255) -- change to the color of your choice
end
end
end
-- end of create flash image
-- uncomment the next line to save the flash image for later use
-- saveImage("Dropbox:flash",img1)
end
function draw()
background(0)
fill(255)
text("Tap screen to flash",WIDTH/2,HEIGHT-100)
if flash then
sprite(img1,WIDTH/2,HEIGHT/2)
flash=false
else
sprite(img,WIDTH/2,HEIGHT/2)
end
end
function touched(t)
if t.state==BEGAN then
flash=true
end
end
@dave1707 - I found a simpler way to flash, using tint, there’s no need for a second image.
if flash then
tint(5000,5000,5000) --the extra line
sprite(img1,WIDTH/2,HEIGHT/2)
flash=false
tint(255) --reset to normal
tint is multiplied by the Sprite colours, and while it is supposed to only use values up to 255, it accepts larger values, so large enough values will turn any sprite white.
EDIT - this method also makes it trivial to vary the flash colours.
@yojimbo2000 - you can cheat by making the tint values greater than 255, so if for example you make them 5120, it effectively multiplies all the colours by 20, since the tint shader will convert them all to fractions of 255.
Wow, I did not know that, you’re right. I think I assumed it clamped the colors like all the other color commands. I’m pretty sure this didn’t come up last time we discussed this on @MajorMorgan 's thread.
Still, if you’re making a hectic arcade game, you should be using rects not sprites, and I’m pretty sure setRectColor does clamp at 255 … Though maybe I need to check that now too…
But I’m not so sure about setting all the colours at a quarter of their normal value. There must be an easier way. EDIT - I guess colours don’t need to be precise when you have textures, so your approach works fine.
NB in the shader, you don’t need to clamp the final colour, OpenGL does it for you.