Hi guys, as you can see from the title, I’m having trouble with collisions and translations…
here’s the code I’m using, followed by my problems:
local function coin()
local coin = display.newCircle(5, 5, 5)
coin:setReferencePoint(display.CenterReferencePoint);
coin.x = mRand(50, \_W-50);
coin.y = mRand(50, \_H-50);
coin.myName = "coin"
end
tmr = timer.performWithDelay(20, coin, max)
local function animate()
coin:translate(0, 1)
Runtime:addEventListener( "enterFrame", animate );
end
physics.addBody(coin,"static",{isSensor = true})
function onCollision( event )
if ( event.phase == "began" ) then
if event.object1.myName == "coin" and event.object2.myName == "player" then
event.object1.alpha = 0.001
end
elseif ( event.phase == "ended" ) then
if event.object1.myName == "coin" and event.object2.myName == "player" then
event.object1:removeSelf()
event.object1 = nil
end
end
end
Runtime:addEventListener( "collision", onCollision )
If “coin” collides with “player”, it dissapears, but if I use a function to spawns more than one coin (in my case 20), they won’t be collected by “player”… in other words, they don’t dissapear and I don’t know why, any suggestions?
And then I’ve got the same problem with translations, so if the coin is only one, it will translate, but if I spawn more than a coin, they stay fixed to their original position.
I’d really appreciate your help
Thanks 
[import]uid: 122056 topic_id: 34017 reply_id: 334017[/import]
