ProgressBar.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. const {ccclass, property} = cc._decorator;
  2. @ccclass
  3. export default class ProgressBar extends cc.Component {
  4. progressBG:cc.Node;
  5. selfProgress:cc.Node;
  6. otherProgress:cc.Node;
  7. canUpdate:boolean = false;
  8. onLoad(){
  9. window.progressBar = this;
  10. this.progressBG = this.node.getChildByName('ProgressBG');
  11. this.selfProgress = this.node.getChildByName('SelfProgress');
  12. this.otherProgress = this.node.getChildByName('OtherProgress');
  13. this.hide();
  14. }
  15. hide(){
  16. this.node.children.forEach((child)=>{
  17. child.active = false;
  18. });
  19. this.canUpdate = false;
  20. }
  21. show(){
  22. this.node.children.forEach((child)=>{
  23. child.active = true;
  24. });
  25. this.selfProgress.getChildByName('BirdFrame').getComponent(cc.Sprite).spriteFrame = window.gm.birds[window.myPlayerInfo.index].spFlyingFrames[0];
  26. this.otherProgress.getChildByName('BirdFrame').getComponent(cc.Sprite).spriteFrame = window.gm.birds[window.otherPlayerInfo.index].spFlyingFrames[0];
  27. this.canUpdate = true;
  28. }
  29. update(){
  30. if(this.canUpdate){
  31. let leftX = this.progressBG.x+10;
  32. let selfRate = window.gm.birds[window.myPlayerInfo.index].node.x/window.gc.modeInfo.destination;
  33. let otherRate = window.gm.birds[window.otherPlayerInfo.index].node.x/window.gc.modeInfo.destination;
  34. let selfProgressX = selfRate*(this.progressBG.width-20);
  35. let otherProgressX = otherRate*(this.progressBG.width-20);
  36. this.selfProgress.x = leftX + selfProgressX;
  37. this.otherProgress.x = leftX + otherProgressX;
  38. }
  39. }
  40. }