修复开关门问题

This commit is contained in:
COMPUTER\EDY 2026-06-25 18:53:31 +08:00
parent a09855bd8f
commit 94fe50642a
2 changed files with 43 additions and 44 deletions

View File

@ -222,6 +222,19 @@ export default class Wall extends cc.Component {
toggleReview: boolean = false; toggleReview: boolean = false;
// 开关门状态修正兜底回调(具名箭头函数,便于单独 unschedule不影响组件上其它 schedule
private _lockStateFix = () => {
if (this.openNode && this.openNode.children.length > 0) {
let targetMag = this.open ? 0.01 : 1;
if (this.openNode.children[0]) {
this.openNode.children[0].scaleX = this.openNode.children[0].scaleX < 0 ? -targetMag : targetMag;
}
if (this.openNode.children[1]) {
this.openNode.children[1].scaleX = this.openNode.children[1].scaleX < 0 ? -targetMag : targetMag;
}
}
};
// ============================================ // ============================================
// Cocos生命周期 - start方法 // Cocos生命周期 - start方法
// 在组件第一次激活时调用,通常用于初始化 // 在组件第一次激活时调用,通常用于初始化
@ -784,11 +797,13 @@ export default class Wall extends cc.Component {
// 改变开关门的状态 // 改变开关门的状态
// 功能:切换开关门的开启/关闭状态,并播放对应的动画 // 功能:切换开关门的开启/关闭状态,并播放对应的动画
// 开关门状态: // 开关门状态:
// - open == true门开着scaleX == 1方块可以通过 // - open == true门开着scaleX 接近 0.01方块可以通过
// - open == false门关着scaleX接近0),方块不能通过 // - open == false门关着scaleX == 1),方块不能通过
// 动画说明: // 动画说明:
// - 门的两半leftTween和rightTween会分别播放开启/关闭动画 // - 门的两半leftTween和rightTween会分别播放开启/关闭动画
// - 动画时长0.3秒 // - 动画时长0.3秒
// - 动画目标值直接由 this.open 决定,不依赖"当前 scaleX 的反相"
// 避免短时间内连续切换时目标方向算错(视觉与状态不一致)
// ============================================ // ============================================
changeLock() { changeLock() {
// 切换门的开关状态 // 切换门的开关状态
@ -809,63 +824,47 @@ export default class Wall extends cc.Component {
} }
if (this.openNode.children.length > 0) { if (this.openNode.children.length > 0) {
let fill = 1; // 目标缩放值直接由目标状态 this.open 决定:
if (this.openNode.children[0]) { // open == true -> 0.01open == false -> 1
// 如果门要打开确保scaleX是1如果要关闭确保scaleX接近0 let targetMag = this.open ? 0.01 : 1;
if (this.open == true) {
if (this.openNode.children[0].scaleX < 1 && this.openNode.children[0].scaleX > 0.01) {
this.openNode.children[0].scaleX = 1;
}
}
else {
if (this.openNode.children[0].scaleX < 1 && this.openNode.children[0].scaleX > 0.01) {
this.openNode.children[0].scaleX = 0.01;
}
}
// 计算目标scale值
fill = this.openNode.children[0].scaleX == 1 ? 0.01 : 1;
if (this.openNode.children[0].scaleX < 0) fill = -fill;
}
// 播放左边门的动画 // 播放左边门的动画
if (this.openNode.children[0]) { if (this.openNode.children[0]) {
let cur0 = this.openNode.children[0].scaleX;
let sign0 = cur0 < 0 ? -1 : 1; // 保留镜像方向(门两半可能一正一负)
let target0 = sign0 * targetMag;
this.leftTween = cc.tween(this.openNode.children[0]) this.leftTween = cc.tween(this.openNode.children[0])
.to(0.3, { scaleX: this.openNode.children[0].scaleX < 0 ? -fill : fill }) .to(0.3, { scaleX: target0 })
.call(() => { .call(() => {
this.leftTween = null; // 动画完成后清除引用 this.leftTween = null; // 动画完成后清除引用
if (this.open == true) // 强制对齐到目标值,消除浮点误差
this.openNode.children[0].scaleX = this.openNode.children[0].scaleX < 0 ? -0.01 : 0.01; if (this.openNode && this.openNode.children[0]) {
else this.openNode.children[0].scaleX = target0;
this.openNode.children[0].scaleX = this.openNode.children[0].scaleX < 0 ? -1 : 1; }
}) })
.start(); .start();
} }
// 播放右边门的动画 // 播放右边门的动画
if (this.openNode.children[1]) { if (this.openNode.children[1]) {
let cur1 = this.openNode.children[1].scaleX;
let sign1 = cur1 < 0 ? -1 : 1;
let target1 = sign1 * targetMag;
this.rightTween = cc.tween(this.openNode.children[1]) this.rightTween = cc.tween(this.openNode.children[1])
.to(0.3, { scaleX: this.openNode.children[1].scaleX < 0 ? -fill : fill }) .to(0.3, { scaleX: target1 })
.call(() => { .call(() => {
this.rightTween = null; // 动画完成后清除引用 this.rightTween = null; // 动画完成后清除引用
if (this.open == true) if (this.openNode && this.openNode.children[1]) {
this.openNode.children[1].scaleX = this.openNode.children[1].scaleX < 0 ? -0.01 : 0.01; this.openNode.children[1].scaleX = target1;
else }
this.openNode.children[1].scaleX = this.openNode.children[1].scaleX < 0 ? -1 : 1;
}) })
.start(); .start();
} }
if (this) { // 状态修正兜底0.35s 后强制对齐到 this.open 对应的目标值
this.scheduleOnce(() => { // 先取消上一次还未执行的修正回调,避免堆叠导致状态错乱
if (this.openNode && this.openNode.children.length > 0) { // (使用具名回调单独 unschedule不影响组件上其它 schedule
let targetScaleX = this.open ? 0.01 : 1; this.unschedule(this._lockStateFix);
if (this.openNode.children[0]) { this.scheduleOnce(this._lockStateFix, 0.35);
this.openNode.children[0].scaleX = this.openNode.children[0].scaleX < 0 ? -targetScaleX : targetScaleX;
}
if (this.openNode.children[1]) {
this.openNode.children[1].scaleX = this.openNode.children[1].scaleX < 0 ? -targetScaleX : targetScaleX;
}
}
}, 0.35);
}
} }

View File

@ -302,7 +302,7 @@ export class GameConfig {
vibrateOpen: true, //震动 vibrateOpen: true, //震动
coinnum: 0, //每局的金币数 coinnum: 0, //每局的金币数
paid_user: false, //是否是付费用户 paid_user: false, //是否是付费用户
version: "1.9.88", //版本号 version: "1.9.89", //版本号
shushu_DistinctId: "", //数数访客ID shushu_DistinctId: "", //数数访客ID
shushu_AccountId: "", //数数账号ID shushu_AccountId: "", //数数账号ID
uid: "", //用户和后端唯一id uid: "", //用户和后端唯一id