SetMaskColor and GrabImage

BlitzMax Forums/BlitzMax Beginners Area/SetMaskColor and GrabImage

Chalky(Posted 2007) [#1]
I have imported a bb game into bmax and am having trouble understanding all the SetBlend/SetMaskColor/CreateImage/GrabImage command settings required to get my code to work. In B3D, I loaded a bmp and then grabbed each tile, setting the mask color each time:
Function TilesLoad()
	Local Palette%
	Local TileW%
	Local k%
	
	Palette%=LoadImage("Palette.tmp")
	If Palette%<>0 Then
		CurrentBuffer%=GraphicsBuffer()
		SetBuffer ImageBuffer(Palette%)
		TileW%=TileSize%-1
		For k%=0 To MaxTiles%-1
			Tiles%(k%+1)=CreateImage(TileW%,TileW%)
			GrabImage Tiles%(k%+1),k%*TileW%,0
			MaskImage Tiles%(k%+1),192,192,255
		Next
		SetBuffer CurrentBuffer%
		FreeImage Palette%
	EndIf
End Function

In bmax, I tried the following:
Function TilesLoad()
	Local Palette:TImage
	Local TileW%
	Local k%
	
	SetMaskColor 1,1,1 ' I seem to need this or bmax alphablends any black areas when I DrawImage to the BackBuffer despite SOLIDBLEND...
	Palette=LoadImage("Palette.tmp")
	If Palette<>Null Then
		Cls
		SetColor 255,255,255
		SetBlend SOLIDBLEND
		DrawImage Palette,0,0
		SetBlend ALPHABLEND
		TileW%=TileSize%-1
		SetMaskColor 192,192,255
		For k%=0 To MaxTiles%-1
			Tiles:TImage[k%+1]=CreateImage(TileW%,TileW%,DYNAMICIMAGE|MASKEDIMAGE)
			GrabImage Tiles[k%+1],k%*TileW%,0
		Next
		Palette=Null
		GCCollect
	EndIf
End Function

but the mask color is ignored later when I DrawImage the grabbed Tiles[]. I am evidently making a very basic error - probably due to my lack of understanding as to how all these commands integrate with each other - so if anyone can tell me what I am going wrong I would be very grateful!!


Chalky(Posted 2007) [#2]
Ok - I have got it working. In case anyone is interested:
Function TilesLoad()
	Local Palette:TImage
	Local TileW%
	Local k%
	
	SetMaskColor 192,192,255
	Palette=LoadImage("Palette.tmp")
	If Palette<>Null Then
		TileW%=TileSize%-1
		SetBlend ALPHABLEND
		For k%=0 To MaxTiles%-1
			Tiles[k%+1]=LoadImage(PixmapWindow(LockImage(Palette),k%*TileW%,0,TileW%,TileW%))
		Next
		Palette=Null
		GCCollect
	EndIf
EndFunction