修复开关门问题
This commit is contained in:
parent
a09855bd8f
commit
94fe50642a
|
|
@ -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.01;open == 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() {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user