refactor(hero): 优化英雄缩放逻辑和位置配置
重构英雄缩放逻辑,使用统一的缩放计算方法替代硬编码值 调整英雄和怪物的初始位置坐标 在Hero和Monster类中添加size变量控制缩放
This commit is contained in:
@@ -25,13 +25,13 @@ export class HInfoComp extends CCComp {
|
||||
|
||||
// 英雄位置定义
|
||||
hero_pos:any={
|
||||
0:v3(420,-57,0), // 不在屏幕内
|
||||
1:v3(280,-57,0),
|
||||
2:v3(160,-57,0),
|
||||
3:v3(0,-67,0),
|
||||
4:v3(-160,-57,0),
|
||||
5:v3(-280,-57,0),
|
||||
6:v3(-420,-57,0), // 不在屏幕内
|
||||
0:v3(420,-50,0), // 不在屏幕内
|
||||
1:v3(280,-50,0),
|
||||
2:v3(160,-50,0),
|
||||
3:v3(0,-60,0),
|
||||
4:v3(-160,-50,0),
|
||||
5:v3(-280,-50,0),
|
||||
6:v3(-420,-50,0), // 不在屏幕内
|
||||
}
|
||||
|
||||
// 动画锁定标志:防止快速点击导致的动画冲突
|
||||
@@ -43,6 +43,23 @@ export class HInfoComp extends CCComp {
|
||||
}
|
||||
// 位置索引常量
|
||||
private static center_pos = 3;
|
||||
|
||||
/**
|
||||
* 根据位置索引获取英雄缩放值
|
||||
* @param posIndex 位置索引 (0-6)
|
||||
* @returns Vec3 缩放向量
|
||||
*/
|
||||
private getHeroScale(posIndex: number): Vec3 {
|
||||
switch(posIndex) {
|
||||
case 2:
|
||||
case 4:
|
||||
return v3(-1.6, 1.6, 1); // 2、4位置:1.2倍缩放
|
||||
case 3:
|
||||
return v3(-1.8, 1.8, 1); // 3位置(中心):1.5倍缩放
|
||||
default:
|
||||
return v3(-1.4, 1.4, 1); // 其他位置:1倍缩放
|
||||
}
|
||||
}
|
||||
|
||||
start() {
|
||||
this.name_node=this.node.getChildByName("hero").getChildByName("hname").getChildByName("name")
|
||||
@@ -105,10 +122,11 @@ export class HInfoComp extends CCComp {
|
||||
// 载入英雄预制体并设置位置
|
||||
this.heroNodes[i] = this.load_hui(heroUuid, i);
|
||||
|
||||
// 添加初始缩放动画,确保3号位是1.5倍
|
||||
if (this.heroNodes[i] && i === 3) {
|
||||
// 添加初始缩放动画,根据位置设置不同的缩放值
|
||||
if (this.heroNodes[i]) {
|
||||
let targetScale = this.getHeroScale(i);
|
||||
tween(this.heroNodes[i])
|
||||
.to(0.2, { scale: v3(-1.5, 1.5, 1) })
|
||||
.to(0.2, { scale: targetScale })
|
||||
.start();
|
||||
}
|
||||
}
|
||||
@@ -124,12 +142,8 @@ export class HInfoComp extends CCComp {
|
||||
// 设置节点位置
|
||||
node.setPosition(this.hero_pos[pos_index]);
|
||||
node.setSiblingIndex(0);
|
||||
// 设置缩放:3号位1.5倍,其他位置1倍
|
||||
if(pos_index==3){
|
||||
node.setScale(v3(-1.5,1.5,1))
|
||||
} else {
|
||||
node.setScale(v3(-1,1,1))
|
||||
}
|
||||
// 根据位置设置不同的缩放值
|
||||
node.setScale(this.getHeroScale(pos_index));
|
||||
// 加载并播放动画
|
||||
let anm_path=HeroInfo[uuid].path;
|
||||
resources.load("game/heros/hero/"+anm_path+"/idle", AnimationClip, (err, clip) => {
|
||||
@@ -240,7 +254,7 @@ export class HInfoComp extends CCComp {
|
||||
let targetPos = this.hero_pos[i + 1];
|
||||
|
||||
// 使用Tween执行平滑移动和缩放动画
|
||||
let targetScale = (i + 1) === 3 ? v3(-1.5, 1.5, 1) : v3(-1, 1, 1);
|
||||
let targetScale = this.getHeroScale(i + 1);
|
||||
|
||||
tween(this.heroNodes[i])
|
||||
.to(0.2, { position: targetPos, scale: targetScale })
|
||||
@@ -267,9 +281,9 @@ export class HInfoComp extends CCComp {
|
||||
|
||||
this.heroNodes[0] = this.load_hui(heros[newIndex], 0);
|
||||
|
||||
// 确保新创建的节点初始缩放为1倍(因为0号位不是中心位置)
|
||||
// 确保新创建的节点使用正确的缩放值
|
||||
if (this.heroNodes[0]) {
|
||||
this.heroNodes[0].setScale(v3(-1, 1, 1));
|
||||
this.heroNodes[0].setScale(this.getHeroScale(0));
|
||||
}
|
||||
|
||||
// 动画完成,解除锁定
|
||||
@@ -300,7 +314,7 @@ export class HInfoComp extends CCComp {
|
||||
let targetPos = this.hero_pos[i - 1];
|
||||
|
||||
// 使用Tween执行平滑移动和缩放动画
|
||||
let targetScale = (i - 1) === 3 ? v3(-1.5, 1.5, 1) : v3(-1, 1, 1);
|
||||
let targetScale = this.getHeroScale(i - 1);
|
||||
|
||||
tween(this.heroNodes[i])
|
||||
.to(0.2, { position: targetPos, scale: targetScale })
|
||||
@@ -327,9 +341,9 @@ export class HInfoComp extends CCComp {
|
||||
|
||||
this.heroNodes[6] = this.load_hui(heros[newIndex], 6);
|
||||
|
||||
// 确保新创建的节点初始缩放为1倍(因为6号位不是中心位置)
|
||||
// 确保新创建的节点使用正确的缩放值
|
||||
if (this.heroNodes[6]) {
|
||||
this.heroNodes[6].setScale(v3(-1, 1, 1));
|
||||
this.heroNodes[6].setScale(this.getHeroScale(6));
|
||||
}
|
||||
|
||||
// 动画完成,解除锁定
|
||||
|
||||
Reference in New Issue
Block a user