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. startDamp : function (speedMax,speedMaxtime,speedMin,speedMaxtoo,speedMaxtimetoo) {
  41. this.speedMax = speedMax;
  42. this.speedMaxtime = speedMaxtime;
  43. this.speedMin = speedMin;
  44. // this.speedMintime = speedMintime;
  45. this.speedMaxtoo = speedMaxtoo;
  46. this.speedMaxtimetoo = speedMaxtimetoo;
  47. // cc.log("这俩毁掉的状况 0", this.callTime ,this.callTimetoo);
  48. if (this.callTime != null) {
  49. this.unschedule(this.callTime);
  50. }else if (this.callTimetoo != null) {
  51. this.unschedule(this.callTimetoo);
  52. }
  53. // cc.log("减速轨迹 开始");
  54. this.reduce();
  55. // this.increase();
  56. },
  57. //减少
  58. reduce : function () {
  59. var s1 = this.speedMax;
  60. var s2 = this.speedMin;
  61. // cc.log("这俩毁掉的状况 1", this.callTime ,this.callTimetoo);
  62. this.callTime = function () {
  63. s1-=this.offsetReduceSpeed;
  64. // cc.log("轨迹 减速",s1);
  65. this.reduceListnener(s1);
  66. if (s1 <= s2) {
  67. // 在第六次执行回调时取消这个计时器
  68. this.unschedule(this.callTime);
  69. this.callTime = null;
  70. this.increase();
  71. }
  72. }.bind(this);
  73. this.schedule(this.callTime, this.speedMaxtime/100);
  74. },
  75. reduceListnener : function () {
  76. },
  77. setreduceListnener : function (reduceListnener) {
  78. this.reduceListnener = reduceListnener;
  79. },
  80. //增加
  81. increase : function () {
  82. var s1 = this.speedMin;
  83. var s2 = this.speedMaxtoo;
  84. // cc.log("这俩毁掉的状况 2", this.callTime ,this.callTimetoo);
  85. this.callTimetoo = function () {
  86. s1+=this.offsetIncreaseSpeed;
  87. this.increaseListnener(s1);
  88. // cc.log("轨迹 加速",s1);
  89. if (s1 >= s2) {
  90. // 在第六次执行回调时取消这个计时器
  91. this.unschedule(this.callTimetoo);
  92. this.callTimetoo = null;
  93. this.handleCallBack();
  94. }
  95. }.bind(this);
  96. this.schedule(this.callTimetoo, this.speedMaxtimetoo/100);
  97. },
  98. increaseListnener : function () {
  99. },
  100. setincreaseListnener : function (increaseListnener) {
  101. this.increaseListnener = increaseListnener;
  102. },
  103. handleCallBack : function () {
  104. // this.player.getComponent()
  105. },
  106. sethandleCallBack : function (handleCallBack) {
  107. this.handleCallBack = handleCallBack;
  108. },
  109. });