Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Snippet: Collision check Box2Box — Gideros Forum

Snippet: Collision check Box2Box

MikeHartMikeHart Guru
edited January 2012 in Code snippets
Hi there,

here is a function, which will check a collision between 2 sprites by checking if the boundries overlap.
collCheck_Box2B = function( source, target )
	local rw = source:getWidth()/2.0 + target:getWidth()/2.0
	local rh = source:getHeight()/2.0 + target:getHeight()/2.0
	if math.abs(source:getY() - target:getY()) < rh then
		if math.abs(source:getX() - target:getX() ) < rw then
			return true
		end
	end
	return false
end
You might want to make the math.abs call local. Same goes for the width and height. If you don't need to calculate them dynamically, then store these values when you create the sprite in them and use these user properties.

Cheers
Michael

Likes: WauloK

+1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.