XProcess.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
  7. const { ccclass, property } = cc._decorator;
  8. @ccclass
  9. export default class XProcess extends cc.Component {
  10. @property(cc.Node)
  11. process: cc.Node = null;
  12. @property(cc.Label)
  13. processLabel: cc.Label = null;
  14. private ProcessWidth: number = 0;
  15. onLoad() {
  16. this.ProcessWidth = this.node.width;
  17. }
  18. public showProcessLabel() {
  19. if (!this.processLabel.node.activeInHierarchy)
  20. this.processLabel.node.active = true;
  21. }
  22. public setProcess(processNum: number, processstr: string = "0/0") {
  23. this.processLabel.string = processstr;
  24. if (processNum > 1)
  25. processNum = 1;
  26. this.process.width = this.node.width * processNum;
  27. }
  28. start() {
  29. }
  30. // update (dt) {}
  31. }