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.

95 lines
3.1 KiB

  1. local yibinmajiangGameStartAnimation = class("yibinmajiangGameStartAnimation", cc.UIView);
  2. function yibinmajiangGameStartAnimation:ctor ()
  3. self:initViews();
  4. end
  5. function yibinmajiangGameStartAnimation:initViews ()
  6. if self.imgText then
  7. self.imgText:removeFromParent();
  8. end
  9. if self.imgBg then
  10. self.imgBg:removeFromParent();
  11. end
  12. local visibleSize = cc.Director:getInstance():getVisibleSize();
  13. local imgBg = cc.Sprite:create();
  14. imgBg:setTexture("mj_yibinmajiang/res/zy_fangjian/anim/gamestart/yibinmajiang_bg_gamestart.png");
  15. imgBg:setPosition(cc.p(visibleSize.width / 6, visibleSize.height / 2));
  16. imgBg:setOpacity(0);
  17. self:addChild(imgBg);
  18. self.imgBg = imgBg;
  19. local imgText = cc.Sprite:create();
  20. imgText:setTexture("mj_yibinmajiang/res/zy_fangjian/anim/gamestart/yibinmajiang_img_gamestart.png");
  21. imgText:setPosition(cc.p(visibleSize.width * 5 / 6, visibleSize.height / 2));
  22. imgBg:setOpacity(0);
  23. self:addChild(imgText);
  24. self.imgText = imgText;
  25. end
  26. function yibinmajiangGameStartAnimation:play ()
  27. if not (self.imgBg and self.imgText) then
  28. return ;
  29. end
  30. local acMove1 = self:createMoveAction();
  31. local acMove2 = self:createMoveAction();
  32. local acMoveCallback = cc.CallFunc:create(handler(self, self.onMoveFinished));
  33. local acDelay = cc.DelayTime:create(0.7);
  34. local acCallback = cc.CallFunc:create(handler(self, self.onPlayAnimFinished));
  35. local acSeq = cc.Sequence:create(acMove2, acMoveCallback, acDelay, acCallback);
  36. self.imgBg:runAction(acMove1);
  37. self.imgText:runAction(acSeq);
  38. end
  39. function yibinmajiangGameStartAnimation:createMoveAction ()
  40. local visibleSize = cc.Director:getInstance():getVisibleSize();
  41. local acMoveTo = cc.MoveTo:create(0.5, cc.p(visibleSize.width / 2, visibleSize.height / 2));
  42. local acFadeIn = cc.FadeIn:create(0.5);
  43. local acSpawn = cc.Spawn:create(acMoveTo, acFadeIn);
  44. return acSpawn;
  45. end
  46. --- yibinmajiangGameStartAnimation:onMoveFinished 移动完成动画
  47. function yibinmajiangGameStartAnimation:onMoveFinished ()
  48. -- 移动完成,可能要显示繁星点点
  49. if not self.imgText then
  50. return ;
  51. end
  52. local size = self.imgText:getContentSize();
  53. math.randomseed(tostring(os.time()):reverse():sub(1, 6))
  54. function createStar ()
  55. local x = math.random(size.width * 3 /4);
  56. local y = math.random(size.height * 3 / 4);
  57. local sprite = cc.Sprite:create("mj_yibinmajiang/res/zy_fangjian/anim/gamestart/yibinmajiang_img_star1.png");
  58. sprite:setPosition(cc.p(x, y));
  59. sprite:setScale(math.random(15, 25) * 0.1);
  60. self.imgText:addChild(sprite);
  61. local acRotate = cc.RotateTo:create(0.5, 360);
  62. local acFadeIn = cc.FadeIn:create(0.5);
  63. local acFadeOut = cc.FadeOut:create(0.5);
  64. local acSeq = cc.Sequence:create(acFadeIn, acFadeOut);
  65. local acSpawn = cc.Spawn:create(acRotate, acSeq);
  66. local acRepeat = cc.RepeatForever:create(acSpawn);
  67. sprite:runAction(acRepeat);
  68. end
  69. for i = 1, 6 do
  70. createStar();
  71. end
  72. end
  73. function yibinmajiangGameStartAnimation:onPlayAnimFinished( )
  74. self:stop();
  75. end
  76. function yibinmajiangGameStartAnimation:stop ()
  77. self:setVisible(false);
  78. self:removeFromParent();
  79. self = nil;
  80. end
  81. return yibinmajiangGameStartAnimation;