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.

Is there a form to change the color of a sprite in runtime?}

I have a black point loaded with an image, but i dont want to load various images with different colors, is there a mode to change the color in runtime and not loading lot of images?

And i want to tell it what part to color of the sprite, is it possible?

share|improve this question
add comment

3 Answers 3

up vote 5 down vote accepted

I had to do something like this in XNA with pixel-art sprites. The best way i've found was using pixel shader.

The sprites are done in gray-scale (8 bits colors without alpha), then you'll have to map each gray-color to the correspondent 32 bit color you want, using a 256 lenght array of Colors.

In the shader you can use the gray colors of the sprite as a look-up table to the array of 32 bit colors.

share|improve this answer
    
Yes, With the gray color i can tint my images :) and with the set color of the sprite i change the color. Thanks for that –  Rudy_TM Mar 8 '12 at 17:46
add comment

If you refer to libgdx then the class com.badlogic.gdx.graphics.g2d.Sprite provides two different methods called setColor: http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/Sprite.html#setColor(com.badlogic.gdx.graphics.Color)

share|improve this answer
    
Ok I missed the point. You just need to parse all the pixels of your sprite and simply change by another color when a pixel matches the color you want to replace. Be careful it can turns out to be very time-consuming in real-time that's why usually sprites can be pre-rendered in several variations of colors in the resources. –  user14170 Mar 7 '12 at 13:37
add comment

libgdx:

Color c = new Color(batch.getColor()); batch.setColor(a,b,c,d); batch.draw(yourSprite, x, y); batch.setColor(c);

share|improve this answer
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.