action.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * @author uu
  3. * @file 所有的简单动作集合
  4. */
  5. // 震动动作 0.1效果比较好
  6. function shackAction(time, range) {
  7. let action1 = cc.moveBy(time, range, range)
  8. let action2 = cc.moveBy(time, -range, -range)
  9. let action3 = cc.moveBy(time * 0.8, range * 0.8, range * 0.8)
  10. let action4 = cc.moveBy(time * 0.8, -range * 0.8, -range * 0.8)
  11. let action5 = cc.moveBy(time * 0.6, range * 0.6, range * 0.6)
  12. let action6 = cc.moveBy(time * 0.6, -range * 0.6, -range * 0.6)
  13. let action7 = cc.moveBy(time * 0.4, range * 0.4, range * 0.4)
  14. let action8 = cc.moveBy(time * 0.4, -range * 0.4, -range * 0.4)
  15. let action9 = cc.moveBy(time * 0.2, range * 0.2, range * 0.2)
  16. let action10 = cc.moveBy(time * 0.2, -range * 0.2, -range * 0.2)
  17. let sq = cc.sequence(action1, action2, action3, action4, action5, action6, action7, action8, action9, action10)
  18. return sq
  19. }
  20. // 晃动动作
  21. function rockAction(time, range) {
  22. let action1 = cc.rotateBy(time, range, range)
  23. let action2 = cc.rotateBy(time, -2 * range, -2 * range)
  24. let action3 = cc.rotateBy(time * 0.8, 2 * range * 0.8, 2 * range * 0.8)
  25. let action6 = cc.rotateBy(time * 0.6, -2 * range * 0.6, -2 * range * 0.6)
  26. let action7 = cc.rotateBy(time * 0.4, 2 * range * 0.4, 2 * range * 0.4)
  27. let action10 = cc.rotateTo(time * 0.2, 0, 0)
  28. let sq = cc.sequence(action1, action2, action3, action6, action7, action10)
  29. return sq
  30. }
  31. // 弹出效果
  32. function popOut(time) {
  33. return cc.scaleTo(time, 1).easing(cc.easeBackOut(2.0))
  34. }
  35. // 收入效果
  36. function popIn(time) {
  37. return cc.scaleTo(time, 0.5).easing(cc.easeBackIn(2.0))
  38. }
  39. function heartBeat() {
  40. let action1 = cc.scaleTo(0.2, 1.2).easing(cc.easeElasticInOut())
  41. let action2 = cc.scaleTo(0.2, 1).easing(cc.easeElasticInOut())
  42. let action3 = cc.rotateTo(0.1, 45)
  43. let action4 = cc.rotateTo(0.2, -45)
  44. let action5 = cc.rotateTo(0.1, 0)
  45. }
  46. //翻页效果 前两个传node type传数字 左右旋转的
  47. function pageTurning(pageUp, pageDown, typeA) {
  48. switch (typeA) {
  49. case 0:
  50. pageUp.runAction(cc.fadeOut(0.6));
  51. pageDown.runAction(cc.delayTime(0.6), cc.fadeIn(0.6), cc.sequence(cc.callFunc(() => {
  52. pageUp.active = false;
  53. }, this, pageUp)));
  54. break;
  55. case 1:
  56. pageDown.scaleX = 0;
  57. pageUp.runAction(cc.scaleTo(0.6, 0, 1))
  58. pageDown.runAction(cc.sequence(cc.delayTime(0.6), cc.callFunc(() => {
  59. pageUp.active = false;
  60. }, this, pageUp), cc.scaleTo(0.6, 1, 1), ))
  61. break;
  62. case 2:
  63. break;
  64. }
  65. }
  66. //移动到屏幕外 并且隐藏 0123 上右下左 会移动一个屏幕的距离 然后直接消失
  67. function getMoveOutofScreenActive(typeA, winWidth, winHeight, delTime) {
  68. switch (typeA) {
  69. case 0:
  70. return cc.moveBy(delTime, 0, winHeight)
  71. case 1:
  72. return cc.moveBy(delTime, winWidth, 0)
  73. case 2:
  74. return cc.moveBy(delTime, 0, -winHeight)
  75. case 3:
  76. return cc.moveBy(delTime, -winWidth, 0)
  77. }
  78. }
  79. //从屏幕外进入 上右下左
  80. function getMoveInScreenActive(typeA, winWidth, winHeight, delTime) {
  81. switch (typeA) {
  82. case 0:
  83. return cc.moveBy(delTime, 0, -winHeight)
  84. case 1:
  85. return cc.moveBy(delTime, -winWidth, 0)
  86. case 2:
  87. return cc.moveBy(delTime, 0, winHeight)
  88. case 3:
  89. return cc.moveBy(delTime, winWidth, 0)
  90. }
  91. }
  92. //闪烁动作
  93. function blinkAction(delTime) {
  94. return cc.repeatForever(cc.sequence(cc.fadeOut(delTime), cc.fadeIn(delTime)))
  95. }
  96. module.exports = {
  97. shackAction: shackAction,
  98. blinkAction: blinkAction,
  99. pageTurning: pageTurning,
  100. heartBeat: heartBeat,
  101. getMoveOutofScreenActive: getMoveOutofScreenActive,
  102. popOut: popOut,
  103. popIn: popIn,
  104. getMoveInScreenActive: getMoveInScreenActive,
  105. rockAction: rockAction
  106. }