You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

404 line
13 KiB

  1. --[[
  2. 动画播放管理器
  3. --]]
  4. local PropAniPlayer = class("PropAniPlayer")
  5. function PropAniPlayer:ctor(node)
  6. self.node = node
  7. for k,v in pairs(GameProp) do
  8. loadSpriteFrameFile(v.plistFile)
  9. end
  10. loadSpriteFrameFile("res/ui/zy_tongyong/zy_prop/item10/item10_anims_bulletdown.plist")
  11. loadSpriteFrameFile("res/ui/zy_tongyong/zy_prop/item10/item10_anims_bulletBow.plist")
  12. loadSpriteFrameFile("res/ui/zy_tongyong/zy_prop/item10/item10_bow.plist")
  13. end
  14. function PropAniPlayer:playAnimation(nodeBegin, nodeEnd, propId)
  15. logD(string.format("PropAniPlayer:playAnimation() %s", propId))
  16. -- 判断道具ID是否存在
  17. if not GameProp or not GameProp[propId] then
  18. logD(string.format("PropAniPlayer:playAnimation() %s is not exist", propId))
  19. return
  20. end
  21. -- 判断起始节点是否有效
  22. if tolua.isnull(nodeBegin) then
  23. logD(string.format("PropAniPlayer:playAnimation() nodeBegin is null"))
  24. return;
  25. end
  26. if tolua.isnull(nodeEnd) then
  27. logD(string.format("PropAniPlayer:playAnimation() nodeEnd is null"))
  28. return;
  29. end
  30. local posBegin = nodeBegin:getWorldPosition();
  31. local posEnd = nodeEnd:getWorldPosition();
  32. if propId == 9 then
  33. self:playAnimation_09(posBegin, posEnd)
  34. elseif propId == 10 then
  35. self:playAnimation_10(posBegin, posEnd)
  36. else
  37. self:playAnimationNor(posBegin, posEnd, propId)
  38. end
  39. end
  40. function PropAniPlayer:playAnimationWithPos(posBegin, posEnd, propId)
  41. if propId == 9 then
  42. self:playAnimation_09(posBegin, posEnd)
  43. elseif propId == 10 then
  44. self:playAnimation_10(posBegin, posEnd)
  45. else
  46. self:playAnimationNor(posBegin, posEnd, propId)
  47. end
  48. end
  49. -- 播放普通的道具动画
  50. function PropAniPlayer:playAnimationNor(posBegin, posEnd, propId)
  51. local aniConfig = GameProp[propId]
  52. if not aniConfig then
  53. return
  54. end
  55. -- 创建图片
  56. local nodeImage = cc.ImageView:createNode()
  57. nodeImage:loadTexture(string.format("res/ui/zy_tongyong/zy_prop/item%d/item%d_fly-i6p.png",propId,propId))
  58. if self.node then
  59. self.node:addChild(nodeImage)
  60. else
  61. app.mainScene:addChild(nodeImage)
  62. end
  63. nodeImage:setPosition(posBegin)
  64. nodeImage:setOpacity(0)
  65. --判断纹理是否存在
  66. local name = string.format("item%d_%d.png",propId,1)
  67. local cache = cc.SpriteFrameCache:getInstance()
  68. local spriteFrame = cache:getSpriteFrameByName(name);
  69. if tolua.isnull(spriteFrame) then
  70. print("spriteFrame is not in cache")
  71. nodeImage:removeFromParent()
  72. return
  73. end
  74. nodeImage:runAction(cc.Sequence:create(cc.FadeIn:create(0.1),cc.MoveTo:create(0.5,posEnd),cc.CallFunc:create(function ()
  75. local musicFilePath = string.format("res/sound/room/prop_ogg/item%d.ogg",propId)
  76. local soundID = playVoice(musicFilePath)
  77. local indexFace = 0;
  78. local maxList = {19,28,20,29,19,28,30,13}
  79. --每隔多少秒切换一张图片
  80. local everyFrame
  81. if propId > 2 then
  82. everyFrame = 0.05
  83. elseif propId == 2 then
  84. everyFrame = 0.025
  85. elseif propId == 1 then
  86. everyFrame = 0.115
  87. end
  88. local seq = cc.Sequence:create(cc.DelayTime:create(everyFrame),cc.CallFunc:create(function ()
  89. indexFace = indexFace + 1
  90. if 0 < indexFace and indexFace <= maxList[propId] then
  91. local name = string.format("item%d_%d.png",propId,indexFace)
  92. if not tolua.isnull(nodeImage) then
  93. nodeImage:loadTexture(name, cc.TextureResType.plistType)
  94. end
  95. else
  96. nodeImage:removeFromParent()
  97. stopVoice(soundID)
  98. end
  99. end))
  100. local act = cc.Repeat:create(seq,maxList[propId] + 2)
  101. nodeImage:runAction(act)
  102. end)))
  103. end
  104. -- 播放道具动画09
  105. function PropAniPlayer:playAnimation_09(posBegin, posEnd)
  106. local propId = 9
  107. local nodeImage = cc.ImageView:createNode()
  108. nodeImage:loadTexture(string.format("res/ui/zy_tongyong/zy_prop/item%d/item%d_fly-i6p.png",propId,propId))
  109. nodeImage:setPosition(posBegin)
  110. nodeImage:setOpacity(0)
  111. if self.node then
  112. self.node:addChild(nodeImage)
  113. else
  114. app.mainScene:addChild(nodeImage)
  115. end
  116. --判断纹理是否存在
  117. local name = string.format("item%d_%d.png",propId,1)
  118. local cache = cc.SpriteFrameCache:getInstance()
  119. local spriteFrame = cache:getSpriteFrameByName(name);
  120. if tolua.isnull(spriteFrame) then
  121. print("spriteFrame is not in cache")
  122. nodeImage:removeFromParent()
  123. return
  124. end
  125. local musicFilePath = string.format("res/sound/room/prop_ogg/item%d.ogg",propId)
  126. playVoice(musicFilePath)
  127. nodeImage:runAction(cc.Sequence:create(cc.FadeIn:create(0.1),cc.CallFunc:create(function ()
  128. local indexFace = 0;
  129. --每隔多少秒切换一张图片
  130. local everyFrame
  131. everyFrame = 0.09
  132. local seq = cc.Sequence:create(cc.DelayTime:create(everyFrame),cc.CallFunc:create(function ()
  133. indexFace = indexFace + 1
  134. if 0 < indexFace and indexFace <= 13 then
  135. local name = string.format("item%d_%d.png",propId,indexFace)
  136. if not tolua.isnull(nodeImage) then
  137. nodeImage:loadTexture(name, cc.TextureResType.plistType)
  138. end
  139. end
  140. end))
  141. local act = cc.Repeat:create(seq,13)
  142. nodeImage:runAction(act)
  143. end),cc.DelayTime:create(13 * 0.09),cc.CallFunc:create(function ()
  144. --旋转角度
  145. local disX = math.abs(posEnd.x - posBegin.x)
  146. local disY = math.abs(posEnd.y - posBegin.y)
  147. local angle = math.deg(math.atan(disY/disX)) --第一象限
  148. if posEnd.y - posBegin.y >= 0 and posEnd.x <= posBegin.x then --第二象限
  149. angle = 180 - angle
  150. elseif posEnd.y <= posBegin.y and posEnd.x <= posBegin.x then --第三象限
  151. angle = 180 + angle
  152. elseif posEnd.y <= posBegin.y and posEnd.x >= posBegin.x then --第四象限
  153. angle = -1 * angle
  154. end
  155. nodeImage:setEulerRotation(cc.vec3(0,0,angle))
  156. end),cc.MoveTo:create(0.5,posEnd),cc.CallFunc:create(function ()
  157. nodeImage:setEulerRotation(cc.vec3(0,0,0))
  158. local indexFace = 13;
  159. local max = 33 - 14
  160. --每隔多少秒切换一张图片
  161. local everyFrame
  162. everyFrame = 0.09
  163. local seq = cc.Sequence:create(cc.DelayTime:create(everyFrame),cc.CallFunc:create(function ()
  164. indexFace = indexFace + 1
  165. if 0 < indexFace and indexFace <= max then
  166. local name = string.format("item%d_%d.png",propId,indexFace)
  167. if not tolua.isnull(nodeImage) then
  168. nodeImage:loadTexture(name, cc.TextureResType.plistType)
  169. end
  170. else
  171. nodeImage:removeFromParent()
  172. end
  173. end))
  174. local act = cc.Repeat:create(seq,max + 2)
  175. nodeImage:runAction(act)
  176. end)))
  177. end
  178. -- 播放道具动画10
  179. function PropAniPlayer:playAnimation_10(beginPos, endPos)
  180. local propID = 10
  181. local nodeImage = cc.ImageView:createNode()
  182. nodeImage:loadTexture(string.format("res/ui/zy_tongyong/zy_prop/item%d/item%d_fly-i6p.png",propID,propID))
  183. nodeImage:setPosition(beginPos)
  184. nodeImage:setOpacity(0)
  185. if self.node then
  186. self.node:addChild(nodeImage)
  187. else
  188. app.mainScene:addChild(nodeImage)
  189. end
  190. --激光枪
  191. local cache = cc.SpriteFrameCache:getInstance()
  192. local spriteFrame = cache:getSpriteFrameByName("item10_1.png");
  193. if tolua.isnull(spriteFrame) then
  194. print("spriteFrame is not in cache")
  195. nodeImage:removeFromParent()
  196. return
  197. end
  198. nodeImage:loadTexture("item10_1.png",cc.TextureResType.plistType)
  199. local qiangSize = nodeImage:getContentSize()
  200. nodeImage:runAction(cc.Sequence:create(cc.FadeIn:create(0.1),cc.CallFunc:create(function ()
  201. local musicFilePath = string.format("res/sound/room/prop_ogg/item%d.ogg",propID)
  202. local soundID = playVoice(musicFilePath)
  203. local indexFace = 0;
  204. local lunshu = 1
  205. --每隔多少秒切换一张图片
  206. local everyFrame = 0.15
  207. local seq = cc.Sequence:create(cc.DelayTime:create(everyFrame),cc.CallFunc:create(function ()
  208. indexFace = indexFace + 1
  209. if 0 < indexFace and indexFace <= 4 then
  210. local name = string.format("item%d_%d.png",propID,indexFace)
  211. if not tolua.isnull(nodeImage) then
  212. nodeImage:loadTexture(name, cc.TextureResType.plistType)
  213. end
  214. elseif indexFace > 4 and lunshu < 2 then
  215. indexFace = 0
  216. lunshu = lunshu + 1
  217. else
  218. nodeImage:removeFromParent()
  219. stopVoice(soundID)
  220. end
  221. end))
  222. local act = cc.Repeat:create(seq,8 + 5)
  223. nodeImage:runAction(act)
  224. end)))
  225. local disX = math.abs(endPos.x - beginPos.x)
  226. local disY = math.abs(endPos.y - beginPos.y)
  227. local angle = math.deg(math.atan(disY/disX)) --第一象限
  228. if endPos.y - beginPos.y >= 0 and endPos.x <= beginPos.x then --第二象限
  229. angle = 180 - angle
  230. elseif endPos.y <= beginPos.y and endPos.x <= beginPos.x then --第三象限
  231. angle = 180 + angle
  232. elseif endPos.y <= beginPos.y and endPos.x >= beginPos.x then --第四象限
  233. angle = -1 * angle
  234. end
  235. nodeImage:setEulerRotation(cc.vec3(0,0,angle + 180))
  236. --散落的子弹动画
  237. local nodeBulletImage = cc.ImageView:createNode()
  238. nodeBulletImage:loadTexture(string.format("res/ui/zy_tongyong/zy_prop/item%d/item%d_fly-i6p.png",propID,propID))
  239. nodeImage:addChild(nodeBulletImage)
  240. local sizeDown = nodeBulletImage:getContentSize()
  241. --nodeBulletImage:setPosition(beginPos)
  242. nodeBulletImage:setPosition(cc.p(0 + 25 * sizeDown.width,qiangSize.height/2))
  243. nodeBulletImage:setOpacity(0)
  244. nodeBulletImage:setFlippedX(true)
  245. local cache = cc.SpriteFrameCache:getInstance()
  246. local spriteFrame = cache:getSpriteFrameByName("item10_danke_1.png");
  247. if tolua.isnull(spriteFrame) then
  248. print("spriteFrame is not in cache")
  249. nodeBulletImage:removeFromParent()
  250. return
  251. end
  252. nodeBulletImage:loadTexture("item10_danke_1.png",cc.TextureResType.plistType)
  253. nodeBulletImage:runAction(cc.Sequence:create(cc.FadeIn:create(0.1),cc.CallFunc:create(function ()
  254. local indexFace = 0;
  255. local lunshu = 1
  256. --每隔多少秒切换一张图片
  257. local everyFrame = 0.15
  258. local seq = cc.Sequence:create(cc.DelayTime:create(everyFrame),cc.CallFunc:create(function ()
  259. indexFace = indexFace + 1
  260. if 0 < indexFace and indexFace <= 3 then
  261. local name = string.format("item%d_danke_%d.png",propID,indexFace)
  262. if not tolua.isnull(nodeBulletImage) then
  263. nodeBulletImage:loadTexture(name, cc.TextureResType.plistType)
  264. end
  265. elseif indexFace > 3 and lunshu < 2 then
  266. indexFace = 0
  267. lunshu = lunshu + 1
  268. else
  269. nodeBulletImage:removeFromParent()
  270. stopVoice(soundID)
  271. end
  272. end))
  273. local act = cc.Repeat:create(seq,6 + 5)
  274. nodeBulletImage:runAction(act)
  275. end)))
  276. --电火花
  277. local nodeBowImage = cc.ImageView:createNode()
  278. nodeBowImage:loadTexture(string.format("res/ui/zy_tongyong/zy_prop/item%d/item%d_fly-i6p.png",propID,propID))
  279. nodeImage:addChild(nodeBowImage)
  280. local sizeBow = nodeBowImage:getContentSize()
  281. --nodeBowImage:setPosition(beginPos)
  282. local y = math.random(-18,18)
  283. nodeBowImage:setPosition(cc.p(0 - sizeBow.width/2,qiangSize.height/2))
  284. nodeBowImage:setOpacity(0)
  285. nodeBowImage:setFlippedX(true)
  286. local cache = cc.SpriteFrameCache:getInstance()
  287. local spriteFrame = cache:getSpriteFrameByName("item10_guang_1.png");
  288. if tolua.isnull(spriteFrame) then
  289. print("spriteFrame is not in cache")
  290. nodeBowImage:removeFromParent()
  291. return
  292. end
  293. nodeBowImage:loadTexture("item10_guang_1.png",cc.TextureResType.plistType)
  294. nodeBowImage:runAction(cc.Sequence:create(cc.FadeIn:create(0.1),cc.CallFunc:create(function ()
  295. local indexFace = 0;
  296. local lunshu = 1
  297. --每隔多少秒切换一张图片
  298. local everyFrame = 0.15
  299. local seq = cc.Sequence:create(cc.DelayTime:create(everyFrame),cc.CallFunc:create(function ()
  300. indexFace = indexFace + 1
  301. if 0 < indexFace and indexFace <= 7 then
  302. local name = string.format("item%d_guang_%d.png",propID,indexFace)
  303. if not tolua.isnull(nodeBowImage) then
  304. nodeBowImage:loadTexture(name, cc.TextureResType.plistType)
  305. end
  306. elseif indexFace > 7 and lunshu < 2 then
  307. indexFace = 0
  308. lunshu = lunshu + 1
  309. else
  310. nodeBowImage:removeFromParent()
  311. stopVoice(soundID)
  312. end
  313. end))
  314. local act = cc.Repeat:create(seq,14 + 5)
  315. nodeBowImage:runAction(act)
  316. end)))
  317. --子弹动画
  318. for i = 1,15 do
  319. local bullet = cc.ImageView:createNode()
  320. bullet:loadTexture("res/ui/zy_tongyong/zy_prop/item10/item10_bullet_fly.png")
  321. bullet:setAnchorPoint(cc.p(0.5,0.5))
  322. local size = bullet:getContentSize()
  323. nodeImage:addChild(bullet)
  324. bullet:setPosition(cc.p(0 - size.width/2,qiangSize.height/2))
  325. --目标点
  326. local targetPos = nodeImage:convertToNodeSpace(endPos)
  327. bullet:setOpacity(0)
  328. bullet:runAction(cc.Sequence:create(cc.DelayTime:create(i * 0.1),cc.FadeIn:create(0.1),cc.CallFunc:create(function ()
  329. end),cc.MoveTo:create(0.35,cc.p(targetPos.x,targetPos.y)),cc.RemoveSelf:create(true)))
  330. end
  331. --弹孔动画
  332. --判断纹理是否存在
  333. local name = string.format("item%d_bow_%d.png",10,1)
  334. local cache = cc.SpriteFrameCache:getInstance()
  335. local spriteFrame = cache:getSpriteFrameByName(name);
  336. if tolua.isnull(spriteFrame) then
  337. print("spriteFrame is not in cache")
  338. return
  339. end
  340. local bulletHole = cc.ImageView:createNode()
  341. bulletHole:loadTexture(string.format("res/ui/zy_tongyong/zy_prop/item%d/item%d_fly-i6p.png",10,10))
  342. if self.node then
  343. self.node:addChild(bulletHole)
  344. else
  345. app.mainScene:addChild(bulletHole)
  346. end
  347. --node:addChild(bulletHole)
  348. bulletHole:setPosition(endPos)
  349. bulletHole:setOpacity(0)
  350. bulletHole:runAction(cc.Sequence:create(cc.FadeIn:create(0.1),cc.CallFunc:create(function ()
  351. local indexFace = 0;
  352. --每隔多少秒切换一张图片
  353. local everyFrame
  354. everyFrame = 0.1
  355. local seq = cc.Sequence:create(cc.DelayTime:create(everyFrame),cc.CallFunc:create(function ()
  356. indexFace = indexFace + 1
  357. if 0 < indexFace and indexFace <= 13 then
  358. local name = string.format("item%d_bow_%d.png",10,indexFace)
  359. if not tolua.isnull(bulletHole) then
  360. bulletHole:loadTexture(name, cc.TextureResType.plistType)
  361. end
  362. else
  363. bulletHole:runAction(cc.Sequence:create(cc.DelayTime:create(1.0),cc.CallFunc:create(function ()
  364. bulletHole:removeFromParent()
  365. end)))
  366. end
  367. end))
  368. local act = cc.Repeat:create(seq,13 + 2)
  369. bulletHole:runAction(act)
  370. end)))
  371. end
  372. return PropAniPlayer