GameAnimal.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { _decorator, Component, Node, tween, Vec3, AudioSource } from 'cc';
  2. import { GameEvent } from '../Common/Base/GameEventConfig';
  3. import GameEventManager from '../Common/Base/GameEventManager';
  4. import { Global } from '../Common/Global';
  5. const { ccclass, property } = _decorator;
  6. @ccclass('GameAnimal')
  7. export class GameAnimal extends Component {
  8. audioPlaying:boolean=false;
  9. pause:boolean=false;
  10. audioTime=0;
  11. timerCount=0;
  12. start() {
  13. // this.node.on(Node.EventType.TOUCH_END, this._onTouchEndNode, this);
  14. // this.node.on(Node.EventType.TOUCH_CANCEL, this._onTouchEndNode, this);
  15. this.setDefault();
  16. this.node.setScale(Vec3.ZERO);
  17. }
  18. update(deltaTime: number) {
  19. }
  20. // _onTouchEndNode(){
  21. // GameEventManager.getInstance().dispathcGameEvent(GameEvent.ClickUp,this.node.name);
  22. // }
  23. BiggerAnimal(flag:boolean){
  24. if(flag){
  25. this.node.setScale(new Vec3(1.2,1.2,1));
  26. }else{
  27. this.node.setScale(new Vec3(1,1,1));
  28. }
  29. }
  30. beforeDestroy(){
  31. // this.node.off(Node.EventType.TOUCH_END, this._onTouchEndNode, this);
  32. // this.node.off(Node.EventType.TOUCH_CANCEL, this._onTouchEndNode, this);
  33. }
  34. setIsRight(isright){
  35. this.node.children[1].active=isright;
  36. this.node.children[2].active=!isright;
  37. }
  38. setDefault(){
  39. this.node.children[1].active=false;
  40. this.node.children[2].active=false;
  41. this.BiggerAnimal(false);
  42. }
  43. onDestroy(){
  44. }
  45. pausePlay(){
  46. if(this.audioPlaying){
  47. this.node.getComponent(AudioSource).pause();
  48. this.pause=true;
  49. }
  50. }
  51. RestartPlay(){
  52. if(this.audioPlaying){
  53. this.node.getComponent(AudioSource).play();
  54. this.pause=false;
  55. }
  56. }
  57. PlayMyAudio(func){
  58. let audio=this.node.getComponent(AudioSource);
  59. audio.play();
  60. this.audioPlaying=true;
  61. this.audioTime=audio.duration;
  62. Global.cdSchedule.schedule(()=>{
  63. if(func){
  64. func();
  65. }
  66. Global.cdSchedule.unschedule(this.node.name);
  67. },this.audioTime,this.node.name)
  68. }
  69. ShowCard(func){
  70. tween(this.node).to(0.4,{scale:new Vec3(1,1,1)},{ easing: 'elasticOut' }).call(()=>{
  71. if(func){
  72. func();
  73. }
  74. }).start();
  75. }
  76. }