LevelHomeTop.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. const ThemeManager = require('../utils/ThemeManger');
  2. const NotiKey = require('../utils/GameEnum').GameNotificationKey;
  3. cc.Class({
  4. extends: cc.Component,
  5. properties: {
  6. bgSprite: cc.Sprite,
  7. coverSprite: cc.Sprite,
  8. catNode: cc.Node,
  9. },
  10. // LIFE-CYCLE CALLBACKS:
  11. init(cityId) {
  12. this.cityId = cityId;
  13. ThemeManager.setTopBgBuildSpriteFrame(cityId, this.bgSprite);
  14. ThemeManager.setTopCoverSpriteFrame(cityId, this.coverSprite);
  15. this.catNode.active = Global.devCityId === 1;//判断用户开发中的城市是否在第一个城市
  16. },
  17. initFriend(cityId) {
  18. this.cityId = cityId;
  19. ThemeManager.setTopBgBuildSpriteFrame(cityId, this.bgSprite);
  20. ThemeManager.setTopCoverSpriteFrame(cityId, this.coverSprite);
  21. this.catNode.active = this.cityId === 1;//判断好友开发中的城市是否在第一个城市
  22. },
  23. onLoad() {
  24. GameEvent.on(NotiKey.showCatFlyAnimation, this, this.catFlyAnimation);
  25. },
  26. catFlyAnimation(endPosition) {
  27. this.scheduleOnce(() => {
  28. this.catNode.active = false;
  29. let position = this.catNode.parent.convertToWorldSpaceAR(this.catNode);
  30. position = cc.find('Canvas').convertToNodeSpaceAR(position);
  31. cc.loader.loadRes('./prefabs/cat_animation', cc.Prefab, (err, prefab) => {
  32. let flyCat = cc.instantiate(prefab);
  33. flyCat.parent = cc.find('Canvas');
  34. flyCat.getComponent('FlyCat').fly(position, endPosition);
  35. });
  36. }, 0.2);
  37. },
  38. onDestroy() {
  39. GameEvent.off(NotiKey.showCatFlyAnimation, this);
  40. },
  41. start() {
  42. },
  43. // update (dt) {},
  44. });