refactor(map): 优化英雄节点左右移动逻辑
- 调整moveHeroesLeft方法,动画开始前销毁第6个英雄节点,避免重复渲染 - 实现英雄节点向左平滑移动,使用Tween过渡动画 - 延迟重排英雄节点数组,确保动画完成后数组正确更新 - 调整moveHeroesRight方法,动画开始前销毁第0个英雄节点,避免重复渲染 - 实现英雄节点向右平滑移动,使用Tween过渡动画 - 延迟重排英雄节点数组,确保动画完成后数组正确更新 - 移除close方法中无用的节点移除逻辑,改用reset方法销毁节点 - 更新prefab中部分控件位置和尺寸,微调界面布局样式
This commit is contained in:
@@ -147,12 +147,18 @@ export class HInfoComp extends Component {
|
||||
this.moveHeroesLeft();
|
||||
}
|
||||
|
||||
moveHeroesRight() {
|
||||
// 移动所有现有节点向右
|
||||
for (let i = 0; i < this.heroNodes.length; i++) {
|
||||
moveHeroesLeft() {
|
||||
// 在动画开始前,直接销毁hero_pos[6]上的节点
|
||||
if (this.heroNodes[6]) {
|
||||
this.heroNodes[6].destroy();
|
||||
this.heroNodes[6] = null;
|
||||
}
|
||||
|
||||
// 移动所有现有节点向左(除了已销毁的heroNodes[6])
|
||||
for (let i = 0; i < 6; i++) {
|
||||
if (this.heroNodes[i]) {
|
||||
// 计算目标位置
|
||||
let targetPos = this.hero_pos[i + 1] || this.hero_pos[0];
|
||||
// 计算目标位置:向左移动
|
||||
let targetPos = this.hero_pos[i + 1];
|
||||
|
||||
// 使用Tween执行平滑移动
|
||||
tween(this.heroNodes[i])
|
||||
@@ -161,14 +167,9 @@ export class HInfoComp extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
// 延迟创建新节点和删除旧节点,等待动画完成
|
||||
// 延迟重排数组和创建新节点,等待动画完成
|
||||
setTimeout(() => {
|
||||
// 删除原先位于hero_pos[6]位置的节点
|
||||
if (this.heroNodes[6]) {
|
||||
this.heroNodes[6].destroy();
|
||||
}
|
||||
|
||||
// 移动数组元素
|
||||
// 移动数组元素(向后平移)
|
||||
for (let i = 6; i > 0; i--) {
|
||||
this.heroNodes[i] = this.heroNodes[i - 1];
|
||||
}
|
||||
@@ -187,12 +188,18 @@ export class HInfoComp extends Component {
|
||||
}, 300); // 与动画时间保持一致
|
||||
}
|
||||
|
||||
moveHeroesLeft() {
|
||||
// 移动所有现有节点向左
|
||||
for (let i = 0; i < this.heroNodes.length; i++) {
|
||||
moveHeroesRight() {
|
||||
// 在动画开始前,直接销毁hero_pos[0]上的节点
|
||||
if (this.heroNodes[0]) {
|
||||
this.heroNodes[0].destroy();
|
||||
this.heroNodes[0] = null;
|
||||
}
|
||||
|
||||
// 移动所有现有节点向右(除了已销毁的heroNodes[0])
|
||||
for (let i = 1; i < this.heroNodes.length; i++) {
|
||||
if (this.heroNodes[i]) {
|
||||
// 计算目标位置
|
||||
let targetPos = this.hero_pos[i - 1] || this.hero_pos[6];
|
||||
// 计算目标位置:向右移动
|
||||
let targetPos = this.hero_pos[i - 1];
|
||||
|
||||
// 使用Tween执行平滑移动
|
||||
tween(this.heroNodes[i])
|
||||
@@ -201,14 +208,9 @@ export class HInfoComp extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
// 延迟创建新节点和删除旧节点,等待动画完成
|
||||
// 延迟重排数组和创建新节点,等待动画完成
|
||||
setTimeout(() => {
|
||||
// 删除原先位于hero_pos[0]位置的节点
|
||||
if (this.heroNodes[0]) {
|
||||
this.heroNodes[0].destroy();
|
||||
}
|
||||
|
||||
// 移动数组元素
|
||||
// 移动数组元素(向前平移)
|
||||
for (let i = 0; i < 6; i++) {
|
||||
this.heroNodes[i] = this.heroNodes[i + 1];
|
||||
}
|
||||
@@ -227,9 +229,6 @@ export class HInfoComp extends Component {
|
||||
}, 300); // 与动画时间保持一致
|
||||
}
|
||||
|
||||
close(){
|
||||
oops.gui.removeByNode(this.node)
|
||||
}
|
||||
reset() {
|
||||
this.node.destroy()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user