cc.Class({ extends: cc.Component, properties: { //-- 滚动的速度 speed: 0, //-- X轴边缘 resetX: 0, isFollowPlayerState:false, notAffectedBySpeed:false, coefficientOfVelocity:1, }, start(){ this.speed = -GlobalData.game.GameSpeed*this.coefficientOfVelocity; }, update (dt) { if (GlobalData.game.state !== GlobalData.GameManager.State.Run) { return; } if(this.isFollowPlayerState&&GlobalData.game.PlayerState == GlobalData.GameManager.PlayerState.Stop){ return; } if(!this.notAffectedBySpeed){ this.speed = -GlobalData.game.GameSpeed*this.coefficientOfVelocity; } var x = this.node.x; x += this.speed * dt; if (x <= this.resetX) { x -= this.resetX; } this.node.x = x; } });