Commit 70cb1247 authored by Tt's avatar Tt

1

parent c6b67d95
......@@ -965,23 +965,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
.start();
})
}
/**
* 播放本地音频
* @param audioName 音频资源名称
......@@ -998,130 +981,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
cc.audioEngine.setFinishCallback(id, () => { resolve(id); });
})
}
// private intervalId;
// private playLaba() {
// let btn_kaba2 = this.btn_laba.getChildByName("btn_laba2");
// let btn_kaba3 = this.btn_laba.getChildByName("btn_laba3");
// btn_kaba2.active = true;
// btn_kaba3.active = true;
// let count = 0;
// if (this.intervalId) clearInterval(this.intervalId);
// let stop = false;
// this.intervalId = setInterval(() => {
// count++;
// btn_kaba2.active = count % 3 == 1;
// btn_kaba3.active = count % 3 == 2;
// if (stop && count % 3 == 2) clearInterval(this.intervalId);
// }, 150)
// pg.audio.playAudioByUrl(Game.getIns().getCurrentPage().audio, (() => {
// stop = true;
// }))
// }
/**
* 在指定位置显示一组烟花效果
* @param pos 烟花位置
* @param parentNode 父节点
* @param nodeList 烟花节点列表
*/
async showOneFirework(pos, parentNode, nodeList) {
// 连续显示3次烟花效果,每次间隔0.1秒
for (let i = 0; i < 3; i++) {
this.showFirework(pos, parentNode, nodeList, 200, 200, 25);
await asyncDelay(0.1);
}
}
/**
* 显示烟花粒子效果
* @param pos 烟花位置
* @param parentNode 父节点
* @param nodeList 烟花节点列表
* @param width 水平扩散宽度
* @param height 垂直扩散高度
* @param number 粒子数量
*/
showFirework(pos, parentNode, nodeList, width = 200, height = 500, number = 30) {
// 创建指定数量的粒子
for (let i = 0; i < number; i++) {
// 创建单个粒子
const quad = this.createQuads(pos, parentNode, nodeList);
// 随机生成目标位置
const targetX = RandomInt(width / 2, -width / 2);
const targetY = RandomInt(height);
// 水平移动动画
cc.tween(quad)
.by(0.5, { x: targetX }) // 初始水平移动
.by(3, { x: targetX * 2 }) // 继续水平移动
.start();
// 垂直移动动画(先上升后下落)
cc.tween(quad)
.by(0.5, { y: targetY }, { easing: 'quadOut' }) // 上升减速
.to(4, { y: -parentNode.height * 2 }, { easing: 'quadIn' }) // 下落加速
.removeSelf() // 移除自身
.start();
// 淡出动画
cc.tween(quad)
.delay(1) // 延迟1秒后开始淡出
.to(0.5 + 1 * Math.random(), { opacity: 0 }) // 随机淡出时间
.start();
}
}
/**
* 创建烟花粒子
* @param pos 初始位置
* @param parentNode 父节点
* @param nodeList 粒子模板列表
* @returns 创建的粒子节点
*/
createQuads(pos, parentNode, nodeList) {
// 从模板列表中随机选择一个克隆
const quadBase = cc.instantiate(nodeList[RandomInt(nodeList.length)]);
// 设置初始位置和角度
quadBase.x = pos.x;
quadBase.y = pos.y + 30;
quadBase.z = pos.z;
quadBase.angle = RandomInt(180); // 随机旋转角度
quadBase.parent = parentNode;
// 设置内部四边形的位置和角度
const quad = quadBase.getChildByName('quad');
quad.x = 0;
quad.y = 0;
quad.angle = RandomInt(180); // 随机旋转角度
// 设置纸片的缩放比例
const paper = quad.getChildByName('paper');
paper.scaleX = Math.random() * 0.8 + 0.2; // 随机宽度缩放
paper.scaleY = Math.random() * 0.8 + 0.2; // 随机高度缩放
// 设置基础节点的初始缩放和动画
quadBase.scaleX = Math.random();
cc.tween(quadBase)
// 先缩放到正常大小
.to((1 - quadBase.scaleX) * 0.3, { scaleX: 1 })
.call(() => {
// 然后创建左右翻转的循环动画
const time = Math.random() * 0.2;
cc.tween(quadBase)
.to(0.1 + time, { scaleX: -1 }) // 翻转到负向
.to(0.1 + time, { scaleX: 1 }) // 翻转回正向
.union() // 合并为一个动作
.repeatForever() // 无限循环
.start();
})
.start();
return quadBase;
}
}
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