QueueEngine.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. var QueueEngine = cc.Class({
  2. extends: cc.Component,
  3. ctor () {
  4. this.List = new Array();
  5. this.Action = cc.director.getActionManager();
  6. },
  7. _QueneType : function () {
  8. var Obj = new Object();
  9. Obj.func = null;
  10. Obj.pra = null;
  11. Obj.delay = 0;
  12. Obj.end = null;
  13. return Obj;
  14. },
  15. onLoad () {
  16. },
  17. start () {
  18. },
  19. //delay 为空 && fun 返回值为空时 延迟时间为0s
  20. //delay 不为空, 时间以delay为准
  21. //delay 为空时, fun 返回值为空时, 时间以fun 返回值为准
  22. push : function (fun, pra, delay) {
  23. console.log('push start')
  24. var Obj = this._QueneType();
  25. Obj.func = fun;
  26. Obj.pra = deepClone(pra);
  27. Obj.delay = delay;
  28. Obj.end = null;
  29. this.List.push(Obj);
  30. if (this.List.length == 1) {
  31. console.log('push');
  32. this._run();
  33. }
  34. console.log('push end')
  35. },
  36. _run : function () {
  37. console.log('_run start');
  38. var Obj = this.List[0];
  39. if (Obj == null) return;
  40. var delay = Obj.func(Obj.pra);
  41. if (delay != null && null == Obj.delay) {
  42. Obj.delay = delay;
  43. }
  44. if (null == Obj.delay) Obj.delay = 0;
  45. this.scheduleOnce(function () {
  46. this.List.shift();
  47. console.log('callFunc ' + this.List.length);
  48. if (this.List.length > 0) {
  49. console.log('this._run');
  50. this._run();
  51. }
  52. }.bind(this), Obj.delay);
  53. // var action = cc.sequence(cc.delayTime(Obj.delay), cc.callFunc(function(){
  54. // this.List.shift();
  55. // console.log('callFunc ' + this.List.length);
  56. // if (this.List.length > 0) {
  57. // console.log('this._run');
  58. // this._run();
  59. // }
  60. // },this));
  61. // this.Action.addAction(action, this, false);
  62. console.log('_run end');
  63. },
  64. clean : function () {
  65. this.List = new Array();
  66. },
  67. // update (dt) {},
  68. });