加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

lua – 尝试在日冕中调用方法’translet'(零值)

发布时间:2020-12-14 21:49:55 所属栏目:大数据 来源:网络整理
导读:对于这个函数fallingCoins(),我在我的代码中向后移动硬币,当锚接触硬币时我需要隐藏这些硬币. function fallingCoins()local myPlayer = display.newCircle( math.random(20,_W+20),-25,math.random(10,10) ) myPlayer:setStrokeColor(255,128,0 ) myPlayer:
对于这个函数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
---------------------------
...asdesktoprun2scrollscrolling backgroundmain.lua:123: attempt to call method 'translate' (a nil value)
stack traceback:
    [C]: in function 'translate'
    ...asdesktoprun2scrollscrolling backgroundmain.lua:123: in function <...asdesktoprun2scrollscrolling backgroundmain.lua:122>
    ?: in function <?:218>

Do you want to relaunch the project?
---------------------------
Yes   No   
---------------------------
"

请帮我,我在做错了..

解决方法

translate方法可以应用于显示对象.在这里你的对象也是一个物理,对象.
你可以改变有问题的行:

myPlayer.x = myPlayer.x - 2

P.S:但在这种情况下它会快速移动^^

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读