From HEX (string) to Color in Silverlight

In my current game (Balloon Mayhem) I needed to pick a random color from an predefined list of colors. The way I solved this were to make an string[] of the colors as hex values (ex. #FF000000 for black) and then just pick a random index into this array each time a need a new color. My problem were to convert the hex values, in string format, to a real .NET Color. I Googled it a little and found some articles about generating brushes this way. I just altered the code a little and got this one:

private Color GetColorFromHexa(string hexaColor)
        {
            return Color.FromArgb(
                    Convert.ToByte(hexaColor.Substring(1, 2), 16),
                    Convert.ToByte(hexaColor.Substring(3, 2), 16),
                    Convert.ToByte(hexaColor.Substring(5, 2), 16),
                    Convert.ToByte(hexaColor.Substring(7, 2), 16));
        }

Feel free to use it :)

– Enjoy!

Silverlight graphic and animation links

I have now answered a couple of thread on http://silverlight.net about graphics in Silverlight and sprite animation this week. Therefore I thought I might also as well, post the same links here on my blog. Actually I think I have posted all of the links on my blog before, but here they are together in the same post.

Frame-based animation using clipping
For games, the typical animation style is “frame based” animations. This can been archived in Silverlight using “clipping”. Bill Reiss over at Bluerosegames.com, have created a pretty good article about how to do this:
http://www.bluerosegames.com/silverlight-games-101/post/Frame-Based-Sprite-Animation-in-Silverlight.aspx

Principles of basic animation in Silverlight
At MIX09 Jeff Paries had a pretty good session about “Principles of basic animation in Silverlight”. He shows different ways of doing animation and some basic physics (using vectors to simulate gravity)
http://videos.visitmix.com/MIX09/T12F

Deep dive into Silverlight graphics
When doing graphic intensive stuff in Silverlight, like games, it’s good to know something about how the graphics pipeline in Silverlight works. Seema Ramchandani had a good session about this at MIX09.
http://videos.visitmix.com/MIX09/T17F

Hope this help you in the right direction

– Enjoy!

GameJolt.com – Yet another Silverlight game site

image 
The other day I read Jeff Weber’s blogpost about GameJolt.com. I decided to give the site a go and signed up. The site seems pretty good and supports much more than just Silverlight games, even though Silverlight is the most important one ;). It also have a Ad revenue plan coming up, so don’t wait on putting your games up there, it’s really easy, trust me. I just put up Bubbles and a branch of it I made, which is perfectly playable, I just never got further with it. I call that branch Bubbles Reflex. The “reflex” is actually because I had this idea of a “reflex indicator” to put in the game. I did that, and here you can try it out. As I didn’t find it to work really well, gameplay-wise, I cancelled that branch of the game.

Back to the actual site – GameJolt.com. The site works great as far as I have tryed it out. Upload of Silverlight games are great and simple. Initially I had a problem with the size of my game. I then wrote to the developer of the site via the chat in the button of every page, and after a day it were fixed.

So, if you have one or more Silverlight games already on the net, why don’t put it up on this one :)

– Enjoy!