refactor(map): 优化英雄节点左右移动逻辑
- 调整moveHeroesLeft方法,动画开始前销毁第6个英雄节点,避免重复渲染 - 实现英雄节点向左平滑移动,使用Tween过渡动画 - 延迟重排英雄节点数组,确保动画完成后数组正确更新 - 调整moveHeroesRight方法,动画开始前销毁第0个英雄节点,避免重复渲染 - 实现英雄节点向右平滑移动,使用Tween过渡动画 - 延迟重排英雄节点数组,确保动画完成后数组正确更新 - 移除close方法中无用的节点移除逻辑,改用reset方法销毁节点 - 更新prefab中部分控件位置和尺寸,微调界面布局样式
This commit is contained in:
@@ -180,7 +180,7 @@
|
|||||||
},
|
},
|
||||||
"_lpos": {
|
"_lpos": {
|
||||||
"__type__": "cc.Vec3",
|
"__type__": "cc.Vec3",
|
||||||
"x": -300,
|
"x": -276.526,
|
||||||
"y": 1130,
|
"y": 1130,
|
||||||
"z": 0
|
"z": 0
|
||||||
},
|
},
|
||||||
@@ -230,7 +230,7 @@
|
|||||||
},
|
},
|
||||||
"_lpos": {
|
"_lpos": {
|
||||||
"__type__": "cc.Vec3",
|
"__type__": "cc.Vec3",
|
||||||
"x": 14.894,
|
"x": 0,
|
||||||
"y": -5,
|
"y": -5,
|
||||||
"z": 0
|
"z": 0
|
||||||
},
|
},
|
||||||
@@ -369,7 +369,7 @@
|
|||||||
},
|
},
|
||||||
"_lpos": {
|
"_lpos": {
|
||||||
"__type__": "cc.Vec3",
|
"__type__": "cc.Vec3",
|
||||||
"x": -21.369,
|
"x": -30.654,
|
||||||
"y": 0,
|
"y": 0,
|
||||||
"z": 0
|
"z": 0
|
||||||
},
|
},
|
||||||
@@ -508,7 +508,7 @@
|
|||||||
},
|
},
|
||||||
"_lpos": {
|
"_lpos": {
|
||||||
"__type__": "cc.Vec3",
|
"__type__": "cc.Vec3",
|
||||||
"x": 40.92,
|
"x": 24.748,
|
||||||
"y": 0,
|
"y": 0,
|
||||||
"z": 0
|
"z": 0
|
||||||
},
|
},
|
||||||
@@ -658,8 +658,8 @@
|
|||||||
},
|
},
|
||||||
"_contentSize": {
|
"_contentSize": {
|
||||||
"__type__": "cc.Size",
|
"__type__": "cc.Size",
|
||||||
"width": 100,
|
"width": 150,
|
||||||
"height": 60
|
"height": 100
|
||||||
},
|
},
|
||||||
"_anchorPoint": {
|
"_anchorPoint": {
|
||||||
"__type__": "cc.Vec2",
|
"__type__": "cc.Vec2",
|
||||||
@@ -758,9 +758,9 @@
|
|||||||
},
|
},
|
||||||
"_alignFlags": 9,
|
"_alignFlags": 9,
|
||||||
"_target": null,
|
"_target": null,
|
||||||
"_left": 10,
|
"_left": 8.47399999999999,
|
||||||
"_right": 20,
|
"_right": 20,
|
||||||
"_top": 120,
|
"_top": 100,
|
||||||
"_bottom": 35,
|
"_bottom": 35,
|
||||||
"_horizontalCenter": 0,
|
"_horizontalCenter": 0,
|
||||||
"_verticalCenter": 0,
|
"_verticalCenter": 0,
|
||||||
|
|||||||
@@ -147,12 +147,18 @@ export class HInfoComp extends Component {
|
|||||||
this.moveHeroesLeft();
|
this.moveHeroesLeft();
|
||||||
}
|
}
|
||||||
|
|
||||||
moveHeroesRight() {
|
moveHeroesLeft() {
|
||||||
// 移动所有现有节点向右
|
// 在动画开始前,直接销毁hero_pos[6]上的节点
|
||||||
for (let i = 0; i < this.heroNodes.length; i++) {
|
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]) {
|
if (this.heroNodes[i]) {
|
||||||
// 计算目标位置
|
// 计算目标位置:向左移动
|
||||||
let targetPos = this.hero_pos[i + 1] || this.hero_pos[0];
|
let targetPos = this.hero_pos[i + 1];
|
||||||
|
|
||||||
// 使用Tween执行平滑移动
|
// 使用Tween执行平滑移动
|
||||||
tween(this.heroNodes[i])
|
tween(this.heroNodes[i])
|
||||||
@@ -161,14 +167,9 @@ export class HInfoComp extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 延迟创建新节点和删除旧节点,等待动画完成
|
// 延迟重排数组和创建新节点,等待动画完成
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
// 删除原先位于hero_pos[6]位置的节点
|
// 移动数组元素(向后平移)
|
||||||
if (this.heroNodes[6]) {
|
|
||||||
this.heroNodes[6].destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 移动数组元素
|
|
||||||
for (let i = 6; i > 0; i--) {
|
for (let i = 6; i > 0; i--) {
|
||||||
this.heroNodes[i] = this.heroNodes[i - 1];
|
this.heroNodes[i] = this.heroNodes[i - 1];
|
||||||
}
|
}
|
||||||
@@ -187,12 +188,18 @@ export class HInfoComp extends Component {
|
|||||||
}, 300); // 与动画时间保持一致
|
}, 300); // 与动画时间保持一致
|
||||||
}
|
}
|
||||||
|
|
||||||
moveHeroesLeft() {
|
moveHeroesRight() {
|
||||||
// 移动所有现有节点向左
|
// 在动画开始前,直接销毁hero_pos[0]上的节点
|
||||||
for (let i = 0; i < this.heroNodes.length; i++) {
|
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]) {
|
if (this.heroNodes[i]) {
|
||||||
// 计算目标位置
|
// 计算目标位置:向右移动
|
||||||
let targetPos = this.hero_pos[i - 1] || this.hero_pos[6];
|
let targetPos = this.hero_pos[i - 1];
|
||||||
|
|
||||||
// 使用Tween执行平滑移动
|
// 使用Tween执行平滑移动
|
||||||
tween(this.heroNodes[i])
|
tween(this.heroNodes[i])
|
||||||
@@ -201,14 +208,9 @@ export class HInfoComp extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 延迟创建新节点和删除旧节点,等待动画完成
|
// 延迟重排数组和创建新节点,等待动画完成
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
// 删除原先位于hero_pos[0]位置的节点
|
// 移动数组元素(向前平移)
|
||||||
if (this.heroNodes[0]) {
|
|
||||||
this.heroNodes[0].destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 移动数组元素
|
|
||||||
for (let i = 0; i < 6; i++) {
|
for (let i = 0; i < 6; i++) {
|
||||||
this.heroNodes[i] = this.heroNodes[i + 1];
|
this.heroNodes[i] = this.heroNodes[i + 1];
|
||||||
}
|
}
|
||||||
@@ -227,9 +229,6 @@ export class HInfoComp extends Component {
|
|||||||
}, 300); // 与动画时间保持一致
|
}, 300); // 与动画时间保持一致
|
||||||
}
|
}
|
||||||
|
|
||||||
close(){
|
|
||||||
oops.gui.removeByNode(this.node)
|
|
||||||
}
|
|
||||||
reset() {
|
reset() {
|
||||||
this.node.destroy()
|
this.node.destroy()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user