GEffect.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import FSprite from "../object/FSprite";
  2. import FObject from "../object/FObject";
  3. /**
  4. * 刀光
  5. */
  6. const {ccclass, property} = cc._decorator;
  7. @ccclass
  8. export default class GEffect extends cc.Component {
  9. @property({
  10. displayName: '最大攻击人数'
  11. })
  12. maxCount: number = 1;
  13. /**
  14. * 子弹所属角色
  15. */
  16. public sprite:FSprite;
  17. private hitCount = 0;
  18. start () {
  19. this.hitCount = 0;
  20. let armature = this.node.getComponent(dragonBones.ArmatureDisplay);
  21. armature.addEventListener(dragonBones.EventObject.LOOP_COMPLETE as any ,(event)=>{
  22. this.node.destroy();
  23. }, this);
  24. }
  25. onBeginContact(contact: cc.PhysicsContact, selfCollider: cc.PhysicsCollider, otherCollider: cc.PhysicsCollider){
  26. if(this.hitCount >= this.maxCount){
  27. return;
  28. }
  29. if(this.sprite.node.group != otherCollider.node.group){
  30. let target = otherCollider.node.getComponent(FSprite);
  31. if(target){
  32. this.hitCount ++;
  33. this.sprite.atkjs(target);
  34. }
  35. }
  36. }
  37. }