Changing colour of sprite "in game"

Blitz3D Forums/Blitz3D Beginners Area/Changing colour of sprite "in game"

gnipper(Posted 2003) [#1]
I have designed a sprite which I wish to use more than once on the same screen (which isnt a problem) HOWEVER i want to change part of the sprite to a different colour (to identify between the numerous ones on screen).

There must be an easier way than drawing 10 different coloured sprites when they are essentially the same! Is there a command which lets you change a certain colour to another? i.e. the sprites shirt colour


Miracle(Posted 2003) [#2]
There's no palette-swap command. However, you could generate different sprites at runtime with a combination of ReadPixel/WritePixel if your sprite's shirt color is unique.


gnipper(Posted 2003) [#3]
the read/write pixel command, do I have to specify each pixel to change colour? could take an age and it would be quicker to do different colour sprites in paint!

I have one animstrip (10 frame) of which part is "colour a" and its this "colour a" i want to be able to change without drawing 10 or 20 sets of sprites!


QuietBloke(Posted 2003) [#4]
I dont think miracle meant to change the colours on the fly within the main game loop.

You can just load the 1 anim then create all the other images as copies of the original with the colour changed.

OK.. so you will still end up with 10 images in memory but at least you only have 1 animstrip to draw.


Miracle(Posted 2003) [#5]
You just need to do something like this (pseudocode):

For n = 1 to 10 ; 10 frames
SetBuffer ImageBuffer(image,n)
LockBuffer
For x = 1 to imagewidth
For y = 1 to imageheight
c = ReadPixelFast x,y
If c = shirtcolor Then WritePixelFast x,y,newcolor
Next
Next
UnlockBuffer
Next
SetBuffer BackBuffer()

If you want to make a copy first, just do a CopyImage ahead of time and run this routine on the copy instead.

Edit: Yeah, you do this before your main loop.


gnipper(Posted 2003) [#6]
hmmmmmmm yeah i see what you are doing... but would that not change the entire sprite to the new colour - effectively erasing the image!?

Quietblokes idea is the one i need to pursue.. i spose i will need to locate the pixels on the indiviual animation frames and repace them 1 by 1? Not a quick task but "do-able"


Miracle(Posted 2003) [#7]
Er, no ... it's only looking for the old short color, and if it finds it, replaces it with the new one.


gnipper(Posted 2003) [#8]
oh i c now!! ill give it a go!

This is just what i needed!

Cheers


SSS(Posted 2003) [#9]
btw are you talking bout blitz3d sprites or custom sprites because if you are using blitz3d sprites all you have to do is entitycolor sprite, 255,0,0 for a red sprite


Anthony Flack(Posted 2003) [#10]
Another thing worth noting - if you use 256 colour bitmaps, you can apply different palletes to it to get different colours at loadtime (this is much faster). "But blitz doesn't support paletted images!" I hear you cry. True, but it loads them in well enough. Every paletted bmp has the pallet info at the start of the file. If you overwrite these values with a new palette before loading the image, hey presto! I had some code that did this knocking about on the forum somewhere, but gawd onlyknows where it is...