function UnitNode:movePath (path, callBack)
self._spine:setAnimation(0, "run" , true)
local i = 1
local pt = cc.p(path:get(i))
local move = cc.MoveTo:create(0.5, pt)
//声明回调
local done
//定义回调函数
local function callback()
if i == path:len() then
self._spine:setAnimation(0, "idle" , true)
if callBack then
callBack()
end
return true
end
i = i + 1
pt = cc.p(path:get(i))
local selfX, selfY = self :getPosition()
local lenX = pt.x - selfX
local lenY = pt.y - selfY
local dist = math.sqrt (lenX * lenX + lenY * lenY)
if lenX > 0 then
self._spineBlur:setRotationSkewY(180)
else
self._spineBlur:setRotationSkewY(0)
end
self:stopAllActions()
if dist > 16 then
move = cc.MoveTo:create((dist / 200), pt)
else
move = cc.MoveTo:create((dist * math.sqrt(2) / 200), pt)
end
action = cc.Sequence:create(move,done, nil)
self:runAction(action)
end
//创建回调
done = cc.CallFunc:create(callback)
//创建动作
local action = cc.Sequence:create(move, done, nil)
//运行动作
self:runAction(action)
end
按寻路路径连续移动(方法1)开始有卡顿
最新推荐文章于 2019-10-31 10:10:15 发布