Lua 尝试调用方法';易位';(零值)在电晕中
对于这个函数Lua 尝试调用方法';易位';(零值)在电晕中,lua,coronasdk,Lua,Coronasdk,对于这个函数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
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 )
如果硬币碰到锚,我就把它藏起来
function onCollision3( event )
if(event.object1.myName == "guy" and event.object2.myName == "myPlayer") then
event.object2:removeSelf();
end
end
Runtime:addEventListener( "collision", onCollision3 )
如果我碰了硬币,我就犯了这个错误
"---------------------------
Corona Runtime Error
---------------------------
...as\desktop\run2\scroll\scrolling background\main.lua:123: attempt to call method 'translate' (a nil value)
stack traceback:
[C]: in function 'translate'
...as\desktop\run2\scroll\scrolling background\main.lua:123: in function <...as\desktop\run2\scroll\scrolling background\main.lua:122>
?: in function <?:218>
Do you want to relaunch the project?
---------------------------
Yes No
---------------------------
"
”---------------------------
电晕运行时错误
---------------------------
…as\desktop\run2\scroll\scrolling background\main.lua:123:尝试调用方法“translate”(一个空值)
堆栈回溯:
[C] :在函数“translate”中
…作为\desktop\run2\scroll\scrolling background\main.lua:123:in函数
?:在函数中,平移方法可用于显示对象。这里的对象也是物理对象,对象。
您可以使用以下命令更改有问题的行:
myPlayer.x = myPlayer.x - 2
附言:但在这种情况下,它会快速移动,main.lua中哪一行是123?