started learning and developing games using Corona SDK recently and right now I am facing an issue to collect coins in the gameplay. When the player object collides with the coin object the coin should be removed/disappeared. I tried the below code which is not successful whenever the coin collides with the player it throws an error
Attempt to call method ‘translate’ (a nil value)
Below is the code I used,
------Create Coins------
function coin()
token = display.newImage(sceneContainer, “gold.png”)
token.x = math.random(320, 720)
token.y = math.random(160, 260)
token.myName = “token”
physics.addBody( token, “dynamic”, { bounce=0, friction=1, radius=20 })
local function muovi()
token:translate(-2, 0)
end
Runtime:addEventListener( “enterFrame”, muovi )
end
tmr = timer.performWithDelay(5000, coin, 0)
------Collision Function------
function onCollision( event )
if ( event.phase == “began” ) then
if event.object1.myName == “player” and event.object2.myName == “token” then
event.object2:removeSelf()
print(“hitting 1”)
elseif event.object1.myName == “token” and event.object2.myName == “player” then
event.object1:removeSelf()
print(“hitting 1”)
end
end
end
Runtime:addEventListener( “collision”, onCollision)