I have to objects that go in to different hitSpots (left wing and right wing to a rocket ship)
[lua]local wingl = display.newImageRect(“wingL.png”, 67, 67)
wingl.x = 100; wingl.y = 360
local wingr = display.newImageRect(“wingR.png”, 67, 67)
wingr.x = 200; wingr.y = 360
local hitspotR = display.newImageRect(“hitSpot.png”, 44, 74)
hitspotR.x = 183; hitspotR.y = 690
hitspotR.alpha = .3
local hitspotL = display.newImageRect(“hitSpot.png”, 44, 74)
hitspotL.x = 120; hitspotL.y = 690
hitspotL.alpha = .3[/lua]
What I am having trouble with is getting the right wing to stay at its hit spot when the mouse is released… Here is the code I written to make the left wing work…
[lua]function hitTestObjects(obj1, obj2)
local left = obj1.contentBounds.xMin <= obj2.contentBounds.xMin and obj1.contentBounds.xMax >= obj2.contentBounds.xMin
local right = obj1.contentBounds.xMin >= obj2.contentBounds.xMin and obj1.contentBounds.xMin <= obj2.contentBounds.xMax
local up = obj1.contentBounds.yMin <= obj2.contentBounds.yMin and obj1.contentBounds.yMax >= obj2.contentBounds.yMin
local down = obj1.contentBounds.yMin >= obj2.contentBounds.yMin and obj1.contentBounds.yMin <= obj2.contentBounds.yMax
return (left or right) and (up or down)
end
local function dragWing(_e)
local t = _e.target
local phase = _e.phase
if _e.phase == “began” then
local parent = t.parent
display.getCurrentStage():setFocus( t )
t.isFocus = true
t.x0 = _e.x - t.x
t.y0 = _e.y - t.y
elseif t.isFocus then
if “moved” == phase then
t.x = _e.x - t.x0
t.y = _e.y - t.y0
elseif “ended” == phase or “cancelled” == phase then
if hitTestObjects(t, hitspotL) == true then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
else
print ( “missed target” )
wingl.x = leftX
wingl.y = leftY
wingr.x = rightX
wingr.y = rightY
display.getCurrentStage():setFocus( nil )
t.isFocus = false
end
end
end
return true
end[/lua]
If anybody can point my in the right direction that would be AWESOME!!
Thanks [import]uid: 51459 topic_id: 15147 reply_id: 315147[/import]