Does this get you started?
[code]
local function hitTestObjects(obj1, obj2)
– added tollerance because collision was happening before touching
local tollerance = -1
local left = (obj1.contentBounds.xMin + tollerance) <= obj2.contentBounds.xMin and obj1.contentBounds.xMax >= (obj2.contentBounds.xMin + tollerance)
local right = obj1.contentBounds.xMin >= (obj2.contentBounds.xMin + tollerance) and (obj1.contentBounds.xMin + tollerance) <= obj2.contentBounds.xMax
local up = (obj1.contentBounds.yMin + tollerance) <= obj2.contentBounds.yMin and obj1.contentBounds.yMax >= (obj2.contentBounds.yMin + tollerance)
local down = obj1.contentBounds.yMin >= (obj2.contentBounds.yMin + tollerance) and (obj1.contentBounds.yMin + tollerance) <= obj2.contentBounds.yMax
return (left or right) and (up or down)
end – hitTestObjects
local img1 = display.newRect(0, 0, 50, 50)
img1.x = 50 ; img1.y = 50
local function drag(event)
if event.phase == “moved” then
img1.x = event.x
img1.y = event.y
end
end
img1:addEventListener(“touch”, drag)
local myText = display.newText(“drag the square over me to win”, 50,200, “Helvetica”, 16)
local function onComplete( event )
if “clicked” == event.action then
local i = event.index
if 1 == i then
print(“replay”)
elseif 2 == i then
print (“next level”)
end
end
end – onComplete
local function listenForWin(event)
if hitTestObjects(myText, img1) then
Runtime:removeEventListener(“enterFrame”, listenForWin)
local alert = native.showAlert( “You Win!”, “Congratulations”,
{ “replay”, “Next level” }, onComplete )
end
end – listenForWin
Runtime:addEventListener(“enterFrame”, listenForWin)
[/code] [import]uid: 12635 topic_id: 8087 reply_id: 29242[/import]