Scroller.js 912 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. //-- 滚动的速度
  5. speed: 0,
  6. //-- X轴边缘
  7. resetX: 0,
  8. isFollowPlayerState:false,
  9. notAffectedBySpeed:false,
  10. coefficientOfVelocity:1,
  11. },
  12. start(){
  13. this.speed = -GlobalData.game.GameSpeed*this.coefficientOfVelocity;
  14. },
  15. update (dt) {
  16. if (GlobalData.game.state !== GlobalData.GameManager.State.Run) {
  17. return;
  18. }
  19. if(this.isFollowPlayerState&&GlobalData.game.PlayerState == GlobalData.GameManager.PlayerState.Stop){
  20. return;
  21. }
  22. if(!this.notAffectedBySpeed){
  23. this.speed = -GlobalData.game.GameSpeed*this.coefficientOfVelocity;
  24. }
  25. var x = this.node.x;
  26. x += this.speed * dt;
  27. if (x <= this.resetX) {
  28. x -= this.resetX;
  29. }
  30. this.node.x = x;
  31. }
  32. });