animationFrame.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const { ccclass, property } = cc._decorator;
  2. @ccclass
  3. export default class animationFrame extends cc.Component {
  4. private intervalTime: number = 0.01;// _间隔时间: 1,
  5. private currentIntervalTime: number = 0;// 当前间隔时间: 1,
  6. private time: number = 1;// 最小间隔: 1,
  7. private changeIntervalTime: number = 0.01;//切换间隔时间: 0.1,
  8. private flags: boolean = false;
  9. @property([cc.SpriteFrame])
  10. public textureArr: cc.SpriteFrame[] = [];// 动画帧组: [cc.SpriteFrame],
  11. private _index: number = 0;
  12. // LIFE-CYCLE CALLBACKS:
  13. // onLoad () {}
  14. start() {
  15. }
  16. update(dt) {
  17. if (!this.flags) {
  18. this.currentIntervalTime -= dt;
  19. if (this.currentIntervalTime <= 0) {
  20. this.flags = true;
  21. }
  22. } else {
  23. this.time += dt;
  24. if (this.time >= this.changeIntervalTime) {
  25. if (this._index < this.textureArr.length) {
  26. this.node.getComponent(cc.Sprite).spriteFrame = this.textureArr[this._index];
  27. this._index++;
  28. } else {
  29. this._index = 0;
  30. this.currentIntervalTime = this.intervalTime;
  31. this.flags = false;
  32. }
  33. this.time = 0;
  34. }
  35. }
  36. }
  37. }