easing.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // Learn cc.Class:
  2. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. offsetReduceSpeed : 20,
  14. offsetIncreaseSpeed : 10,
  15. player: {
  16. // ATTRIBUTES:
  17. default: null, // The default value will be used only when the component attaching
  18. // to a node for the first time
  19. type: cc.Node, // optional, default is typeof default
  20. serializable: true, // optional, default is true
  21. },
  22. // bar: {
  23. // get () {
  24. // return this._bar;
  25. // },
  26. // set (value) {
  27. // this._bar = value;
  28. // }
  29. // },
  30. },
  31. // LIFE-CYCLE CALLBACKS:
  32. onLoad : function() {
  33. // this.startDamp(500,5,200,600,8);
  34. },
  35. // start () {
  36. //
  37. // },
  38. // update: function (dt) {
  39. //
  40. // },
  41. startDamp : function (speedMax,speedMaxtime,speedMin,speedMaxtoo,speedMaxtimetoo) {
  42. this.speedMax = speedMax;
  43. this.speedMaxtime = speedMaxtime;
  44. this.speedMin = speedMin;
  45. // this.speedMintime = speedMintime;
  46. this.speedMaxtoo = speedMaxtoo;
  47. this.speedMaxtimetoo = speedMaxtimetoo;
  48. // cc.log("这俩毁掉的状况 0", this.callTime ,this.callTimetoo);
  49. if (this.callTime != null) {
  50. this.unschedule(this.callTime);
  51. }else if (this.callTimetoo != null) {
  52. this.unschedule(this.callTimetoo);
  53. }
  54. // cc.log("减速轨迹 开始");
  55. this.reduce();
  56. // this.increase();
  57. },
  58. //减少
  59. reduce : function () {
  60. var s1 = this.speedMax;
  61. var s2 = this.speedMin;
  62. // cc.log("这俩毁掉的状况 1", this.callTime ,this.callTimetoo);
  63. this.callTime = function () {
  64. s1-=this.offsetReduceSpeed;
  65. // cc.log("轨迹 减速",s1);
  66. this.reduceListnener(s1);
  67. if (s1 <= s2) {
  68. // 在第六次执行回调时取消这个计时器
  69. this.unschedule(this.callTime);
  70. this.callTime = null;
  71. this.increase();
  72. }
  73. }.bind(this);
  74. this.schedule(this.callTime, this.speedMaxtime/100);
  75. },
  76. reduceListnener : function () {
  77. },
  78. setreduceListnener : function (reduceListnener) {
  79. this.reduceListnener = reduceListnener;
  80. },
  81. //增加
  82. increase : function () {
  83. var s1 = this.speedMin;
  84. var s2 = this.speedMaxtoo;
  85. // cc.log("这俩毁掉的状况 2", this.callTime ,this.callTimetoo);
  86. this.callTimetoo = function () {
  87. s1+=this.offsetIncreaseSpeed;
  88. this.increaseListnener(s1);
  89. // cc.log("轨迹 加速",s1);
  90. if (s1 >= s2) {
  91. // 在第六次执行回调时取消这个计时器
  92. this.unschedule(this.callTimetoo);
  93. this.callTimetoo = null;
  94. this.handleCallBack();
  95. }
  96. }.bind(this);
  97. this.schedule(this.callTimetoo, this.speedMaxtimetoo/100);
  98. },
  99. increaseListnener : function () {
  100. },
  101. setincreaseListnener : function (increaseListnener) {
  102. this.increaseListnener = increaseListnener;
  103. },
  104. handleCallBack : function () {
  105. // this.player.getComponent()
  106. },
  107. sethandleCallBack : function (handleCallBack) {
  108. this.handleCallBack = handleCallBack;
  109. },
  110. });