标签:
追踪算法的原理:目标位置 - 当前位置 / 速度,即: dx = targetX - currentX / speed, dy = targetY - currentY / speed
var getStep = function(iTarget, iNow) { var iStep = (iTarget - iNow) / this.speed; if (iStep == 0){ return 0; } if (Math.abs(iStep) < 1){ return (iStep > 0 ? 1 : -1); } return iStep; }; var dx = getStep(this.ctx.owner.owner.player.x,this.ctx.owner.x), dy = getStep(this.ctx.owner.owner.player.y,this.ctx.owner.y);
标签:
原文地址:http://www.cnblogs.com/gongshunkai/p/5818748.html