Attempting to call the 'translet' method (nil value) in the crown

For this function, fallingCoins()I get reverse coins in my code, and I need to hide these coins when the binding touches the coin.

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 )

And I hide the coins if they touch the anchor.

function onCollision3( event )
   if(event.object1.myName == "guy" and event.object2.myName == "myPlayer") then
      event.object2:removeSelf(); 
   end
end
Runtime:addEventListener( "collision", onCollision3 )

If I touch the coins, I get this error

"---------------------------
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   
---------------------------
"

Please help me where I am wrong.

+4
source share
1 answer

The translation method can be applied to displayed objects. Here your objects are also physics, objects. You can change the problem line:

myPlayer.x = myPlayer.x - 2

PS: But in this case, he will quickly move at a speed ^^

+2
source

Source: https://habr.com/ru/post/1529971/


All Articles