The objective is to make animated objects larger in time and disappear when the user clicks on them; my approach (shown below) was to use timers to scale the objects. The problem for me is that I cannot figure out how to assign each object its very own timer with timerID so they can be canceled and removed when tapped. A problem I see further down the road is how will I identify which object has been tapped so the appropriate timer is removed?
Is there an easier way to do this? I’ve looked at beebegames.lua but didn’t see how that would help this situation.
Any help is greatly appreciated!
[code]
–what happens when killed (play sound + add to score + remove timer + remove self)
local function kill(event)
media.playEventSound( brickSound )
score.setScore (score.getScore()+107)
timer.cancel(getlarger)
event.target:removeEventListener(“tap”,kill)
end
–Function to make Bad Guys
local bunch = {}
–# of bad guys
local evil = 3
local function spawnBadguy(event)
local myAnim = movieclip.newAnim{“cube01.png”, “cube02.png”, “cube03.png”, “cube04.png”, “cube05.png”, “cube06.png”}
p0_subGroup1:insert(myAnim)
local x = math.random(50,200)
local y = 200
local i = event.count
bunch[i] = myAnim
bunch[i].x = x
bunch[i].y = y
p0_subGroup2:insert(bunch[i])
local growth = .01
local function grow()
bunch[i].xScale = bunch[i].xScale + growth
bunch[i].yScale = bunch[i].yScale + growth
end
–Make Bad Guys Come at You (time between frames, function,number of scales)
getlarger = timer.performWithDelay(5,grow,1000)
– Start the animations
bunch[i]:play() – play all frames
bunch[i]:addEventListener(“tap”,kill)
end
–Spawn Bad Guy
timer.performWithDelay(1000,spawnBadguy,evil) --spawn 2 seconds apart
[/code] [import]uid: 27080 topic_id: 6083 reply_id: 306083[/import]