测试的代码使得了一个3D动画,就是那个FantasyWarrior3D里面带的,首先是加了个Touch事件,每次在移动和站立之间切换,动作的Action使用retain,如果点太快了就会出现移动动作卡在某一帧上。如果是在同一个方法里不断调用切换不会出问题,间隔一会(5-8FPS)再切换也可以。每次切换时都使用clone也可以。
部分创建的代码如下:
function Actor:initActions( actions )
self._actions = {}
for k,v in ipairs(actions) do
local animation3d = cc.Animation3D:create(string.format(self._file, v.name));
local animate3d;
if v.begin==nil then
animate3d = cc.Animate3D:create(animation3d);
else
animate3d = cc.Animate3D:create(animation3d, v.begin/30,(v.finish-v.begin)/30)
end
animate3d:setSpeed(v.speed or 1)
if v.name==Actions.ATTACK then
self._actions = cc.Sequence:create(animate3d,cc.CallFunc:create(self.restoreState));
else
self._actions = cc.RepeatForever:create(animate3d);
end
self._actions:retain()
end
end
–使用这个方法,点太快时就会卡住
function Actor:_play(name)
if self._curAnimation ~= name then
local action = self._actions;
if action~=nil then
self:stopAction(action)
end
self._curAnimation = name
self:runAction(self._actions)
end
end
–使用这个方法是正常的,但每次都得重新创建一次Action
function Actor:play(name)
if self._curAnimation ~= name then
if self._playAction~=nil then
self:stopAction(self._playAction)
end
self._curAnimation = name
self._playAction = self._actions:clone()
self:runAction(self._playAction)
end
end