Main Menu

sprite transparent colour

Started by daver, September 11, 2011, 11:39:31 AM

Previous topic - Next topic

daver

Hi there,

Assuming it's possible to do this, I'm trying to load a PNG file to be used as a spite, designate the colour I want PB to treat as transparent and then display it. However, the white background on the attached image is being displayed instead of the background colour used when I performed a CLS.

Any help in the right direction would be appreciated.


Cls rgb(34,102,204)
LoadFxImage "GFX\stickman_running_1.png",1
ImageMaskColour 1,rgb(255,255,255)
Sprite1 = NewSprite(200,200,1)
SpriteDrawMode Sprite1,2

PositionSprite Sprite1, 200, 200
DrawAllSprites
Sync
wait 2000

kevin


  Even though you're not using it, the image prolly sets the alpha channel byte to 255 on mask colour pixels.

So try changing this   

   ImageMaskColour 1,rgb(255,255,255)

to

   ImageMaskColour 1,argb(255,255,255,255)



daver


kevin

  What you could do, is pre-process the images and convert the WHITE mask colour of rgb(255,255,255) into black rgb(0,0,0), the sprite render engine has opt's for this.  Same applies for the image width, where power of 2 sizes are easier for it rotate than none power of two sizes.  




  path$="E:\Downloads_FDM\"

Cls rgb(34,102,204)

; original method
LoadFxImage path$+"stickman_running_1.png",1
ImageMaskColour 1,argb(255,255,255,255)
Sprite1 = NewSprite(200,200,1)
SpriteDrawMode Sprite1,2


; conversion method
LoadFxImage path$+"stickman_running_1.png",2
  ConvertMaskColourToZero(2,argb(255,255,255,255))
 
Sprite2 = NewSprite(400,200,2)
SpriteDrawMode Sprite2,2


DrawAllSprites
Sync
waitkey


/*
This Function replaces none zero mask colour with a black pixel
*/

Function ConvertMaskColourToZero(ThisImage,CurrentmaskCOlour)
oldsurface=getsurface()
rendertoimage ThisImage
For ylp=0 to getimageheight(ThisIMage)-1
lockbuffer
ThisPixel=POint(0,0)
For xlp=0 to getimagewidth(ThisIMage)-1
ThisPixel=fastPoint(xlp,ylp)
if ThisPixel=CurrentMaskColour
ThisPixel=0
else
ThisPixel|=$ff000000
endif
fastdot xlp,ylp,ThisPixel
next
unlockbuffer
next
rendertoimage oldsurface
endfunction