Robot Foot Games Helping you improve your games as we improve our own. :)

30May/110

Blending through multiple colors

This is an update to a post I made beforehand but it has been made much easier to modify/customize now so it's coming at you with a new post!

Someone in the XNA forums brought up that they wanted to change through the colors of the rainbow, and have them blend together as they go through. He brought up how Mario does it when you touch a star, it cycles through a bunch of colors, and I noticed this while I was playing through Retrofit - Overload. The enemies are all colored, and as they get closer to dying they lose their colors and turn to white. I thought this was a neat effect because you don't need a health bar to show all of the enemy's health, you can use a visual representation and it works just as good, if not better, and doesn't clutter up your GUI!

Here's a video showing off the color changer in action (exciting, I know):

 

The entire class is just below. Read through it quick (its not very long) so you're not lost when I explain it underneath. :)

 

OK, so now lets get on to implementation! After you get the class added to your project you'll want to add a ColorChanger variable to the top of your class:

and you'll want to initialize it in your LoadContent(...) method:

and make sure to update it in our Update(...) method:

 

That does it for setting it up. Here we're just setting it to active right away so it'll continue to update and change colors. There's a good chance you'd only want this to be active after you pick up a powerup or something so you can initialize it as inactive and then call "colorChanger.IsActive = true;" when you want to activate it.

Awesome, it's setup, but how do I use it? You can grab the current color of the color changer by calling "colorChanger.CurrentColor". If the color changer is inactive it'll simple return Color.White and it won't go through updating itself until it's set to active. Here's an example of a SpriteBatch call you might use:

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

No trackbacks yet.