Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

attempt to call method 'translet' (a nil value) in corona

Tags:

lua

coronasdk

For this function fallingCoins(), I'm getting backward moving coins in my code and I need to hide these coins when anchor touches the coins.

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'm hiding the coins if it touch 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 coins then I'm getting 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'm doing mistake..

like image 823
VenkatSoma Avatar asked Nov 01 '22 04:11

VenkatSoma


1 Answers

translate method can be applied to display objects. Here your objects is also a physics, objects. You can change problematic line with:

myPlayer.x = myPlayer.x - 2

P.S : But in this case it will move soo fast^^

like image 64
Doğancan Arabacı Avatar answered Nov 08 '22 07:11

Doğancan Arabacı