attackOnTarget: function (atkDir, targetPos) {
var self = this;
let deg = cc.radiansToDegrees(cc.pAngleSigned(cc.p(0, 1), atkDir));
let angleDivider = [0, 12, 35, 56, 79, 101, 124, 146, 168, 180];
function getAtkSF(mag, sfAtkDirs) {
let atkSF = null;
for (let i = 1; i < angleDivider.length; ++i) {
let min = angleDivider[i - 1];
let max = angleDivider[i];
if (mag <= max && mag > min) {
atkSF = sfAtkDirs[i - 1];
self.nextPoseSF = self.sfPostAtks[Math.floor(( i - 1 )/3)];
return atkSF;
}
}
if (atkSF === null) {
console.error('cannot find correct attack pose sprite frame! mag: ' + mag);
return null;
}
}
let mag = Math.abs(deg);
if (deg <= 0) {
this.spPlayer.node.scaleX = 1;
this.spPlayer.spriteFrame = getAtkSF(mag, this.sfAtkDirs);
} else {
this.spPlayer.node.scaleX = -1;
this.spPlayer.spriteFrame = getAtkSF(mag, this.sfAtkDirs);
}
let moveAction = cc.moveTo(this.atkDuration, targetPos).easing(cc.easeQuinticActionOut());
let callback = cc.callFunc(this.onAtkFinished, this);
this.node.runAction(cc.sequence(moveAction, callback));
this.inputEnabled = false;
this.isAttacking = true;
},