http://www.cnblogs.com/raymondking123/
)以及微信公众号"优梦创客"OnEnter(){
// TODO: 选择路点,进入ArmyCallState
this.card.fsm.ChangeState(ArmyCallState);
}
//取得军队移动方向与上方向之间的弧度
let radian = dir.signAngle(cc.Vec2.UP);
//将弧度转为角度
let angle = cc.misc.radiansToDegrees(radian);
//如果军队移动方向与上方向的夹角在 -45到45之间,说明军队移动的方向是偏向上方的
if (angle > -45 && angle < 45) {
let clip = this.animation.getClips()[0]; //取得往上走的动画片段
if (this.animation.currentClip != clip) { //如果当前播放的动画不是往上走的动画
this.animation.play(clip.name); //播放往上走的动画
}
}
else if (angle > 135 || angle < -135) { //下
let clip = this.animation.getClips()[1]; //下走
if (this.animation.currentClip != clip) {
this.animation.play(clip.name);
}
}
else if (angle >= -135 && angle <= -45) { //左
let clip = this.animation.getClips()[2]; //左走
if (this.animation.currentClip != clip) {
this.animation.play(clip.name);
}
}
else if (angle >= 45 && angle <= 135) { //右
let clip = this.animation.getClips()[3]; //右走
if (this.animation.currentClip != clip) {
this.animation.play(clip.name);
}
}
//取得初始路点(桥)
let initialWaypoint = WayMgr.instance.ways[this.wayIdx].nodes[0].position;
//取得终点(国王塔位置)
let destination = WayMgr.instance.ways[this.wayIdx].nodes[1].position;
//如果玩家到国王塔的距离 小于 桥到国王塔的距离
if(destination.sub(this.card.pos).mag()<destination.sub(initialWaypoint).mag()){
this.wpIdx = 1; //就将路点索引设为1(就是直接往国王塔走)
}
let moveSpeed = this.card.propsTmp.mspd //获取模板属性中的移动速度(枚举值)
if(moveSpeed == MoveSpeed.Invalid){ //如果速度是无效
this.spd = 0;
}
else if(moveSpeed == MoveSpeed.VeryFast){ //非常快
this.spd = 50;
}
else if(moveSpeed == MoveSpeed.Fast){ //快
this.spd = 40;
}
else if(moveSpeed == MoveSpeed.Mid){ //正常
this.spd = 30;
}
else if(moveSpeed == MoveSpeed.Slow){ //慢
this.spd = 20;
}
else if(moveSpeed == MoveSpeed.VerySlow){ //非常慢
this.spd = 10;
}
原文:https://www.cnblogs.com/raymondking123/p/11326265.html