scaleAction.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { _decorator, Component, Node, tween, CCInteger, Vec3, CCFloat } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. @ccclass('scaleAction')
  4. export class scaleAction extends Component {
  5. //节点组
  6. @property(Node)
  7. nodes;
  8. //速度
  9. @property(CCInteger)
  10. sleep;
  11. //放大
  12. @property(CCFloat)
  13. scaleMax;
  14. //缩小
  15. @property(CCFloat)
  16. scaleMin;
  17. @property(Boolean)
  18. isChild = false;
  19. start() {
  20. if (this.isChild) {
  21. this.nodes.children.forEach(node => {
  22. let action = tween().target(node)
  23. .to(this.sleep, { scale: new Vec3(this.scaleMax, this.scaleMax, 0), position: node.position }, {
  24. easing: "smooth"
  25. })
  26. .to(this.sleep, { scale: new Vec3(this.scaleMin, this.scaleMin, 0), position: node.position }, {
  27. easing: "smooth"
  28. })
  29. ;
  30. tween().target(node).repeatForever(action).start();
  31. });
  32. } else {
  33. let action = tween().target(this.node)
  34. .to(this.sleep, { scale: new Vec3(this.scaleMax, this.scaleMax, 0), position: this.node.position }, {
  35. easing: "smooth"
  36. })
  37. .to(this.sleep, { scale: new Vec3(this.scaleMin, this.scaleMin, 0), position: this.node.position }, {
  38. easing: "smooth"
  39. })
  40. ;
  41. tween().target(this.node).repeatForever(action).start();
  42. }
  43. }
  44. update(deltaTime: number) {
  45. }
  46. }