var Utils = require("Utils") cc.Class({ extends: cc.Component, properties: { anienames: { default: [], type: cc.String, }, skeleton: { default: null, type: sp.Skeleton, }, hitani: "", cdtime: 1, }, // LIFE-CYCLE CALLBACKS: // onLoad () {}, playloop() { if (this.fathernode.isson) { return } var rd = Math.floor(Math.random() * this.anienames.length) if (this.fathernode.sonobj) { var cd = this.fathernode.sonobj.spinecmp if (cd) { var scp = cd.getComponent("gamespineCmp") if (scp) { scp.playspine(rd) } } } // if(this.isson){ // return // } this.playspine(rd) // this.nowcd = 0 // this.tolooptime = 0 // this.skeleton.setAnimation(0, this.anienames[rd], false) }, playspine(rd) { this.nowcd = 0 this.tolooptime = 0 if (!this.anienames[rd]) { return } // this.nowcd = 0 // this.tolooptime = 0 this.skeleton.clearTrack(0) this.skeleton.setAnimation(0, this.anienames[rd], false) }, onEnable() { this.fathernode = this.node.parent if (!cc.editmodemap) { while (true) { this.fathernode = this.fathernode.parent if (this.fathernode.isloot) { break } } this.fathernode.spinecmp = this } this.savehit = [] if (!this.bindcb) { this.bindcb = true var self = this self.skeleton.setCompleteListener((trackEntry, loopCount) => { self.playloop() // var animationName = trackEntry.animation ? trackEntry.animation.name : ""; // if (animationName != hitani) { // self.playloop() // } }); } this.playloop() }, playhit(now) { // for (var i = 0; i < this.savehit.length; i++) { // if (this.savehit[i] == now) { // return false // } // } // this.savehit.push(now) this.nowcd = this.cdtime this.skeleton.setAnimation(0, this.hitani, false) this.tolooptime = this.cdtime return true }, // checkout(uid) { // for (var i = this.savehit.length - 1; i >= 0; i--) { // if (this.savehit[i] == uid) { // this.savehit.splice(i, 1); // break // } // } // }, chckpz() { if (!cc.gameMgr) { return } var playerarr = cc.gameMgr.playerarr var thisbox = { x: this.node.fnode.x, y: this.node.fnode.y, width: this.node.width, height: this.node.height, } for (var j = playerarr.length - 1; j >= 0; j--) { if (playerarr[j].pctrl.legstate < 2 || playerarr[j].pctrl.isdead() || playerarr[j].opacity == 0 || playerarr[j].active == false || playerarr[j].pctrl.chuantou > 0 || playerarr[j].pctrl.sanmode) { continue; } if (Utils.hitTestRectangle(thisbox, playerarr[j])) { this.playhit(playerarr[j].objuuid) return } } for (var j = cc.gameMgr.npcarr.length - 1; j >= 0; j--) { if (cc.gameMgr.npcarr[j].pctrl.legstate < 2) { continue; } if (Utils.hitTestRectangle(thisbox, cc.gameMgr.npcarr[j])) { this.playhit(cc.gameMgr.npcarr[j].objuuid) return } } }, update(dt) { if (this.hitani == "") { return } if (this.nowcd <= 0) { this.chckpz() } else { this.nowcd -= dt; } // if (this.tolooptime > 0) { // this.tolooptime -= dt; // if (this.tolooptime <= 0) { // this.playloop() // } // } }, });