1
\$\begingroup\$

I am working on a game where we would like the enemies to flash white when hit by a bullet. Ideally, we would like to use the same mechanism to render an Image in any colour. Our Images are all png files with transparent backgrounds and these transparent areas must exist in the coloured version of the Image.

Testing shows that Image.draw(x, y, filter) does not change the appearance of the image when given Color.white

Testing has also shown that Graphics.drawImage(Image, x, y, color) has no affect when color is set to Color.white

Is there a way to change an Image to white using existing Slick2D functionality? Failing that, is there an easy way to use LWJGL to perform the colouring that can be easily incorporated into a Slick2D project?

NB Answers that allow an Image to be rendered in an arbitrary colour will be preferred over answers that are specific to Color.white

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

I think I may have found the function you were looking for.

It appears that what you want is drawFlash: http://slick.ninjacave.com/javadoc/org/newdawn/slick/Image.html#drawFlash%28float,%20float,%20float,%20float,%20org.newdawn.slick.Color%29

This, according to the javadocs linked above "Draw this image at a specified location and size as a silohette".

(Kevin apparently cannot spell silhouette, but as Slick2D is just so stinking useful, we'll forgive him, no?)

If you are curious as to why your original attempt to rendering using a color filter did not work, I recommend googling color modulation, as that is what the color filter does, and why using Color.WHITE didn't work... all of the color components were multiplied by 1, which doesn't change them in the slightest).

All the best.

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .