播发拖影特效
--function g_PlayShadowAction 播发拖影特效 拖影的对象必须先显示,否则无法实现剪切
--@param:moveNode 移动的节点
--@param:pContainer 复制的对象
--@param:count 出现次数
--@param:interval 间隔时间
--@param:color 影子颜色 cc.c3b
function g_PlayShadowAction( pContainer,count,interval,color,hideInterval)
--print("g_PlayShadowAction");
if not pContainer then
return
end
local countSprite = 0;
local actionSprite = cc.Sprite:create();
local ppContainer = pContainer:getParent()
if not ppContainer then
return
end
local pppContainer = ppContainer:getParent()
if not pppContainer then
return
end
pppContainer:addChild(actionSprite);
local function callBackFunc()
if ppContainer.m_nMonomer then
local pSprite = g_CutPicture(ppContainer.m_nMonomer);
if pSprite then
local aniSize = pContainer:getContentSize();
local aniAnchorPoint = cc.p( ppContainer:getAnchorPoint() );
--aniAnchorPoint.x = 0.5;
local postion = cc.p( ppContainer:getPositionX() - aniSize.width/2 ,
ppContainer:getPositionY() - aniSize.height/2 ) ;
--print( ppContainer:getPositionX(), ppContainer:getPositionY());
pSprite:setPosition( postion );
if color then
pSprite:setColor( color ); --cc.c3b( 0,255,0 )
end
pSprite:setAnchorPoint( aniAnchorPoint );
pppContainer:addChild(pSprite,ppContainer:getLocalZOrder() -1 );
countSprite = countSprite + 1;
local function moveCallFunc()
pSprite:removeFromParent();
if countSprite > count then
actionSprite:removeFromParent();
end
end
pSprite:setOpacity(150);
local fadeTo = cc.FadeTo:create( hideInterval , 0);
local moveFunc = cc.CallFunc:create(moveCallFunc);
pSprite:runAction( cc.Sequence:create(fadeTo,moveFunc) );
end
end
end
local actionTable = {};
for i=1,count-1 do
local delayTime = cc.DelayTime:create(interval)
local callFunc = cc.CallFunc:create(callBackFunc)
table.insert(actionTable,delayTime);
table.insert(actionTable,callFunc);
end
local action = cc.Sequence:create( unpack(actionTable) )
actionSprite:runAction(action);
return actionSprite;
end
使用样例
-- 设置 是否播放残影
function BonesEffect:setPlayGhostTime(nGhostTime)
self.m_nGhostTime = nGhostTime
end
-- 播放 残影
function BonesEffect:playGhost(monomer)
if monomer then
local t = self.m_nGhostTime/1000 -- 播放时间
local wt = 0.4 -- 残影存在时间 渐影
if self.m_nGhostTime and t>0 then
g_PlayShadowAction( monomer.m_nMonomer,t,GAME_FRAME_FLUENT*3,cc3BLUE,wt)
end
--if self.m_isSkillBreak then
monomer:setDisappearSkill(self.m_skillMgr,self.m_isSkillBreak)
--end
end
end