CatItem.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
  7. import { DataMgr } from "../manager/DataMgr";
  8. const { ccclass, property } = cc._decorator;
  9. @ccclass
  10. export default class CatItem extends cc.Component {
  11. @property(cc.Node)
  12. cat: cc.Node = null;
  13. @property(cc.Sprite)
  14. catSprite: cc.Sprite = null
  15. start() {
  16. this.scheduleOnce(() => {
  17. this.play(2);
  18. }, 0.1)
  19. }
  20. protected onLoad(): void {
  21. }
  22. protected onEnable(): void {
  23. // const id = DataMgr.ins.getRandomId();
  24. // cc.resources.load("/cat/cat_skin_" + id, cc.SpriteFrame, (error, frame) => {
  25. // this.catSprite.spriteFrame = frame
  26. // })
  27. }
  28. public state = 0;
  29. public play(state) {
  30. if (state == 1) //默认
  31. {
  32. cc.tween(this.cat)
  33. .to(1, { scaleX: 1.2 })
  34. .to(1, { scaleX: 1 })
  35. .union()
  36. .repeat(1000000)
  37. .start();
  38. }else{
  39. var animationComponent = this.getComponent(cc.Animation)
  40. var animState = animationComponent.play('idle');
  41. animState.speed = 0.4
  42. animState.repeatCount = Infinity;
  43. }
  44. }
  45. }