[lua]display.setStatusBar (display.HiddenStatusBar)
–> Hides the status bar
local loqsprite = require(‘loq_sprite’)
display.setDefault(“background”, 255, 255, 255)
loqsprite.addScale(2)
local lfactory = loqsprite.newFactory(‘leaf’)
local leaf = lfactory:newSpriteGroup()
–local leaf = display.newImageRect (“leaf.png”, 66, 47)
leaf.x = 50; leaf.y = 50
local box = display.newRect (0, 0, 80, 80)
box.x = 50; box.y = 50
box.alpha = 0
local box2 = display.newRect (0, 0, 80, 80)
box2.x = 150; box2.y = 150
box2:setFillColor (0, 0, 0)
box2.alpha = 0
local cfactory = loqsprite.newFactory(‘caterpillar’)
local caterpillar = cfactory:newSpriteGroup()
caterpillar.x = 200; caterpillar.y = 50
caterpillar:play(“aniCatipilar still”)
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
function complete ()
caterpillar:prepare( “aniCatipilar flying”)
end
–atrace(xinspect(catipilar:getSpriteNames()))
local function onTouch(_e)
local t = _e.target
local phase = _e.phase
if “began” == phase then
leaf:play(“aniLeaf throb”)
caterpillar:play(“aniCatipilar moving”)
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
–print(hitTestObjects(box, catipilar))
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
caterpillar:play(“aniCatipilar still”)
if hitTestObjects(box, caterpillar) == true then
transition.to(leaf, { time=2500, alpha= 0, transition=easing.inOutExpo})
caterpillar:play( “aniCatipilar eating”)
leaf:play(“aniLeaf eat”)
box2.alpha = 1
end
if hitTestObjects(box2, caterpillar) == true then
print(“cocoon TIME!!!”)
caterpillar:play( “aniCatipilar Cocoon”)
caterpillar:removeEventListener( “touch”, onTouch )
local function touchcocoon (event)
–print (“touching cocoon YAY!”)
caterpillar:play( “aniCatipilar SliceCocoon”)
timer.performWithDelay ( 150, complete )
caterpillar:addEventListener( “touch”, dragButterfly )
caterpillar:removeEventListener (“touch”, touchcocoon)
end
caterpillar:addEventListener (“touch”, touchcocoon)
end
end
end
return true
end
local function dragButterfly(_e)
local t = _e.target
local phase = _e.phase
if “began” == phase then
caterpillar:play(“aniCatipilar flying”)
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
–print(hitTestObjects(box, catipilar))
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
caterpillar:prepare(“aniCatipilar flying”)
end
end
return true
end
caterpillar:addEventListener( “touch”, onTouch )
[/lua]
Ok so all of this code is working except for the last bit of it… When I start the app you see a caterpillar you can drag the caterpillar to the leaf and he eats the leaf… you see a box appear and you drag the caterpillar to that box… he then creates a cocoon and you can touch the cocoon to hatch it… you now see a butterfly… What I am stumped on is how I can move this butterfly with the dragButterfly function… it doesn’t seem to work because it is still linked to onTouch event… how do I tell the program that I now what the dragButterfly event??
Thanks for any help!! [import]uid: 51459 topic_id: 21911 reply_id: 321911[/import]