LoginScene.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { _decorator, Button, Component, Node,director ,tween, Vec3} from 'cc';
  2. const { ccclass, property } = _decorator;
  3. @ccclass('NewComponent')
  4. export class NewComponent extends Component {
  5. @property(Node)
  6. bird:Node=null;
  7. @property(Node)
  8. carrot:Node=null;
  9. start() {
  10. let btnLogin = this.node.getChildByName("Button")
  11. btnLogin.on(Button.EventType.CLICK,this.onBtnLogin,this)
  12. this.carrot.setScale(0.5,0.5);
  13. this.birdAnimation();
  14. this.carrotAnimation();
  15. }
  16. carrotAnimation(){
  17. tween(this.carrot)
  18. .to(0.5,{scale : new Vec3(1,1)})
  19. .start()
  20. }
  21. birdAnimation(){
  22. let x = this.bird.getPosition().x;
  23. let y = this.bird.getPosition().y;
  24. tween(this.bird)
  25. .repeatForever(
  26. tween()
  27. .to(1,{position : new Vec3(x,y - 10)},{easing : 'sineInOut'})
  28. .to(1,{position : new Vec3(x,y + 10)},{easing : 'sineInOut'})
  29. )
  30. .start();
  31. }
  32. onBtnLogin(){
  33. director.loadScene("SelectScene");
  34. }
  35. update(deltaTime: number) {
  36. let x = this.bird.getPosition().x;
  37. let y = this.bird.getPosition().y;
  38. this.bird.setPosition(x,y)
  39. }
  40. }