gameActorEffect.lua 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. local gameActor = require("actor/gameActor")
  2. local gameActorEffect = class('gameActorEffect', gameActor)
  3. function gameActorEffect:ctor()
  4. gameActorEffect.super.ctor(self)
  5. end
  6. function gameActorEffect:init()
  7. gameActorEffect.super.init(self)
  8. self.mClothID = nil
  9. self.mIsLoop = true
  10. self.mEffectType = 0
  11. self.stopFrameIndex = 0
  12. self.mFeatureDirty = false
  13. self.mDuranceID = nil
  14. end
  15. function gameActorEffect:destory()
  16. gameActorEffect.super.destory(self)
  17. end
  18. function gameActorEffect:Tick(dt)
  19. if self.mFeatureDirty then
  20. self.mFeatureDirty = false
  21. self:checkFeature()
  22. end
  23. end
  24. function gameActorEffect:setPosition(x, y)
  25. local offset = global.MMO.EFFECT_AVATAR_OFFSET
  26. x = x + offset.x
  27. y = y + offset.y
  28. gameActorEffect.super.setPosition(self, x, y)
  29. -- refresh zOrder
  30. self:GetNode():setLocalZOrder(math.floor(-y))
  31. end
  32. function gameActorEffect:setRotation(angle)
  33. self:GetNode():setRotation(angle)
  34. end
  35. function gameActorEffect:SetAction(newAction, isTerminate)
  36. self:updateAnimation()
  37. end
  38. function gameActorEffect:GetAnimationID()
  39. if self.mAnimation then
  40. return self.mAnimation:GetID()
  41. else
  42. return -1
  43. end
  44. end
  45. function gameActorEffect:InitParam(param)
  46. self.mCurrActorNode = cc.Node:create()
  47. self.mClothID = param.sfxId
  48. self.mIsLoop = param.isLoop
  49. self.mEffectType = param.type
  50. self.stopFrameIndex = param.param
  51. self.mDuranceID = param.DuranceID
  52. return 1
  53. end
  54. function gameActorEffect:dirtyFeature()
  55. self.mFeatureDirty = true
  56. end
  57. function gameActorEffect:checkFeature()
  58. if (self.mAnimation) then
  59. self.mAnimation:removeFromParent()
  60. self.mAnimation = nil
  61. end
  62. self.mAnimation = global.FrameAnimManager:CreateSFXAnim(self.mClothID)
  63. self.mAnimation:SetGlobalElapseEnable(self.mEffectType ~= global.MMO.EFFECT_TYPE_SFX and self.mIsLoop == true)
  64. self.mCurrActorNode:addChild(self.mAnimation)
  65. self:updateAnimation()
  66. end
  67. function gameActorEffect:updateAnimation()
  68. if self.mAnimation then
  69. self.mAnimation:Play(0, 0, self.mIsLoop)
  70. if self.stopFrameIndex and self.stopFrameIndex > 0 then
  71. self.mAnimation:Stop(self.stopFrameIndex, 0, 0)
  72. end
  73. end
  74. end
  75. function gameActorEffect:GetType()
  76. return global.MMO.ACTOR_SEFFECT
  77. end
  78. function gameActorEffect:GetAnimation()
  79. return self.mAnimation
  80. end
  81. function gameActorEffect:GetEffectType()
  82. return self.mEffectType
  83. end
  84. function gameActorEffect:GetDuranceID()
  85. return self.mDuranceID
  86. end
  87. return gameActorEffect