修复开关门问题

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

View File

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