Tools.ts 744 B

1234567891011121314151617181920212223242526272829303132333435
  1. import { _decorator, Component, ImageAsset, Node, Sprite, SpriteFrame, Texture2D } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. export class Tools {
  4. /**
  5. *
  6. * @param node
  7. * @param co
  8. */
  9. static clearFromParent(node: Node, co: any) {
  10. let arr = [];
  11. node.children.forEach(element => {
  12. if (element.getComponent(co)) {
  13. arr.push(element);
  14. }
  15. });
  16. arr.forEach((element) => {
  17. element.removeFromParent();
  18. });
  19. }
  20. /**
  21. *
  22. * @param min
  23. * @param max
  24. * @returns
  25. */
  26. public static random_between(min: number, max: number): number {
  27. return Math.random() * (max - min) + min;
  28. }
  29. }