ballx值保持不变,因为你可能没有更新它,直接改变ball.x。事实上,这是做到这一点的方法:你应该使用ball.x,因为这是被改变的真实值,而不是ballx。
然而,如果你仍然想使用一个参考值ball.x,您可以直接设置ballx = ball.x
和然后更新ballx值。
当您完成更新ballx值时,您也可以更新ball.x值,以及像您一样更新paddles。
local updateBall = function()
ballx = ballx + 20 --update the ballx value
end
Runtime:addEventListener("enterFrame", updateBall)
local myListener = function(event)
ball.x = ballx --then update the ball itself with the ballx value
upperpad.x = ballx --and make the paddles follow
lowerpad.x = ballx
end
Runtime:addEventListener("enterFrame", myListener)
编辑:如果您想手动设置桨位置取决于球的(这是由物理引擎处理),只是让他们按照原来的ball.x值。你不需要需要ballx。
local movePaddles = function(event)
upperpad.x = ball.x
lowerpad.x = ball.x
end
Runtime:addEventListener("enterFrame", movePaddles)
在函数myListener中添加ballx = ball.x将更改ballx。 – Albert
你应该在你的其他问题上接受我的回答。对于这个问题,我想有时候你需要展示更多的信息(代码)。 –