This project is read-only.

spriteBatch.Draw Colors

Jun 15, 2009 at 10:06 PM

Hi guys, firstly let me thankyou for all the hard work & effort gone into the making SilverSprite libraries.

I have written a remake of an old ZX spectrum game called JetPac using XNA & successfully ported it using SilverSprite, http://homepage.ntlworld.com/ian.wigley2/silverlight_jetpac_remake.html

My problem is that when drawing the flame effect in XNA i have created a simple array of Colors and cycled through them to create the flame effect using a standard call to Sprite Batch as follows :

spriteBatch.Draw(Texture, new Vector2(particleX, particleY), colors[count]);

But after the conversion, the flame effect remains white, even if i change the color to color.Green etc the color remains white. I have stepped through the code to check to see if anything silly is happening , but I haven't managed to find anything wrong.

The sprite font text color changes correctly on the intro screen using the same method.

Any help would be appreciated, thanks Ian.

Jun 16, 2009 at 1:10 PM

Currently because of limitations in Silverlight 2, you can only draw with a different color if you bring your textures in as XNB files. This is because for XNB files I have implemented code to read into a byte array that can then be modified. For PNG and JPG files I don't get access to the actual pixels and therefore can't tint them.

You need to be careful, however, since each drawing with a different color creates a new silverlight Image, and these currently don't get cleaned up. I am currently thinking of ways to clean up these old images, but it may just have to wait for Silverlight 3 where I can use pixel shaders to tint the images.

As for text, if you're using a spritefont file, that's using Silverlight's text rendering, which supports drawing with other colors, or it's using the XNB texture support above, which also supports tinting.

Hope thic clears things up.

Bill

Jun 16, 2009 at 10:16 PM

Bill thanks for your help, I exchanged the .png with the .xnb & have colour again, although I haven't checked to see how many images i am creating. I'll do some testing.

Thanks again, Ian.

Jun 17, 2009 at 1:49 PM
Edited Jun 17, 2009 at 1:49 PM

Ok great well Silverlight 3 will be here soon and then you won't have to use XNB files to draw in color and I won't have to create all of those extra images and hopefully I'll be able to do render targets and some other things that are currently missing.