Camera.ts 728 B

123456789101112131415161718192021222324
  1. const {ccclass, property} = cc._decorator;
  2. @ccclass
  3. export default class Camera extends cc.Component {
  4. canUpY:number = (1600-cc.winSize.height)/2;
  5. canDownY:number = -(1600-cc.winSize.height)/2;
  6. update(dt:number){
  7. if(!window.gm.isGameOver){
  8. if(window.boy&&window.boy.isValid){
  9. let nextY = window.boy.node.y;
  10. if(nextY>this.canDownY&&nextY<this.canUpY){
  11. this.node.y = nextY;
  12. }else{
  13. if(nextY<0){
  14. this.node.y = this.canDownY;
  15. }else if(nextY>0){
  16. this.node.y = this.canUpY;
  17. }
  18. }
  19. }
  20. }
  21. }
  22. }