Exact Collision detection

Blitz3D Forums/Blitz3D Beginners Area/Exact Collision detection

The Forum Archive is locked. These are the original blitzbasic.com forums, kept so their posts can still be read and searched. No new topics, replies or edits can be made here. To join the conversation, head over to the Blitz3D+ forums.

depend of what you call quick.
the only method i know is to read each pixel of the two image and if a pixel is different exit the checking loop
as the fastest method is to check if a picture is different it's generaly quicker:)
Graphics 800,600,32,0
ClsColor 50,50,50
a=CreateImage(32,32)
b=CreateImage(32,32)
Cls
DrawBlock a,10,10
DrawBlock b,45,10
Text 0,40,checkmatch(a,b)
Flip 
WaitKey
SetBuffer ImageBuffer(a)
Plot 10,10
SetBuffer FrontBuffer()
Cls
DrawBlock a,10,10
DrawBlock b,45,10
Text 0,40,checkmatch(a,b)
Flip 
WaitKey



Function checkmatch(picta,pictb)
	x=-1:y=0
	Repeat
	x=x+1
	If x>31
		y=y+1
		x=0
	EndIf
	Until (ReadPixel(x,y,ImageBuffer(picta))<>ReadPixel(x,y,ImageBuffer(pictb))) Or (x=0 And y>31)
	If x=0 And y>31
		Return -1 ;match
	Else
		Return 0 ;no match
	EndIf
End Function

this method is fast if the tiles are really different but take more time on testing graphics that differs by one or two pixels if they are far from the start of the check