GameAct.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /**
  2. * @author heyuchang
  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. // Helper function to create a rotation tween
  21. const createRotationTween = (duration, xRotation, yRotation) => {
  22. return cc.tween(duration)
  23. .to(cc.Node.prototype.setRotation, {
  24. x: this.node.rotationX + xRotation,
  25. y: this.node.rotationY + yRotation
  26. }, {rotationX: '+=', rotationY: '+='})
  27. .action();
  28. };
  29. // Helper function to create a rotation to zero tween
  30. const createZeroRotationTween = (duration) => {
  31. return cc.tween(duration)
  32. .to(cc.Node.prototype.setRotation, {x: 0, y: 0})
  33. .action();
  34. };
  35. // 晃动动作
  36. function rockAction(time, range) {
  37. let action1 = cc.rotateBy(time, range, range)
  38. let action2 = cc.rotateBy(time, -2 * range, -2 * range)
  39. let action3 = cc.rotateBy(time * 0.8, 2 * range * 0.8, 2 * range * 0.8)
  40. let action6 = cc.rotateBy(time * 0.6, -2 * range * 0.6, -2 * range * 0.6)
  41. let action7 = cc.rotateBy(time * 0.4, 2 * range * 0.4, 2 * range * 0.4)
  42. let action10 = cc.rotateTo(time * 0.2, 0, 0)
  43. let sq = cc.sequence(action1, action2, action3, action6, action7, action10)
  44. return sq
  45. }
  46. // 弹出效果
  47. function popOut(time) {
  48. return cc.scaleTo(time, 1).easing(cc.easeBackOut(2.0))
  49. }
  50. // 收入效果
  51. function popIn(time) {
  52. return cc.scaleTo(time, 0.5).easing(cc.easeBackIn(2.0))
  53. }
  54. function heartBeat() {
  55. let action1 = cc.scaleTo(0.2, 1.2).easing(cc.easeElasticInOut())
  56. let action2 = cc.scaleTo(0.2, 1).easing(cc.easeElasticInOut())
  57. let action3 = cc.rotateTo(0.1, 45)
  58. let action4 = cc.rotateTo(0.2, -45)
  59. let action5 = cc.rotateTo(0.1, 0)
  60. }
  61. //翻页效果 前两个传node type传数字 左右旋转的
  62. function pageTurning(pageUp, pageDown, typeA) {
  63. switch (typeA) {
  64. case 0:
  65. pageUp.runAction(cc.fadeOut(0.6));
  66. pageDown.runAction(cc.delayTime(0.6), cc.fadeIn(0.6), cc.sequence(cc.callFunc(() => {
  67. pageUp.active = false;
  68. }, this, pageUp)));
  69. break;
  70. case 1:
  71. pageDown.scaleX = 0;
  72. pageUp.runAction(cc.scaleTo(0.6, 0, 1))
  73. pageDown.runAction(cc.sequence(cc.delayTime(0.6), cc.callFunc(() => {
  74. pageUp.active = false;
  75. }, this, pageUp), cc.scaleTo(0.6, 1, 1),))
  76. break;
  77. case 2:
  78. break;
  79. }
  80. }
  81. //移动到屏幕外 并且隐藏 0123 上右下左 会移动一个屏幕的距离 然后直接消失
  82. function getMoveOutofScreenActive(typeA, winWidth, winHeight, delTime) {
  83. switch (typeA) {
  84. case 0:
  85. return cc.moveBy(delTime, 0, winHeight)
  86. case 1:
  87. return cc.moveBy(delTime, winWidth, 0)
  88. case 2:
  89. return cc.moveBy(delTime, 0, -winHeight)
  90. case 3:
  91. return cc.moveBy(delTime, -winWidth, 0)
  92. }
  93. }
  94. //从屏幕外进入 上右下左
  95. function getMoveInScreenActive(typeA, winWidth, winHeight, delTime) {
  96. switch (typeA) {
  97. case 0:
  98. return cc.moveBy(delTime, 0, -winHeight)
  99. case 1:
  100. return cc.moveBy(delTime, -winWidth, 0)
  101. case 2:
  102. return cc.moveBy(delTime, 0, winHeight)
  103. case 3:
  104. return cc.moveBy(delTime, winWidth, 0)
  105. }
  106. }
  107. //闪烁动作
  108. function blinkAction(delTime) {
  109. return cc.repeatForever(cc.sequence(cc.fadeOut(delTime), cc.fadeIn(delTime)))
  110. }
  111. module.exports = {
  112. shackAction: shackAction,
  113. blinkAction: blinkAction,
  114. pageTurning: pageTurning,
  115. heartBeat: heartBeat,
  116. getMoveOutofScreenActive: getMoveOutofScreenActive,
  117. popOut: popOut,
  118. popIn: popIn,
  119. getMoveInScreenActive: getMoveInScreenActive,
  120. rockAction: rockAction
  121. }