Files
heros/assets/script/game/skills/EndAnmBomCom.ts

73 lines
2.7 KiB
TypeScript

import { _decorator, Animation, Collider2D, Component, Node, RigidBody2D, sp } from 'cc';
import { SkillCom } from './SkillCom';
import { BoxSet } from '../common/config/BoxSet';
import { Hero } from '../hero/Hero';
const { ccclass, property } = _decorator;
@ccclass('EndAnmBomCom')
export class EndAnmBomCom extends Component {
time:number = 0
base:SkillCom = null
collider:Collider2D = null
rigid:RigidBody2D= null
is_complete:boolean = false
start() {
this.base =this.node.getComponent(SkillCom)
this.collider = this.getComponent(Collider2D);
this.rigid = this.getComponent(RigidBody2D);
console.log("collider",this.collider,this.rigid)
this.rigid.sleep()
// this.collider.enabled = false
// if(this.base.box_group ==BoxSet.HERO) this.collider.group = BoxSet.MONSTER
// if(this.base.box_group ==BoxSet.MONSTER) this.collider.group = BoxSet.HERO
if(this.node.getComponent(Animation)){
let anim = this.node.getComponent(Animation);
console.log("has anim",anim)
anim.on(Animation.EventType.FINISHED, this.onAnimationFinished, this);
}
if(this.node.getChildByName('anm')){
if(this.node.getChildByName('anm').getComponent('sp.Skeleton')){
var spine = this.node.getChildByName('anm').getComponent('sp.Skeleton') as sp.Skeleton;
console.log("has spine",spine)
spine.setCompleteListener((trackEntry) => {
this.onAnimationFinished()
console.log("[track %s][animation %s] complete: %s", trackEntry.trackIndex);
});
spine.setEventListener((trackEntry, event:any) => {
this.onEnvent(event)
// console.log("[track %s][animation %s] event: %s", trackEntry.trackIndex, event.data.name, event.intValue);
});
}
}
}
onAnimationFinished(){
if(!this.is_complete){
// this.collider.group = this.base.box_group
// this.node.active=false
// this.node.active=true
this.rigid.wakeUp()
// this.collider.enabled = true
console.log("动画结束,开始伤害")
}
this.base.is_destroy = true
}
onEnvent(event:any){
if(event.data.name == "atk_event"){
// this.collider.group = this.base.box_group
// this.node.active=false
// this.node.active=true
this.rigid.wakeUp()
// this.collider.enabled = true
console.log("onEnvent,开始伤害",event)
this.is_complete=true
}
}
}