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.

This code colors the enemy red:

enemies.get(i).image.setColor(0,1,0,0,1);
enemies.get(i).image.setColor(1,1,0,0,1);
enemies.get(i).image.setColor(2,1,0,0,1);
enemies.get(i).image.setColor(3,1,0,0,1);

if I set it to:
enemies.get(i).image.setColor(0,0,0,0,1);
it turns it pure black, and if I set it to
enemies.get(i).image.setColor(0,0,0,0,0);
it turns the enemy invisiable

How do I un-color enemy red? as in return to state as it was before it was colored.

Documentation link.

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

Don't fiddle with the alpha at all if you're not wanting to change it. Use the non-alpha version.

enemies.get(i).setCurrentColor(1,0,0);

Then create this method:

setCurrentColor(int r, int g, int b) {
    image.setColor(0,r,g,b);
    image.setColor(1,r,g,b);
    image.setColor(2,r,g,b);
    image.setColor(3,r,g,b);
}

Then when you want to return to no color, just texture, set the enemy to white:

enemies.get(i).setCurrentColor(1,1,1);

Turns out there's a setImageColor function that Eric mentioned in his answer. I checked the source:

public void setImageColor(float r, float g, float b) {
    setColor(TOP_LEFT, r, g, b);
    setColor(TOP_RIGHT, r, g, b);
    setColor(BOTTOM_LEFT, r, g, b);
    setColor(BOTTOM_RIGHT, r, g, b);
}

So, setImageColor is not any different than calling setColor on all four corners. Just in case you were wondering.

share|improve this answer
add comment

You need to track the last color set before changing it red, and use that when you want to restore the color.

share|improve this answer
    
but there is no other colors, its just enemy.png image , when he gets hit, it changes red. –  Matthew Apr 3 '13 at 16:27
add comment

An Image's default color is 1,1,1,1 (rgba) a.k.a. opaque (or non-transparent) white. Use Image.setImageColor to reset it:

enemies.get(i).image.setImageColor(1,1,1,1);

Be sure to use this method instead of applying Image.setColor to each of the image's four corners.

share|improve this answer
    
it says setImageColor doesnt exist –  Matthew Apr 5 '13 at 17:57
    
@Matthew Right, I corrected the code for your copy-pasting convenience. –  Eric Apr 5 '13 at 18:02
add comment

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.