Commit 7bd9d4b7 authored by Tt's avatar Tt

feat(play): 添加倒计时视图根据游戏类型调整位置的功能

parent f521198c
......@@ -210,7 +210,7 @@ export class PlayComponent implements OnInit, OnDestroy {
}
});
}
/**
* 隐藏所有321倒计时相关元素
*/
......@@ -224,15 +224,22 @@ export class PlayComponent implements OnInit, OnDestroy {
}
});
}
/**
* 初始化321倒计时视图
* 创建并初始化倒计时数字元素
*/
init321View() {
/**
* 初始化321倒计时视图
* @param type 游戏类型,'left'表示左侧猫开始玩,'right'表示右侧猫开始玩
*/
init321View(type: string = 'left') {
// 创建倒计时数字元素
const countdownElements = ['dao_ji_shi_3', 'dao_ji_shi_2', 'dao_ji_shi_1'];
// 根据type计算x坐标的偏移量
const xOffset = type === 'left' ? 140 : -140;
countdownElements.forEach(elementName => {
// 检查元素是否已存在
if (!this.g_cartoon.cartoonElementsBuffer[elementName]) {
......@@ -243,22 +250,28 @@ export class PlayComponent implements OnInit, OnDestroy {
// 设置元素缩放
element.ref.scaleX = this.g_mapScale;
element.ref.scaleY = this.g_mapScale;
// 设置元素位置(画面中心)
element.ref.x = this.g_canvasWidth / 2;
element.ref.y = this.g_canvasHeight / 2;
// 设置元素位置(根据type调整画面中心的x坐标)
element.ref.x = this.g_canvasWidth / 2 + xOffset;
element.ref.y = this.g_canvasHeight / 2 + 60 * this.g_mapScale;
// 默认隐藏
element.ref.visible = false;
// 添加到渲染队列
this.render(element.ref, zIndexMap.card + 3);
} else {
// 如果元素已存在,更新其位置
const element = this.g_cartoon.cartoonElementsBuffer[elementName];
element.ref.x = this.g_canvasWidth / 2 + xOffset;
}
});
}
/**
* 显示321倒计时动画
* 依次显示3、2、1的倒计时动画效果
* @param type 游戏类型,'left'表示左侧猫开始玩,'right'表示右侧猫开始玩
*/
show321() {
show321(type: string = 'left') {
// 动画配置参数
const config = {
// 动画时间配置
......@@ -274,13 +287,13 @@ export class PlayComponent implements OnInit, OnDestroy {
finalAlpha: 0.5 // 最终透明度
}
};
// 初始化321倒计时视图
this.init321View();
// 初始化321倒计时视图,传递type参数
this.init321View(type);
// 隐藏所有倒计时元素(确保初始状态是隐藏的)
this.hide321Elements();
// 依次显示3、2、1的倒计时动画
// 先显示3
this.showCountdownNumber('dao_ji_shi_3', config, () => {
......@@ -290,13 +303,15 @@ export class PlayComponent implements OnInit, OnDestroy {
this.showCountdownNumber('dao_ji_shi_1', config, () => {
// 倒计时结束后的操作,等待一段时间后显示VS动画
setTimeout(() => {
this.showVsAni('left');
// this.showVsAni(type);
this.hideVsElements();
this.hide321Elements();
}, config.time.afterComplete * 1000);
});
});
});
}
/**
* 显示单个倒计时数字的动画
* @param elementName 元素名称
......@@ -306,14 +321,14 @@ export class PlayComponent implements OnInit, OnDestroy {
showCountdownNumber(elementName, config, callback) {
// 获取倒计时元素
const element = this.g_cartoon.cartoonElementsBuffer[elementName];
if (element && element.ref) {
// 重置元素状态
element.ref.visible = true;
element.ref.alpha = 1;
element.ref.scaleX = this.g_mapScale;
element.ref.scaleY = this.g_mapScale;
// 先显示数字一段时间,然后再执行放大消失动画
setTimeout(() => {
// 创建放大和透明度变化的动画
......@@ -324,7 +339,7 @@ export class PlayComponent implements OnInit, OnDestroy {
}, config.time.animDuration, () => {
// 动画完成后隐藏元素
element.ref.visible = false;
// 延迟执行回调函数
setTimeout(() => {
if (callback) {
......@@ -425,11 +440,11 @@ export class PlayComponent implements OnInit, OnDestroy {
// this.initListPage();
// 显示321倒计时动画
this.show321();
// 显示VS动画
// this.showVsAni('left');
// 显示321倒计时动画,传递'left'参数表示左侧猫开始玩
// this.show321('left');
// 注释掉直接显示VS动画的代码,因为现在由show321函数在倒计时结束后调用
this.showVsAni('left');
// this.initFishGame();
......@@ -1167,7 +1182,8 @@ export class PlayComponent implements OnInit, OnDestroy {
tweenChange(ju_mao_tou, {
scaleX: this.g_mapScale * config.cat.ju.shrinkRatio,
scaleY: this.g_mapScale * config.cat.ju.shrinkRatio,
x: ju_mao_tou.x - config.cat.ju.moveDistance * this.g_mapScale
x: ju_mao_tou.x - config.cat.ju.moveDistance * this.g_mapScale,
y: ju_mao_tou.y + 95 * this.g_mapScale
}, config.cat.ju.animTime);
// 红色底板向左移动
......@@ -1175,36 +1191,15 @@ export class PlayComponent implements OnInit, OnDestroy {
moveItem(
hong_se_jian_bian_ref,
hong_se_jian_bian_ref.x - config.panel.hong.moveDistance * this.g_mapScale,
hong_se_jian_bian_ref.y,
hong_se_jian_bian_ref.y + 95 * this.g_mapScale,
config.panel.hong.moveTime
);
}
}, config.vs.v.moveTime * 1000 + 500);
setTimeout(() => {
this.show321();
}, 1000);
}, config.vs.v.moveTime * 1000 + 500);
}, config.common.vsAnimDelay);
// 隐藏所有VS相关元素
setTimeout(() => {
// 隐藏红色渐变面板
const hong_se_jian_bian = this.g_cartoon.cartoonElementsBuffer['hong_se_jian_bian'];
if (hong_se_jian_bian && hong_se_jian_bian.ref) {
hong_se_jian_bian.ref.visible = false;
}
// 隐藏蓝色渐变面板
const lan_se_jian_bian = this.g_cartoon.cartoonElementsBuffer['lan_se_jian_bian'];
if (lan_se_jian_bian && lan_se_jian_bian.ref) {
lan_se_jian_bian.ref.visible = false;
}
// 隐藏其他VS元素
const vsElements = ['v', 's', 'ju_mao_tou', 'hui_mao_tou'];
vsElements.forEach(elementName => {
const element = this.g_cartoon.cartoonElementsBuffer[elementName];
if (element && element.ref) {
element.ref.visible = false;
}
});
}, config.common.hideDelay);
}
createCat(type) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment