TimeProgress.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import {_decorator, Component, Node, UITransform} from 'cc';
  2. const {ccclass, property} = _decorator;
  3. @ccclass('TimeProgress')
  4. export class TimeProgress extends Component {
  5. public maxTime: number = 15
  6. private orignWidth: number = 1200
  7. private step: number = 0
  8. onLoad() {
  9. this.orignWidth = this.node.getChildByName("PMask").getComponent(UITransform).width
  10. // console.log("0000000000= "+this.orignWidth);
  11. }
  12. start() {
  13. }
  14. update(deltaTime: number) {
  15. }
  16. public prepair(maxTime: number = 15) {
  17. this.node.getChildByName("PMask").getComponent(UITransform).width = this.orignWidth
  18. this.maxTime = maxTime
  19. }
  20. public startProgress() {
  21. this.step = this.node.getChildByName("PMask").getComponent(UITransform).width / this.maxTime
  22. this.schedule(this.goProgress, 1, this.maxTime, 0);
  23. }
  24. private goProgress() {
  25. let w = this.node.getChildByName("PMask").getComponent(UITransform).width
  26. w -= this.step
  27. this.node.getChildByName("PMask").getComponent(UITransform).width = w
  28. if (w <= 0) {
  29. }
  30. }
  31. public stopProgress() {
  32. this.unschedule(this.goProgress)
  33. this.node.active = false
  34. }
  35. }