# Change sprite color

## Recommended Posts

Hello! Just started to learn phaser and have a question:

I have a gray sprite, how can I make it draw blue and after some event make it red?

I tried to find it but haven't any progress.

If there're no solutions, all task:

I want to make blue circles with physics body and if circle is colise with another - change color of both to red.

Thanks.

##### Share on other sites

var sprite = game.add.sprite(0, 0, 'yourGraphic');

sprite.tint = 0xff00ff;

Thanks.

##### Share on other sites

There is another question: How can I convert RGB to hex, e.g. (255, 0, 255) to 0xff00ff.

Is it R * 164 + G * 162 + B?

##### Share on other sites

There is another question: How can I convert RGB to hex, e.g. (255, 0, 255) to 0xff00ff.

Is it R * 164 + G * 162 + B?

This stackoverflow answer helped me for that:

http://stackoverflow.com/a/5624139/669561

##### Share on other sites

`function RGBtoHEX(r, g,  {	return r << 16 | g << 8 | b;}`

All values need to be in the range 0 to 255, (0x00 to 0xff)

Thanks again.