![](/img/trans.png)
[英]Corona SDK saying attempt to call method 'removeSelf()' (a nil value)
[英]attempt to call method 'translet' (a nil value) in corona
對於這個函數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
---------------------------
"
請幫我,我在做錯了..
translate方法可以應用於顯示對象。 在這里你的對象也是一個物理,對象。 你可以改變有問題的行:
myPlayer.x = myPlayer.x - 2
PS:但在這種情況下,它會快速移動^^
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.