Lua 如何使用transition.to随机移动对象?
我试图将一个对象随机移动到不同的位置,因此我得出以下结论:transition.to随机生成x,y以及时间,在finish运行另一个函数,该函数检查对象是否仍然存在,并将其发送到不同的位置 但我有一个错误:Lua 如何使用transition.to随机移动对象?,lua,logic,coronasdk,Lua,Logic,Coronasdk,我试图将一个对象随机移动到不同的位置,因此我得出以下结论:transition.to随机生成x,y以及时间,在finish运行另一个函数,该函数检查对象是否仍然存在,并将其发送到不同的位置 但我有一个错误: Runtime error main.lua:352: stack overflow stack traceback: main.lua:352: in function 'toAnotherPlace' 看起来corona并没有真正等待过渡完成,所以它会进行无限循环 代码 您可以试
Runtime error
main.lua:352: stack overflow
stack traceback:
main.lua:352: in function
'toAnotherPlace'
看起来corona并没有真正等待过渡完成,所以它会进行无限循环
代码
您可以试试这个,我添加了一个
onComplete=function()。。。结束
,我调用到另一个位置(对象)
函数
如果您直接在onComplete
function toAnotherPlace(object)
print(object.width)
if object ~= nil then
transition.to( object,
{
time = math.random(1500,6000),
alpha = 1,
x = math.random(10, 310),
y = math.random(10, 400),
onComplete = function()
toAnotherPlace(object)
end
})
end
end
transition.to(bossess[boss],
{
time = math.random(1500,6000),
alpha = 1,
x = math.random(10, 310),
y = math.random(10, 400),
onComplete = function()
toAnotherPlace(bossess[boss])
end
})
我试过了,效果很好,没有错误
如果仍然出现错误,请检查
bossess[boss]
如果有对对象的引用您可以尝试一下,我添加了一个onComplete=function()。。。结束
,我调用到另一个位置(对象)
函数
如果您直接在onComplete
function toAnotherPlace(object)
print(object.width)
if object ~= nil then
transition.to( object,
{
time = math.random(1500,6000),
alpha = 1,
x = math.random(10, 310),
y = math.random(10, 400),
onComplete = function()
toAnotherPlace(object)
end
})
end
end
transition.to(bossess[boss],
{
time = math.random(1500,6000),
alpha = 1,
x = math.random(10, 310),
y = math.random(10, 400),
onComplete = function()
toAnotherPlace(bossess[boss])
end
})
我试过了,效果很好,没有错误
如果仍然出现错误,请检查
bossess[boss]
是否有对对象的引用是的,确实如此,谢谢!是的,就是这样,谢谢!