FPatrolWarn.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import FF from "../../FF";
  2. import { GroupType } from "../../object/FObject";
  3. import FSprite from "../../object/FSprite";
  4. /**
  5. * 警示区域碰撞逻辑处理
  6. */
  7. const {ccclass, property} = cc._decorator;
  8. @ccclass
  9. export default class FPatrolWarn extends cc.Component {
  10. @property(cc.Node)
  11. mInitPos: cc.Node = null;
  12. public ff:FF;
  13. private isOver = false;
  14. onBeginContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider){
  15. if(this.isOver){
  16. return;
  17. }
  18. if(other.node.group == 'A'){
  19. let obj = other.node.getComponent(FSprite);
  20. this.ff = obj.ff;
  21. this.isOver = true;
  22. this.ff.pauseSprite(true);
  23. cc.tween(this).sequence(
  24. cc.delayTime(0.01),
  25. cc.callFunc(()=>{
  26. let pos = this.mInitPos.getPosition();
  27. let sprites = this.ff.getGroupBy(GroupType.A);
  28. for (let i = 0; i < sprites.length; i++) {
  29. const element = sprites[i];
  30. if(element){
  31. element.setPosition(pos);
  32. }
  33. }
  34. }),
  35. cc.delayTime(0.01),
  36. cc.callFunc(()=>{
  37. this.isOver = false;
  38. this.ff.pauseSprite(false);
  39. }),
  40. ).start();
  41. }
  42. }
  43. }