TickTest.ts 917 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import DateTime from "../scripts/help/DateTime";
  2. const {ccclass, property} = cc._decorator;
  3. @ccclass
  4. export default class TickTest extends cc.Component {
  5. // LIFE-CYCLE CALLBACKS:
  6. // onLoad () {}
  7. public setTimeScale(touch,val){
  8. cc.director.getScheduler().setTimeScale(val);
  9. }
  10. public startTick(){
  11. Ticker.start(new Date().getTime());
  12. }
  13. public stopTick(){
  14. Ticker.stop();
  15. }
  16. public pause(){
  17. Ticker.pause();
  18. }
  19. public repause(){
  20. Ticker.resume();
  21. }
  22. private timerId: string;
  23. public startItv() {
  24. this.removeItv();
  25. this.timerId = Ticker.registerDelay(this.tick.bind(this), 1000);
  26. }
  27. private tick(count:number){
  28. console.log( DateTime.formatDate()+ " tick:"+count)
  29. }
  30. public removeItv() {
  31. Ticker.unregisterDelay(this.timerId);
  32. }
  33. // update (dt) {}
  34. }