B+, Emulators, and ALPHA Sprites!

BlitzPlus Forums/BlitzPlus Programming/B+, Emulators, and ALPHA Sprites!

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

If you are only doing a few sprites here and there, you don't have to wpf the entire screen. Just put the color values of the sprites into arrays and then only read the pixels that are in the actual location you are drawing to. If you are drawing a 32x32 pixel sprite then that is only 1024 rpf plus another 1024 wpf to write it back. If you have some kind of masking color you might even avoid a bunch of those as well with an if-check. A fullscreen in the above is 307,200 rpf+wpf's which ofcause is somewhat on the slow side. But you can have plenty of smaller sprites moving around no problem.

You could do something like this:

Function drawTransp(x,y,transp)
transpn = 1-transp
LockBuffer BackBuffer()
For yy=0 To 39
	For xx=0 To 39
		mask = spritemaskdata(xx,yy)
		If mask <>$ff0000 Then
		rgbs = spritedata(xx,yy)
		rgbd = ReadPixelFast(x+xx,y+yy,BackBuffer())
		r = (((rgbs Shr 16) And $ff) * transp) + (((rgbd Shr 16) And $ff) * transpn)
		g = (((rgbs Shr 8) And $ff) * transp) + (((rgbd Shr 8) And $ff) * transpn)
		b = ((rgbs And $ff) * transp) + ((rgbd And $ff) * transpn)
		If r > 255 Then r = 255
		If g > 255 Then g = 255
		If b > 255 Then b = 255
		If r < 0 Then r = 0
		If g < 0 Then g = 0
		If b < 0 Then b = 0
		rgbf = r Shl 16 + g Shl 8 + b
		If x+xx > -1 And x+xx < 640 And y+yy > -1 And y+yy < 480 Then WritePixelFast x+xx,y+yy,rgbf
		End If
	Next
Next 
UnlockBuffer BackBuffer() 
End Function


And before you use it put the rgb values of the sprite and mask into the arrays set up for it.