I have a click event attached to a frog and flys flying in from the left of the screen. When the click event is “ended” the frog shoots out his tongue to catch a fly… Does anybody know how I can have a fly’s alpha transition down to 0 when the player clicks on a frog? I know how to do it if it wasn’t part of a spawn function.
Here is my code:
[lua]display.setStatusBar( display.HiddenStatusBar ) – HIDE STATUS BAR
local rand = math.random
local i = 1
local flysCaught = 0
local loqsprite = require(‘loq_sprite’)
local screenW = display.contentWidth
local screenH = display.contentHeight
local BG = display.newImageRect(“background.png”, 1024, 768)
BG.x = screenW/2; BG.y = screenH/2
local ffactory = loqsprite.newFactory(“frog”)
local frog = ffactory:newSpriteGroup()
frog.x = 640 ; frog.y = 470
local numberCount = display.newText(string.format("%02d", 0), 0, 0, native.systemFontBold, 40)
numberCount.x = frog.x; numberCount.y = frog.y
local hitArea = display.newRect( 0, 0,display.contentWidth, 250 )
hitArea:setFillColor( 255, 255, 255 )
hitArea.alpha = 0
function letsCount ()
flysCaught = flysCaught + 1
numberCount.text = string.format("%02d", flysCaught)
–transition.to(numberCount, { time=1500, y =100, alpha = 0} )
end
local function removeFly( _t)
_t:removeSelf()
_t = nil
print(“fly removed”)
end
local function spawnFlys()
local flyfactory = loqsprite.newFactory(“fly”)
local fly = flyfactory:newSpriteGroup()
fly.x = rand(300,380); fly.y = rand(300,380)
fly:play(“aniFly fly”)
local moveSpeed = rand(2500, 45000)
transition.to(fly, {time=moveSpeed, x=1550, onComplete=removeFly})
end
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
catchFlys = function( event )
local phase = event.phase
local function onContact()
local eatFly = hitTestObjects( frog, hitArea)
if (eatFly == true) then
print(“fly cought”)
letsCount ()
end
end
if ( phase == “ended” ) then
frog:play(“aniFrog eat”)
timer.performWithDelay(15, onContact, 1 )
end
end
timer.performWithDelay(50, spawnFlys,20)
frog:addEventListener( “touch”, catchFlys ) [/lua]
Also I want to have a little mor control on how the flys come out… I want them to just show up 1 at a time instead of little bunches.
Thanks
[import]uid: 51459 topic_id: 16338 reply_id: 316338[/import]
[import]uid: 3826 topic_id: 16338 reply_id: 60876[/import]