1
0

BuildingAnimation.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. floors: [cc.Node],
  5. pillars:[cc.Node],
  6. },
  7. // LIFE-CYCLE CALLBACKS:
  8. onLoad () {
  9. // for (var i = 0; i < this.floors.length; i++) {
  10. // this.floors[i].active = false;
  11. // }
  12. // this.upgrade.on('touchend',()=>{
  13. // // this.node.runAction(cc.sequence(cc.scaleTo(0.1,1.1,1.1),cc.scaleTo(0,1,1)));
  14. // this.showJumpAnimation();
  15. // })
  16. // this.node.on('touchend',()=>{
  17. // // this.node.runAction(cc.sequence(cc.scaleTo(0.1,1.1,1.1),cc.scaleTo(0,1,1)));
  18. // this.showUpgradeAnimation();
  19. // })
  20. },
  21. start() {
  22. // this.showUpgradeAnimation(this.floors);
  23. },
  24. showUpgradeAnimation() {
  25. this.floorListAnimation(this.floors);
  26. this.floorListAnimation(this.pillars);
  27. // this.pillarListAnimation();
  28. },
  29. floorListAnimation(floors){
  30. for (var i = 0; i < floors.length; i++) {
  31. floors[i].active = false;
  32. }
  33. let delayDivider = 0.2;
  34. let delayOffset = 0;
  35. let startYOffset = 300;
  36. let yDivider = 20;
  37. this.floorAnimation(floors[0], startYOffset);
  38. for (var i = 1; i < floors.length; i++) {
  39. let floor = floors[i];
  40. this.scheduleOnce(() => {
  41. this.floorAnimation(floor, startYOffset + yDivider * i);
  42. }, delayOffset + delayDivider * i);
  43. }
  44. },
  45. floorAnimation(floor, startY) {
  46. floor.active = true;
  47. floor.y += startY;
  48. // let down = cc.sequence(this.getEaseAnimation(cc.moveBy(0.2,0,startY)),this.getEaseAnimation(cc.moveBy(0.2,0,-startY)));
  49. let down = this.getEaseAnimation(cc.moveBy(0.2, 0, -startY));
  50. let scale1 = this.getEaseAnimation(cc.scaleTo(0.2, 1.1, 1.1));
  51. let scale2 = this.getEaseAnimation(cc.scaleTo(0.2, 1, 1));
  52. floor.runAction(cc.sequence(down, scale1, scale2));
  53. },
  54. pillarListAnimation(){
  55. for (var i = 0; i < this.pillars.length; i++) {
  56. this.pillars[i].active = false;
  57. }
  58. let delayDivider = 0.1;
  59. let delayOffset = 0.2;
  60. let startYOffset = 300;
  61. let yDivider = 0;
  62. let rotateOffset = 20;
  63. let moveXOffset = 0;
  64. for (var i = 0; i < this.pillars.length; i++) {
  65. let item = this.pillars[i];
  66. let startY = startYOffset + yDivider * i;
  67. let rotate = (rotateOffset + Math.random()*20)*(i>0?-1:1);
  68. let moveX = (moveXOffset + Math.random()*10)*(i>1?-1:1);
  69. this.scheduleOnce(() => {
  70. this.pillarAnimation(item, startY,rotate,10);
  71. }, delayOffset + delayDivider * i);
  72. }
  73. },
  74. pillarAnimation(pillar,startY,rotate,moveX){
  75. pillar.active = true;
  76. pillar.y += startY;
  77. // let down = cc.sequence(this.getEaseAnimation(cc.moveBy(0.2,0,startY)),this.getEaseAnimation(cc.moveBy(0.2,0,-startY)));
  78. let down = this.getEaseBackAnimation(cc.moveBy(0.2, 0, -startY));
  79. let rotate1 = this.getEaseBackAnimation(cc.rotateBy(0.2,rotate, rotate));
  80. let rotate2 = this.getEaseBackAnimation(cc.rotateBy(0.2, -rotate, -rotate));
  81. let move1 = this.getEaseAnimation(cc.moveBy(0.2,0,moveX));
  82. let move2 = this.getEaseAnimation(cc.moveBy(0.2,0,-moveX));
  83. let scale1 = this.getEaseBackAnimation(cc.scaleTo(0.2, 1.1, 1.1));
  84. let scale2 = this.getEaseBackAnimation(cc.scaleTo(0.2, 1, 1));
  85. let spawn1 = cc.spawn(rotate1,scale1);
  86. let spawn2 = cc.spawn(rotate2,scale2);
  87. pillar.runAction(cc.sequence(down, spawn1, spawn2));
  88. },
  89. getEaseAnimation(action) {
  90. return action.easing(cc.easeQuadraticActionInOut());
  91. // return action;
  92. },
  93. getEaseBackAnimation(action){
  94. return action.easing(cc.easeBackInOut(2));
  95. },
  96. showJumpAnimation() {
  97. for (var i = 0; i < this.floors.length; i++) {
  98. let floor = this.floors[i];
  99. this.scheduleOnce(() => {
  100. this.floorAnimation(floor, startYOffset + yDivider * i);
  101. }, delayOffset + delayDivider * i);
  102. }
  103. for (var i = 0; i < this.pillars.length; i++) {
  104. let item = this.pillars[i];
  105. let startY = startYOffset + yDivider * i;
  106. let rotate = (rotateOffset + Math.random()*20)*(i>0?-1:1);
  107. let moveX = (moveXOffset + Math.random()*10)*(i>1?-1:1);
  108. this.scheduleOnce(() => {
  109. this.pillarAnimation(item, startY,rotate,10);
  110. }, delayOffset + delayDivider * i);
  111. }
  112. }
  113. // update (dt) {},
  114. });