Lua timer.performWithDelay无法正常工作
我有以下代码:Lua timer.performWithDelay无法正常工作,lua,coronasdk,Lua,Coronasdk,我有以下代码: local function RemovePlayer() print("Something") end function change(e) if(e.phase=="began")then Player.alpha=1 Player.height=50 Player.width=50 end if(e.phase=="moved")then angle=(math.atan2( (e.y
local function RemovePlayer()
print("Something")
end
function change(e)
if(e.phase=="began")then
Player.alpha=1
Player.height=50
Player.width=50
end
if(e.phase=="moved")then
angle=(math.atan2( (e.y - Player.y), (e.x - Player.x))*180)/math.pi +90
Player.rotation=angle
end
if(e.phase=="ended")then
transition.to(Player,{time=200,height=32,width=32})
local xx = (e.x-Player.x)*2
local yy = (e.y-Player.y)*2
Player.bodyType = "dynamic"
Player:applyForce( xx, yy, Player.x, Player.y )
timer.performWithDelay ( 10000,RemovePlayer() )
end
return true
end
问题是timer.performWithDelay似乎无法正常工作,因为在结束阶段之后,控制台中会立即打印内容,而不是延迟10000次。知道为什么会发生这种情况吗?尝试按如下方式调用计时器:
timer.performWithDelay ( 10000,RemovePlayer,1 )
-- 1 is the number of times that the 'RemovePlayer' function is to be called.
继续编码 尝试按如下方式调用计时器:
timer.performWithDelay ( 10000,RemovePlayer,1 )
-- 1 is the number of times that the 'RemovePlayer' function is to be called.
继续编码 发生这种情况可能是因为: 定时器将首先执行该功能;然后在10000毫秒后再次执行它。因此,您可以即时获得输出 如果要让用户等待10秒;使用os.sleep 10 另一个可能的原因是您在声明计时器时调用函数。更改:
timer.performWithDelay ( 10000,RemovePlayer() )
到
这可能是因为: 定时器将首先执行该功能;然后在10000毫秒后再次执行它。因此,您可以即时获得输出 如果要让用户等待10秒;使用os.sleep 10 另一个可能的原因是您在声明计时器时调用函数。更改:
timer.performWithDelay ( 10000,RemovePlayer() )
到
我也试过了,但没有改变什么。无论如何,谢谢你的建议@AvraamMavridis:我已经试过你上面的代码,对我来说非常有效。所以,只需检查您是否在代码中的任何其他位置直接调用RemovePlayer。我也尝试过,但没有更改某些内容:。无论如何,谢谢你的建议@AvraamMavridis:我已经试过你上面的代码,对我来说非常有效。所以,只需检查您是否在代码中的任何其他位置直接调用RemovePlayer。我也遇到了同样的问题,removing解决了这个问题!谢谢我也有同样的问题,并且解决了这个问题!谢谢