Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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

It appears that what you want is drawFlash: http://slick.cokeandcode.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.

share|improve this answer
    
Fantastic! I've found the Slick2D docs to be lacking, to say the least. Much appreciated. –  Jake Greene Jul 22 '12 at 1:24
    
And no, I will not forgive Kevin for his spelling :D –  Jake Greene Jul 22 '12 at 2:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.