I made this function today as an example and decided to post it here in case anyone else has a use for it.
It's similar to SPRITE DIFFUSE but allows you to set the sprite to a solid color as well as partial colors (SPRITE DIFFUSE will always have at least half of the sprite's original color coming through).
`Basic setup stuff
sync on: sync rate 60
hide mouse
`Some constants...
`BaseImage in this case is the BASE IMAGE (duh). This image will never be modified.
#Constant BaseImage 1
`SpriteImage is the image that is changed by the SetSpriteMask function.
#Constant SpriteImage 2
#Constant SpriteNo 1
`Set up the base sprite...
load image "StarByScraggle.png",BaseImage
load image "StarByScraggle.png",SpriteImage
sprite SpriteNo,100,100,SpriteImage
sync
`This function will have the effect an alpha'd and diffused sprite would, but without the need for any kind of mask.
SetSpriteMask(255,100,100,200,SpriteImage,BaseImage)
sync
wait key
end
function SetSpriteMask(R,G,B,A,fn_SpriteImage,fn_BaseImage)
if image exist(fn_SpriteImage) then delete image fn_SpriteImage
temp=FreeMemblock()
make memblock from image temp,fn_BaseImage
for c=12 to get memblock size(temp)-3 step 4
oldr=memblock byte(temp,c+2)
oldg=memblock byte(temp,c+1)
oldb=memblock byte(temp,c)
newr=int(oldr*((255-A)/255.0)+R*(A/255.0))
newg=int(oldg*((255-A)/255.0)+G*(A/255.0))
newb=int(oldb*((255-A)/255.0)+B*(A/255.0))
write memblock byte temp,c+2,newr
write memblock byte temp,c+1,newg
write memblock byte temp,c,newb
next c
make image from memblock fn_SpriteImage,temp
delete memblock temp
endfunction
function FreeMemblock()
repeat
inc temp
until memblock exist(temp)=0
endfunction temp
It uses one of Scraggle's free suns as a test image...attached.