Collision problems with masked images.

BlitzMax Forums/BlitzMax Beginners Area/Collision problems with masked images.

I'm having some trouble with collisions between masked images. With the code listed here the tank can overlap the tiles quite a bit without regestering a hit. I've tried without the rotation and still the results are bad. The only thing that seems to fix it is to load the images without masking them. Any ideas on what could be wrong?

Strict

Graphics 640,480,0

Type tTank
	Field x,y,rot:Float
	Field img:tImage
	
	Function Create:tTank(file:String)
		Local this:tTank=New tTank
		
		this.x=200
		this.y=200
		this.rot=0
		SetMaskColor 255,0,255
		this.img=LoadImage(file,MASKEDIMAGE)
		SetImageHandle(this.img,ImageWidth(this.img)/2,ImageHeight(this.img)/2)

		Return this
	End Function
	
	Method Update()
		x=MouseX()
		y=MouseY()
		rot:+1
		
		SetRotation rot
		DrawImage img,x,y
	End Method
	
End Type

Type tTile
	Field x
	Field y
	Field frame
End Type

SetMaskColor 255,0,255
Local tiles:tImage=LoadAnimImage("Terrain2.bmp",32,32,0,6,MASKEDIMAGE)
Local tnk:tTank=tTank.create("tank.bmp")
Local colTiles:tList=CreateList()
For Local n=0 Until 30
	Local t:tTile=New tTile
	t.x=rnd(GraphicsWidth()-ImageWidth(tiles))
	t.y=rnd(GraphicsHeight()-ImageHeight(tiles))
	t.frame=rnd(5)
	colTiles.AddLast t
Next

Repeat

	Cls

	SetRotation 0
	For Local t:tTile=EachIn colTiles
		DrawImage tiles,t.x,t.y,t.frame
	Next	

	tnk.update

	If CheckCollision(tnk,tiles,colTiles,tnk.x,tnk.y)
		SetRotation 0		
		DrawText "COLLISION!!",0,0
	EndIf

	FlushMem
	Flip

Until KeyHit(KEY_ESCAPE)


Function CheckCollision(tnk:tTank,tiles:tImage,colTiles:tList,x,y)
	ResetCollisions 1

	SetRotation 0
	For Local t:tTile=EachIn colTiles
		CollideImage(tiles,t.x,t.y,t.frame,0,1)
	Next

	SetRotation tnk.rot
	If CollideImage(tnk.img,x,y,0,1,0) Then Return 1

	Return 0
End Function


Here are the images I'm using:




Can anyone confirm if they have the same problem when running this code? I'm still not sure what I'm doing wrong so any help would be appreciated. Thanks!

I'm having the same problem but after my system went pear-shaped last time I haven't made the collisions changes again.

Hi, I tried your code with win 2k and got the same problem. It is until the pointer is over the tile that the msg appears. About the solution, haven't got a clue :S

Thanks for checking guys.

Hmm... Seems to work fine when using a single image instead of an anim image for the "ground" images. Possible bug in CollideImage?

Found it, it's a bug with masked anim frames, if you can rebuild modules the fix is line65-68 of image.bmx in brl.mod/max2d.mod:
			Local window:TPixmap=pixmap.Window( x,y,cell_width,cell_height ).Copy()	
			image.frames[cell-first]=blitz2d_driver.CreateFrameFromPixmap( window,flags )
			image.masks[cell-first]=window


Good stuff Skidracer. It works fine now.
Can we have this and the imagecollide 'timage' bugfix in a new official module?

Thanks Skidracer! I'll try it out later when I get home.