| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- const {ccclass, property} = cc._decorator;
- @ccclass
- export default class ProgressBar extends cc.Component {
- progressBG:cc.Node;
- selfProgress:cc.Node;
- otherProgress:cc.Node;
- canUpdate:boolean = false;
- onLoad(){
- window.progressBar = this;
- this.progressBG = this.node.getChildByName('ProgressBG');
- this.selfProgress = this.node.getChildByName('SelfProgress');
- this.otherProgress = this.node.getChildByName('OtherProgress');
- this.hide();
- }
- hide(){
- this.node.children.forEach((child)=>{
- child.active = false;
- });
- this.canUpdate = false;
- }
- show(){
- this.node.children.forEach((child)=>{
- child.active = true;
- });
- this.selfProgress.getChildByName('BirdFrame').getComponent(cc.Sprite).spriteFrame = window.gm.birds[window.myPlayerInfo.index].spFlyingFrames[0];
- this.otherProgress.getChildByName('BirdFrame').getComponent(cc.Sprite).spriteFrame = window.gm.birds[window.otherPlayerInfo.index].spFlyingFrames[0];
- this.canUpdate = true;
- }
- update(){
- if(this.canUpdate){
- let leftX = this.progressBG.x+10;
- let selfRate = window.gm.birds[window.myPlayerInfo.index].node.x/window.gc.modeInfo.destination;
- let otherRate = window.gm.birds[window.otherPlayerInfo.index].node.x/window.gc.modeInfo.destination;
- let selfProgressX = selfRate*(this.progressBG.width-20);
- let otherProgressX = otherRate*(this.progressBG.width-20);
- this.selfProgress.x = leftX + selfProgressX;
- this.otherProgress.x = leftX + otherProgressX;
- }
- }
- }
|