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..
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^^
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With