// Learn cc.Class: // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html // Learn Attribute: // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html cc.Class({ extends: cc.Component, properties: { SpeedLabel: { default: null, type: cc.Label, }, Perfect: { default: null, type: cc.Node, }, //跳远 扔标枪 的计数板 UIDistanceNum: { default: null, type: cc.Node }, //显示分数 UIScore: { default: null, type: cc.Label }, //游戏结束ui GameOverUIScore: { default: null, type: cc.Label } }, // LIFE-CYCLE CALLBACKS: onLoad() { this.PerfectAnimation = this.Perfect.getComponent(cc.Animation); this.DistanceLabel = this.UIDistanceNum.getComponent(cc.Label); this.distance = 0; this.distanceCount = 0; this.timer = 0; }, start() { }, update(dt) { this.SpeedLabel.string = GlobalData.game.GameSpeed.toFixed(2); if (this.isFinish) { this.onComputUIDistance(dt); } if (this.UIScore) { this.UIScore.string = GlobalData.game.GameScore; } if (this.GameOverUIScore && this.GameOverUIScore.node.parent.parent.active) { this.GameOverUIScore.string = GlobalData.game.GameScore; } }, //完美提示 OnPayPerfectAnimation() { this.PerfectAnimation.play(); }, //显示当前跳远和标枪的距离UI onStartShowUIDistance(InputDistance, InputTime) { this.DistanceLabel.node.parent.active = true; this.distance = 0; this.distanceCount = InputDistance; this.timer = InputTime; this.isFinish = true; this.DistanceLabel.string = "0.00M"; // console.log('CSpeed1=', this.distanceCount, InputDistance, InputTime,this.timer); }, //计算当前UI距离 onComputUIDistance(dt) { var ADistance = this.distanceCount; var CDistance = this.distance; var speedFactor = (ADistance - CDistance) * 0.05; CDistance += speedFactor; this.timer -= dt;//timer =0.3 // console.log(this.timer); if (this.timer <= 0 && CDistance - ADistance >= -0.1) { this.isFinish = false; CDistance = ADistance; setTimeout(() => { this.DistanceLabel.node.parent.active = false; }, 1500); } this.distance = CDistance; // console.log('CSpeed2=', CDistance, ADistance); this.DistanceLabel.string = CDistance.toFixed(2) + "M"; }, });