Changing sprite colours during runtime.

Blitz3D Forums/Blitz3D Beginners Area/Changing sprite colours during runtime.

Farflame(Posted 2005) [#1]
Is it possible to change a sprite's colour whilst the program is running? I actually want to change 3 seperate colours on a sprite. Speed isn't really important - what I'm trying to do is to get a 'Kit designer' screen for my Soccer game (you choose a kit pattern, then click to alter the 3 colours).

Any ideas how I'd do this? I can think of how to change a single colour, but not all three.


Rob Farley(Posted 2005) [#2]
Probably the easiest way is to have the 3 distinct colours primary colours that aren't used elsewhere on the strip, Magenta (255,0,255), Green (0,255,0) and Yellow (255,255,0) for example. Then simply make a copy of the original graphic, loop through the pixels using readpixelfast and if you find any of those 3 colours replace with the colour you want using a writepixelfast.

If however, you've got some shading in there then I would suggest doing the base image as full colour with grey scales on all the bits you need to colour. Then have 3 seperate 1 bit images for the 3 coloured areas, run through the colour area bitmaps giving the grey of the base image the required hue.


Farflame(Posted 2005) [#3]
I don't need shading, so the original method should work. I assumed that would be VERY slow, but since I don't need it to be fast, perhaps it's a workable method. I'll give it a go and see how it works out :)


Rob Farley(Posted 2005) [#4]
Depends on your definition of very slow. It's certainly not realtime fast but it'll only take a few millisecs.


Farflame(Posted 2005) [#5]
Yeah, using writepixelfast, it's easily fast enough for my needs. Thanks.

One minor problem, is there a way to specific the colour for writepixelfast without giving it in hexidecimal? Is there a way to do writepixelfast x,y,(255,0,255) or something?


Rob Farley(Posted 2005) [#6]
http://www.blitzbasic.com/codearcs/codearcs.php?code=551


(tu) ENAY(Posted 2005) [#7]
Here's a turbo fast way of doing it in realtime without using slow writepixel.

Do what Rob says and have three distinct colours like with Magenta (255,0,255), Green (0,255,0) and Yellow (255,255,0) in your image.
Then when you need to change one of those. Do this in the background:-

Make a filled rectangle the size of your sprite in the 'new colour' that you desire. Then mask your image with 'old colour' you want to change. Such as Green (0,255,0). Then draw the image over the top of the rectangle. Hey presto chicken nuggets and chips! Your colour appears through the masked out areas.