|
@@ -22,8 +22,13 @@ export class Hero extends BattleNodeBase {
|
|
|
@property({ type: Label, tooltip: '等级' })
|
|
|
levelLabel: Label = null;
|
|
|
|
|
|
- @property({ type: Node, tooltip: '枪' })
|
|
|
- gunNode: Node = null;
|
|
|
+ @property({ type: Node, tooltip: '枪 左右' })
|
|
|
+ gunNode1: Node = null;
|
|
|
+ @property({ type: Node, tooltip: '枪 下' })
|
|
|
+ gunNode2: Node = null;
|
|
|
+ @property({ type: Node, tooltip: '枪 上' })
|
|
|
+ gunNode3: Node = null;
|
|
|
+
|
|
|
|
|
|
@property({ type: UITransform, tooltip: '点击框' })
|
|
|
clickBox: UITransform = null;
|
|
@@ -124,9 +129,8 @@ export class Hero extends BattleNodeBase {
|
|
|
this.levelLabel.string = heroData.level.toString();
|
|
|
this.node.active = true;
|
|
|
this.modelSpine.node.active = true;
|
|
|
- let conf = UptypeConf.data
|
|
|
- let speedScale = conf.HeroSpeedColArr[this.level]
|
|
|
- this.modelSpine.timeScale = speedScale;
|
|
|
+
|
|
|
+ this.modelSpine.timeScale = 1;
|
|
|
this.stand()
|
|
|
// let id: string = heroData.heroID;
|
|
|
}
|
|
@@ -146,63 +150,50 @@ export class Hero extends BattleNodeBase {
|
|
|
super.update(deltaTime);
|
|
|
if(this._bAttackAnimation && isValid(this.attackNode)){
|
|
|
let pos = this.attackNode.position;
|
|
|
- // 获取子节点的世界坐标
|
|
|
- let worldPosition = this.gunNode.getComponent(UITransform).convertToWorldSpaceAR(Vec3.ZERO);
|
|
|
- // 将子节点的世界坐标转换为父节点的局部坐标
|
|
|
- let localPosition = this.node.parent.getComponent(UITransform).convertToNodeSpaceAR(worldPosition);
|
|
|
- // 计算从p0到p1的向量
|
|
|
- let deltaX: number = pos.x - localPosition.x;
|
|
|
- let deltaY: number = pos.y - localPosition.y;
|
|
|
-
|
|
|
- // 计算旋转角度(弧度)
|
|
|
- let rotationAngleRadians: number = Math.atan2(deltaY, deltaX);
|
|
|
- // 将旋转角度转换为度数
|
|
|
- let rotationAngleDegrees: number = (rotationAngleRadians * (180 / Math.PI)+360)%360;
|
|
|
-
|
|
|
- // console.log("旋转角度:", rotationAngleDegrees);
|
|
|
-
|
|
|
- // let scaleX = this.modelSpine.node.scale.x
|
|
|
- // if(rotationAngleDegrees > 90 && rotationAngleDegrees < 270){
|
|
|
- // // if(scaleX > 0){
|
|
|
- // // scaleX= -scaleX;
|
|
|
- // // }
|
|
|
- // // this.gunNode.angle = 180 - rotationAngleDegrees;
|
|
|
- // this.attackBone.rotation = 180 - rotationAngleDegrees
|
|
|
- // }
|
|
|
- // else{
|
|
|
- // // if(scaleX < 0){
|
|
|
- // // scaleX= -scaleX;
|
|
|
- // // }
|
|
|
- // // this.gunNode.angle = rotationAngleDegrees;
|
|
|
- // this.attackBone.rotation = rotationAngleDegrees
|
|
|
- // }
|
|
|
- // this.modelSpine.node.scale = new Vec3(scaleX,this.modelSpine.node.scale.y,this.modelSpine.node.scale.z);
|
|
|
- // console.log("旋转角度:", rotationAngleDegrees);
|
|
|
+ let rotationAngleDegrees = this.getRotationAngle(this.node,pos)
|
|
|
|
|
|
this.attackBone1.rotation = 0
|
|
|
this.attackBone2.rotation = 0
|
|
|
this.attackBone3.rotation = 0
|
|
|
this.attackBone4.rotation = 0
|
|
|
-
|
|
|
+ let bChange = false
|
|
|
if(rotationAngleDegrees<67.5 || rotationAngleDegrees > 292.5){
|
|
|
- this.attackBone1.rotation = (rotationAngleDegrees+this.attackAngle1)
|
|
|
- if(this.modelSpine.animation != "atk_right")
|
|
|
+ let rotationAngle = this.getRotationAngle(this.gunNode1,pos)
|
|
|
+ this.attackBone1.rotation = (rotationAngle+this.attackAngle1)
|
|
|
+ if(this.modelSpine.animation != "atk_right"){
|
|
|
this.modelSpine.setAnimation(0, 'atk_right', true);
|
|
|
+ bChange = true
|
|
|
+ }
|
|
|
}
|
|
|
else if(rotationAngleDegrees < 112.5){
|
|
|
- this.attackBone3.rotation = rotationAngleDegrees+this.attackAngle3-90
|
|
|
- if(this.modelSpine.animation != "atk_up")
|
|
|
+ let rotationAngle = this.getRotationAngle(this.gunNode3,pos)
|
|
|
+ this.attackBone3.rotation = rotationAngle+this.attackAngle3-90
|
|
|
+ if(this.modelSpine.animation != "atk_up"){
|
|
|
this.modelSpine.setAnimation(0, 'atk_up', true);
|
|
|
+ bChange = true
|
|
|
+ }
|
|
|
}
|
|
|
else if(rotationAngleDegrees < 247.5){
|
|
|
- this.attackBone4.rotation = 180-rotationAngleDegrees+this.attackAngle4
|
|
|
- if(this.modelSpine.animation != "atk_left")
|
|
|
+ let rotationAngle = this.getRotationAngle(this.gunNode1,pos)
|
|
|
+ this.attackBone4.rotation = 180-rotationAngle+this.attackAngle4
|
|
|
+ if(this.modelSpine.animation != "atk_left"){
|
|
|
this.modelSpine.setAnimation(0, 'atk_left', true);
|
|
|
+ bChange = true
|
|
|
+ }
|
|
|
}
|
|
|
else if(rotationAngleDegrees < 292.5){
|
|
|
- this.attackBone2.rotation = rotationAngleDegrees+this.attackAngle2-270
|
|
|
- if(this.modelSpine.animation != "atk_down")
|
|
|
+ let rotationAngle = this.getRotationAngle(this.gunNode2,pos)
|
|
|
+ this.attackBone2.rotation = rotationAngle+this.attackAngle2-270
|
|
|
+ if(this.modelSpine.animation != "atk_down"){
|
|
|
this.modelSpine.setAnimation(0, 'atk_down', true);
|
|
|
+ bChange = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(bChange){
|
|
|
+ let conf = UptypeConf.data
|
|
|
+ let speedScale = conf.HeroSpeedColArr[this.level]
|
|
|
+ this.modelSpine.timeScale = speedScale;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -234,14 +225,32 @@ export class Hero extends BattleNodeBase {
|
|
|
if(!this.modelSpine.node.active) return;
|
|
|
this._bAttackAnimation = false;
|
|
|
// this.gunNode.angle = 0;
|
|
|
- this.gunNode.active = true;
|
|
|
- this.attackBone1.rotation = 0
|
|
|
- this.attackBone2.rotation = 0
|
|
|
- this.attackBone3.rotation = 0
|
|
|
- this.attackBone4.rotation = 0
|
|
|
+ // this.gunNode.active = true;
|
|
|
+ this.attackBone1.rotation = 0
|
|
|
+ this.attackBone2.rotation = 0
|
|
|
+ this.attackBone3.rotation = 0
|
|
|
+ this.attackBone4.rotation = 0
|
|
|
// this._attackCallback = null;
|
|
|
- if(this.modelSpine.animation == "idle_right") return;
|
|
|
- this.modelSpine.setAnimation(0, 'idle_right', true);
|
|
|
+ let animationName = this.modelSpine.animation
|
|
|
+ if(animationName.includes("idle")) return;
|
|
|
+ switch(animationName){
|
|
|
+ case "atk_right":
|
|
|
+ this.modelSpine.setAnimation(0, 'idle_right', true);
|
|
|
+ break;
|
|
|
+ case "atk_left":
|
|
|
+ this.modelSpine.setAnimation(0, 'idle_left', true);
|
|
|
+ break;
|
|
|
+ case "atk_up":
|
|
|
+ this.modelSpine.setAnimation(0, 'idle_up', true);
|
|
|
+ break;
|
|
|
+ case "atk_down":
|
|
|
+ this.modelSpine.setAnimation(0, 'idle_down', true);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ this.modelSpine.setAnimation(0, 'idle_right', true);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ this.modelSpine.timeScale = 1;
|
|
|
// if(this.modelSpine.node.scale.x < 0)
|
|
|
// this.modelSpine.node.scale = new Vec3(-this.modelSpine.node.scale.x,this.modelSpine.node.scale.y,this.modelSpine.node.scale.z);
|
|
|
|
|
@@ -250,9 +259,6 @@ export class Hero extends BattleNodeBase {
|
|
|
levelUp() {
|
|
|
this.level++;
|
|
|
this.levelLabel.string = this.level.toString();
|
|
|
- let conf = UptypeConf.data
|
|
|
- let speedScale = conf.HeroSpeedColArr[this.level]
|
|
|
- this.modelSpine.timeScale = speedScale;
|
|
|
}
|
|
|
|
|
|
actionCallback(trackEntry){
|
|
@@ -306,6 +312,24 @@ export class Hero extends BattleNodeBase {
|
|
|
return this.clickBox.hitTest(pos) || this.node.getComponent(UITransform).hitTest(pos);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ //根据目标位置获取旋转角度
|
|
|
+ getRotationAngle(srcNode:Node,targetPos:Vec2){
|
|
|
+ // 获取子节点的世界坐标
|
|
|
+ let worldPosition = this.node.getComponent(UITransform).convertToWorldSpaceAR(Vec3.ZERO);
|
|
|
+ // 将子节点的世界坐标转换为父节点的局部坐标
|
|
|
+ let localPosition = this.node.parent.getComponent(UITransform).convertToNodeSpaceAR(worldPosition);
|
|
|
+ // 计算从p0到p1的向量
|
|
|
+ let deltaX: number = targetPos.x - localPosition.x;
|
|
|
+ let deltaY: number = targetPos.y - localPosition.y;
|
|
|
+
|
|
|
+ // 计算旋转角度(弧度)
|
|
|
+ let rotationAngleRadians: number = Math.atan2(deltaY, deltaX);
|
|
|
+ // 将旋转角度转换为度数
|
|
|
+ let rotationAngleDegrees: number = (rotationAngleRadians * (180 / Math.PI)+360)%360;
|
|
|
+
|
|
|
+ return rotationAngleDegrees;
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|