Hi you all, I my game there are coins that fall from the top to the bottom of the screen, and I want my character to collect them.
It works, but the problem is that when I collect the first one of them, the other ones stop falling, I don’t know why… here’s the code I used:
[code]
local function coin()
local token = display.newImage(“immagini/moneta.png”)
token:setReferencePoint(display.CenterReferencePoint);
token.x = mRand(50, _W-50);
token.y = mRand(-100, -100)-100;
token.myName = “token”
physics.addBody(token,“static”,{isSensor = true})
local function muovi()
token:translate(0, 1)
end
Runtime:addEventListener( “enterFrame”, muovi );
end
tmr = timer.performWithDelay(500, coin, 0)
–COLLISIONS
function onCollision( event )
if ( event.phase == “began” ) then
if event.object1.myName == “lines” and event.object2.myName == “player” then
transition.to( event.object1, { alpha=0, time=200 } )
local function removeLines()
lines[i].parent:remove(lines[i])
lines[i] = nil
end
removetmrLines = timer.performWithDelay(200, removeLines, 1)
scrolling = true
score = score + 100
media.playSound( “suoni/boing1.wav” )
local function animate()
bg1:translate(0, 3)
bg2:translate(0, 3)
bg3:translate(0, 3)
bg4:translate(0, 3)
bg5:translate(0, 3)
bg6:translate(0, 3)
bg7:translate(0, 3)
bg8:translate(0, 3)
bg9:translate(0, 3)
bg10:translate(0, 3)
bg11:translate(0, 3)
bg12:translate(0, 3)
bg13:translate(0, 3)
bg14:translate(0, 3)
bg15:translate(0, 3)
bg16:translate(0, 3)
bg17:translate(0, 3)
bg18:translate(0, 3)
bg19:translate(0, 3)
bg20:translate(0, 3)
bg21:translate(0, 3)
end
Runtime:addEventListener( “enterFrame”, animate );
local function remove()
Runtime:removeEventListener(“enterFrame”, animate)
end
trmRemove = timer.performWithDelay(500, remove, 1)
end
elseif ( event.phase == “ended” ) then
if event.object1.myName == “token” and event.object2.myName == “player” then
media.playSound( “suoni/boing1.wav” )
event.object1:removeSelf()
event.object1 = nil
end
end
end
Runtime:addEventListener( “collision”, onCollision )
[/code] [import]uid: 122056 topic_id: 35165 reply_id: 335165[/import]