Masked Sprites

Blitz3D SDK Forums/Blitz3D SDK Programming/Masked Sprites

How do I get a created sprite() with a texture applied to it to have some transparent sections?

When I say created I mean that I don't want to have to load a sprite but want to create it on the fly.

All I seem to get is the black pixels being drawn along with all the other colours.

Not sure exactly what you're trying to achieve but you may need to make use of temporary files:

* Create a texture (including transparency)
* Save the texture to a png file
* Load the texture
* Apply it to your Sprite
* Delete the png file

Example in BlitzMax:


Strict

Import blitz3d.blitz3dsdk

bbBeginBlitz3D()

bbGraphics3D 800, 600

bbSetBuffer bbBackBuffer()

bbAmbientLight 255, 255, 255

Local Camera = bbCreateCamera()
bbPositionEntity Camera, 0, 0, -4
bbCameraClsColor Camera, 0, 0, 128

Local Sprite = bbCreateSprite()

Local texture_url:String = "temp_texture.png"

createMyTexture(texture_url)
Local Tex = bbLoadTexture(texture_url, 8 + 2 + 1)
DeleteFile texture_url

bbTextureBlend Tex, 1							

bbEntityTexture Sprite, Tex, 0, 0	
		
While Not bbKeyHit(BBKEY_ESCAPE)

	bbRenderWorld

	bbFlip

Wend

bbFreeTexture Tex

bbEndBlitz3d()

End


Function createMyTexture(url:String, width:Int = 64, height:Int = 64)

	SeedRnd MilliSecs()

	Local pm:TPixmap = CreatePixmap(width, height, PF_RGBA8888)
	
	For Local x:Int = 0 To PixmapWidth(pm) - 1
		For Local z:Int = 0 To PixmapHeight(pm) - 1
		
			Local a:Int = 255
			
			If Rand(0, 1) Then a = 0
		
			WritePixel pm, x, z, Int(a Shl 24 | Rand(0, 255) Shl 16 | Rand(0, 255) Shl 8 | Rand(0, 255))
		
		Next
	Next
	
	SavePixmapPNG(pm, url)
	
EndFunction



Thanks for the advice.