对于这个功能fallingCoins(),我在代码中向后移动硬币,当锚点接触硬币时我需要隐藏这些硬币.
function fallingCoins()
local myPlayer = display.newCircle( math.random(20,_W+20), -25, math.random(10,10) )
myPlayer:setStrokeColor(255, 128, 0 )
myPlayer:setFillColor(math.random(245,255),math.random(210,223),7)
myPlayer.myName = "myPlayer"
physics.addBody( myPlayer, "static" )
myPlayer.y = "150"
local function muovi()
myPlayer:translate(-2, 0)
end
Runtime:addEventListener( "enterFrame", muovi );
end
timer.performWithDelay( 3000, fallingCoins )
Run Code Online (Sandbox Code Playgroud)
如果碰到锚,我就会隐藏硬币.
function onCollision3( event )
if(event.object1.myName == "guy" and event.object2.myName == "myPlayer") then
event.object2:removeSelf();
end
end
Runtime:addEventListener( "collision", onCollision3 )
Run Code Online (Sandbox Code Playgroud)
如果我触摸硬币然后我就会收到此错误
"---------------------------
Corona Runtime Error
---------------------------
...as\desktop\run2\scroll\scrolling background\main.lua:123: attempt to call method 'translate' (a nil value)
stack …Run Code Online (Sandbox Code Playgroud)