--[[ 动画播放管理器 --]] local PropAniPlayer = class("PropAniPlayer") function PropAniPlayer:ctor(node) self.node = node for k,v in pairs(GameProp) do loadSpriteFrameFile(v.plistFile) end loadSpriteFrameFile("res/ui/zy_tongyong/zy_prop/item10/item10_anims_bulletdown.plist") loadSpriteFrameFile("res/ui/zy_tongyong/zy_prop/item10/item10_anims_bulletBow.plist") loadSpriteFrameFile("res/ui/zy_tongyong/zy_prop/item10/item10_bow.plist") end function PropAniPlayer:playAnimation(nodeBegin, nodeEnd, propId) logD(string.format("PropAniPlayer:playAnimation() %s", propId)) -- 判断道具ID是否存在 if not GameProp or not GameProp[propId] then logD(string.format("PropAniPlayer:playAnimation() %s is not exist", propId)) return end -- 判断起始节点是否有效 if tolua.isnull(nodeBegin) then logD(string.format("PropAniPlayer:playAnimation() nodeBegin is null")) return; end if tolua.isnull(nodeEnd) then logD(string.format("PropAniPlayer:playAnimation() nodeEnd is null")) return; end local posBegin = nodeBegin:getWorldPosition(); local posEnd = nodeEnd:getWorldPosition(); if propId == 9 then self:playAnimation_09(posBegin, posEnd) elseif propId == 10 then self:playAnimation_10(posBegin, posEnd) else self:playAnimationNor(posBegin, posEnd, propId) end end function PropAniPlayer:playAnimationWithPos(posBegin, posEnd, propId) if propId == 9 then self:playAnimation_09(posBegin, posEnd) elseif propId == 10 then self:playAnimation_10(posBegin, posEnd) else self:playAnimationNor(posBegin, posEnd, propId) end end -- 播放普通的道具动画 function PropAniPlayer:playAnimationNor(posBegin, posEnd, propId) local aniConfig = GameProp[propId] if not aniConfig then return end -- 创建图片 local nodeImage = cc.ImageView:createNode() nodeImage:loadTexture(string.format("res/ui/zy_tongyong/zy_prop/item%d/item%d_fly-i6p.png",propId,propId)) if self.node then self.node:addChild(nodeImage) else app.mainScene:addChild(nodeImage) end nodeImage:setPosition(posBegin) nodeImage:setOpacity(0) --判断纹理是否存在 local name = string.format("item%d_%d.png",propId,1) local cache = cc.SpriteFrameCache:getInstance() local spriteFrame = cache:getSpriteFrameByName(name); if tolua.isnull(spriteFrame) then print("spriteFrame is not in cache") nodeImage:removeFromParent() return end nodeImage:runAction(cc.Sequence:create(cc.FadeIn:create(0.1),cc.MoveTo:create(0.5,posEnd),cc.CallFunc:create(function () local musicFilePath = string.format("res/sound/room/prop_ogg/item%d.ogg",propId) local soundID = playVoice(musicFilePath) local indexFace = 0; local maxList = {19,28,20,29,19,28,30,13} --每隔多少秒切换一张图片 local everyFrame if propId > 2 then everyFrame = 0.05 elseif propId == 2 then everyFrame = 0.025 elseif propId == 1 then everyFrame = 0.115 end local seq = cc.Sequence:create(cc.DelayTime:create(everyFrame),cc.CallFunc:create(function () indexFace = indexFace + 1 if 0 < indexFace and indexFace <= maxList[propId] then local name = string.format("item%d_%d.png",propId,indexFace) if not tolua.isnull(nodeImage) then nodeImage:loadTexture(name, cc.TextureResType.plistType) end else nodeImage:removeFromParent() stopVoice(soundID) end end)) local act = cc.Repeat:create(seq,maxList[propId] + 2) nodeImage:runAction(act) end))) end -- 播放道具动画09 function PropAniPlayer:playAnimation_09(posBegin, posEnd) local propId = 9 local nodeImage = cc.ImageView:createNode() nodeImage:loadTexture(string.format("res/ui/zy_tongyong/zy_prop/item%d/item%d_fly-i6p.png",propId,propId)) nodeImage:setPosition(posBegin) nodeImage:setOpacity(0) if self.node then self.node:addChild(nodeImage) else app.mainScene:addChild(nodeImage) end --判断纹理是否存在 local name = string.format("item%d_%d.png",propId,1) local cache = cc.SpriteFrameCache:getInstance() local spriteFrame = cache:getSpriteFrameByName(name); if tolua.isnull(spriteFrame) then print("spriteFrame is not in cache") nodeImage:removeFromParent() return end local musicFilePath = string.format("res/sound/room/prop_ogg/item%d.ogg",propId) playVoice(musicFilePath) nodeImage:runAction(cc.Sequence:create(cc.FadeIn:create(0.1),cc.CallFunc:create(function () local indexFace = 0; --每隔多少秒切换一张图片 local everyFrame everyFrame = 0.09 local seq = cc.Sequence:create(cc.DelayTime:create(everyFrame),cc.CallFunc:create(function () indexFace = indexFace + 1 if 0 < indexFace and indexFace <= 13 then local name = string.format("item%d_%d.png",propId,indexFace) if not tolua.isnull(nodeImage) then nodeImage:loadTexture(name, cc.TextureResType.plistType) end end end)) local act = cc.Repeat:create(seq,13) nodeImage:runAction(act) end),cc.DelayTime:create(13 * 0.09),cc.CallFunc:create(function () --旋转角度 local disX = math.abs(posEnd.x - posBegin.x) local disY = math.abs(posEnd.y - posBegin.y) local angle = math.deg(math.atan(disY/disX)) --第一象限 if posEnd.y - posBegin.y >= 0 and posEnd.x <= posBegin.x then --第二象限 angle = 180 - angle elseif posEnd.y <= posBegin.y and posEnd.x <= posBegin.x then --第三象限 angle = 180 + angle elseif posEnd.y <= posBegin.y and posEnd.x >= posBegin.x then --第四象限 angle = -1 * angle end nodeImage:setEulerRotation(cc.vec3(0,0,angle)) end),cc.MoveTo:create(0.5,posEnd),cc.CallFunc:create(function () nodeImage:setEulerRotation(cc.vec3(0,0,0)) local indexFace = 13; local max = 33 - 14 --每隔多少秒切换一张图片 local everyFrame everyFrame = 0.09 local seq = cc.Sequence:create(cc.DelayTime:create(everyFrame),cc.CallFunc:create(function () indexFace = indexFace + 1 if 0 < indexFace and indexFace <= max then local name = string.format("item%d_%d.png",propId,indexFace) if not tolua.isnull(nodeImage) then nodeImage:loadTexture(name, cc.TextureResType.plistType) end else nodeImage:removeFromParent() end end)) local act = cc.Repeat:create(seq,max + 2) nodeImage:runAction(act) end))) end -- 播放道具动画10 function PropAniPlayer:playAnimation_10(beginPos, endPos) local propID = 10 local nodeImage = cc.ImageView:createNode() nodeImage:loadTexture(string.format("res/ui/zy_tongyong/zy_prop/item%d/item%d_fly-i6p.png",propID,propID)) nodeImage:setPosition(beginPos) nodeImage:setOpacity(0) if self.node then self.node:addChild(nodeImage) else app.mainScene:addChild(nodeImage) end --激光枪 local cache = cc.SpriteFrameCache:getInstance() local spriteFrame = cache:getSpriteFrameByName("item10_1.png"); if tolua.isnull(spriteFrame) then print("spriteFrame is not in cache") nodeImage:removeFromParent() return end nodeImage:loadTexture("item10_1.png",cc.TextureResType.plistType) local qiangSize = nodeImage:getContentSize() nodeImage:runAction(cc.Sequence:create(cc.FadeIn:create(0.1),cc.CallFunc:create(function () local musicFilePath = string.format("res/sound/room/prop_ogg/item%d.ogg",propID) local soundID = playVoice(musicFilePath) local indexFace = 0; local lunshu = 1 --每隔多少秒切换一张图片 local everyFrame = 0.15 local seq = cc.Sequence:create(cc.DelayTime:create(everyFrame),cc.CallFunc:create(function () indexFace = indexFace + 1 if 0 < indexFace and indexFace <= 4 then local name = string.format("item%d_%d.png",propID,indexFace) if not tolua.isnull(nodeImage) then nodeImage:loadTexture(name, cc.TextureResType.plistType) end elseif indexFace > 4 and lunshu < 2 then indexFace = 0 lunshu = lunshu + 1 else nodeImage:removeFromParent() stopVoice(soundID) end end)) local act = cc.Repeat:create(seq,8 + 5) nodeImage:runAction(act) end))) local disX = math.abs(endPos.x - beginPos.x) local disY = math.abs(endPos.y - beginPos.y) local angle = math.deg(math.atan(disY/disX)) --第一象限 if endPos.y - beginPos.y >= 0 and endPos.x <= beginPos.x then --第二象限 angle = 180 - angle elseif endPos.y <= beginPos.y and endPos.x <= beginPos.x then --第三象限 angle = 180 + angle elseif endPos.y <= beginPos.y and endPos.x >= beginPos.x then --第四象限 angle = -1 * angle end nodeImage:setEulerRotation(cc.vec3(0,0,angle + 180)) --散落的子弹动画 local nodeBulletImage = cc.ImageView:createNode() nodeBulletImage:loadTexture(string.format("res/ui/zy_tongyong/zy_prop/item%d/item%d_fly-i6p.png",propID,propID)) nodeImage:addChild(nodeBulletImage) local sizeDown = nodeBulletImage:getContentSize() --nodeBulletImage:setPosition(beginPos) nodeBulletImage:setPosition(cc.p(0 + 25 * sizeDown.width,qiangSize.height/2)) nodeBulletImage:setOpacity(0) nodeBulletImage:setFlippedX(true) local cache = cc.SpriteFrameCache:getInstance() local spriteFrame = cache:getSpriteFrameByName("item10_danke_1.png"); if tolua.isnull(spriteFrame) then print("spriteFrame is not in cache") nodeBulletImage:removeFromParent() return end nodeBulletImage:loadTexture("item10_danke_1.png",cc.TextureResType.plistType) nodeBulletImage:runAction(cc.Sequence:create(cc.FadeIn:create(0.1),cc.CallFunc:create(function () local indexFace = 0; local lunshu = 1 --每隔多少秒切换一张图片 local everyFrame = 0.15 local seq = cc.Sequence:create(cc.DelayTime:create(everyFrame),cc.CallFunc:create(function () indexFace = indexFace + 1 if 0 < indexFace and indexFace <= 3 then local name = string.format("item%d_danke_%d.png",propID,indexFace) if not tolua.isnull(nodeBulletImage) then nodeBulletImage:loadTexture(name, cc.TextureResType.plistType) end elseif indexFace > 3 and lunshu < 2 then indexFace = 0 lunshu = lunshu + 1 else nodeBulletImage:removeFromParent() stopVoice(soundID) end end)) local act = cc.Repeat:create(seq,6 + 5) nodeBulletImage:runAction(act) end))) --电火花 local nodeBowImage = cc.ImageView:createNode() nodeBowImage:loadTexture(string.format("res/ui/zy_tongyong/zy_prop/item%d/item%d_fly-i6p.png",propID,propID)) nodeImage:addChild(nodeBowImage) local sizeBow = nodeBowImage:getContentSize() --nodeBowImage:setPosition(beginPos) local y = math.random(-18,18) nodeBowImage:setPosition(cc.p(0 - sizeBow.width/2,qiangSize.height/2)) nodeBowImage:setOpacity(0) nodeBowImage:setFlippedX(true) local cache = cc.SpriteFrameCache:getInstance() local spriteFrame = cache:getSpriteFrameByName("item10_guang_1.png"); if tolua.isnull(spriteFrame) then print("spriteFrame is not in cache") nodeBowImage:removeFromParent() return end nodeBowImage:loadTexture("item10_guang_1.png",cc.TextureResType.plistType) nodeBowImage:runAction(cc.Sequence:create(cc.FadeIn:create(0.1),cc.CallFunc:create(function () local indexFace = 0; local lunshu = 1 --每隔多少秒切换一张图片 local everyFrame = 0.15 local seq = cc.Sequence:create(cc.DelayTime:create(everyFrame),cc.CallFunc:create(function () indexFace = indexFace + 1 if 0 < indexFace and indexFace <= 7 then local name = string.format("item%d_guang_%d.png",propID,indexFace) if not tolua.isnull(nodeBowImage) then nodeBowImage:loadTexture(name, cc.TextureResType.plistType) end elseif indexFace > 7 and lunshu < 2 then indexFace = 0 lunshu = lunshu + 1 else nodeBowImage:removeFromParent() stopVoice(soundID) end end)) local act = cc.Repeat:create(seq,14 + 5) nodeBowImage:runAction(act) end))) --子弹动画 for i = 1,15 do local bullet = cc.ImageView:createNode() bullet:loadTexture("res/ui/zy_tongyong/zy_prop/item10/item10_bullet_fly.png") bullet:setAnchorPoint(cc.p(0.5,0.5)) local size = bullet:getContentSize() nodeImage:addChild(bullet) bullet:setPosition(cc.p(0 - size.width/2,qiangSize.height/2)) --目标点 local targetPos = nodeImage:convertToNodeSpace(endPos) bullet:setOpacity(0) bullet:runAction(cc.Sequence:create(cc.DelayTime:create(i * 0.1),cc.FadeIn:create(0.1),cc.CallFunc:create(function () end),cc.MoveTo:create(0.35,cc.p(targetPos.x,targetPos.y)),cc.RemoveSelf:create(true))) end --弹孔动画 --判断纹理是否存在 local name = string.format("item%d_bow_%d.png",10,1) local cache = cc.SpriteFrameCache:getInstance() local spriteFrame = cache:getSpriteFrameByName(name); if tolua.isnull(spriteFrame) then print("spriteFrame is not in cache") return end local bulletHole = cc.ImageView:createNode() bulletHole:loadTexture(string.format("res/ui/zy_tongyong/zy_prop/item%d/item%d_fly-i6p.png",10,10)) if self.node then self.node:addChild(bulletHole) else app.mainScene:addChild(bulletHole) end --node:addChild(bulletHole) bulletHole:setPosition(endPos) bulletHole:setOpacity(0) bulletHole:runAction(cc.Sequence:create(cc.FadeIn:create(0.1),cc.CallFunc:create(function () local indexFace = 0; --每隔多少秒切换一张图片 local everyFrame everyFrame = 0.1 local seq = cc.Sequence:create(cc.DelayTime:create(everyFrame),cc.CallFunc:create(function () indexFace = indexFace + 1 if 0 < indexFace and indexFace <= 13 then local name = string.format("item%d_bow_%d.png",10,indexFace) if not tolua.isnull(bulletHole) then bulletHole:loadTexture(name, cc.TextureResType.plistType) end else bulletHole:runAction(cc.Sequence:create(cc.DelayTime:create(1.0),cc.CallFunc:create(function () bulletHole:removeFromParent() end))) end end)) local act = cc.Repeat:create(seq,13 + 2) bulletHole:runAction(act) end))) end return PropAniPlayer