local winSize = CCDirector:shareDirector():getWinSize()
local layer = CCLayerColor:create(ccc4(0, 0, 0, 111), winSize.winSize, winSize.height)
--加载运动过程中的动画 使用文件加载 texturepacker
for i = 1, n do --这里n是帧的数量
local path = string.format("%d.png", i)
local name = CCSpriteFrameCache:sharedSpriteFrameCache():spriteFrameByName(path)
array:addObject(name)
end
local animation = CCAnimation:createWithSpriteFrames(array)
--也可以用table来设计几个动
--[[
local info =
{
{ pointx = 1, pointy = 2},
{ pointx = 1, pointy = 2}
}
local j = 0
for j = 1, #info do
local info1 = info[j]
info1.pointx
end
]]
--运动动画
local j = 0
for j = 1, 10 do --几个在动
--刚刚设置的帧动画
animation:setDelayPerUnit((math.random(5, 10)) / 70)
animation:setRestoreOriginalFrame(true)
local animate = CCAnimate:create(animation)
animate:setTag(0)
--运动动画
local sprite = CCSprite:create("图片文件, 这里是跟plist文件名一样的名字哟")
local offset = j * math.random(-1, 1) --这里-1, 1 就是中间分割 向两侧产生
sprite:setPosition(ccp(x + offset, y)) -- 这里的x, y 你自己定义
sprite:setScale(1.2)
layer:addChile(sprite)
local arraymove = CCArray:create()
arraymove:addObject(CCDelayTime:create(j * 0.1)) --根据需要自己设置延时
local moveto = CCMoveTo:create(0.8, ccp(x + offset, y)) --跟上面的对比 x, y自己设置
local arrayFade = CCArray:create()
local delayFade = CCDelayTime:create(0.8)
local fade = CCFadeTo:create(0.05, 0) --0.05秒内, 变为不透明
arrayFade:addObject(delayFade)
arrayFade:addObject(fade)
local actionFade = CCSequence:create(arrayFade)
local spawn = CCSpawn:createWithTwoActions(moveto, actionFade) --让精灵的若干个动画同时执行
arraymove:addObject(spawn)
local action = CCSequence:create(arraymove)
sprite:runAction(CCRepeateForever:create(animate))
sprite:runAction(action)
end
--延迟销毁动作
local scene = CCDirector:sharedDirector():getRunningScene()
scene:addChile(layer, 100)
local arrayend = CCArray:create()
arrayend:addObject(CCDelayTime:create(2)) --延迟时间
arrayend:addObject(CCFadeTo:create(0.1, 0))
arrayend:addObject(CCCallFuncN:create(removeLayer)) --这里removeLayer是一个函数
local endAction = CCSequence:create(arrayend)
layer:runAction(endAction)
function removeLayer(n)
n = tolua.cast(n, "CCNode")
n:removeFromParentAndCleanup(true)
end