ChargeCollision.ts 846 B

123456789101112131415161718192021222324252627282930
  1. import FSprite from "../FSprite";
  2. import SkillBase from "./SkillBase";
  3. /**
  4. * 冲击时候的碰撞
  5. */
  6. const {ccclass, property} = cc._decorator;
  7. @ccclass
  8. export default class ChargeCollision extends cc.Component {
  9. public skillBase:SkillBase;
  10. onBeginContact (contact:cc.PhysicsContact,self, other) {
  11. let sprite = this.skillBase.sprite;
  12. if(sprite &&sprite.isValid && sprite.hp > 0 &&
  13. sprite.node.group != other.node.group){
  14. if(self.isValid && other.node.isValid){
  15. let otherNode = other.node as cc.Node;
  16. let target = otherNode.getComponent(FSprite);
  17. if(target && target.hp > 0){
  18. if(target != null && target.isActive){
  19. sprite.atkjs(target);
  20. }
  21. }
  22. }
  23. }
  24. }
  25. }