修改特效展示

This commit is contained in:
huanghaipeng 2025-11-13 19:05:41 +08:00
parent 28b648bc9d
commit 6357fa0c35

View File

@ -165,6 +165,11 @@ export default class MapConroler extends cc.Component {
// mapInfo: number[][] = [];
getProgressLevel: number = 0;
getProgress: number = 0;
private magicEffectIndex: number = 0;
private magicEffect1: cc.Node = null; // 第一套特效节点
private magicEffect2: cc.Node = null; // 第二套特效节点
onLoad() {
MiniGameSdk.API.setNewCloudlevel();
@ -3114,6 +3119,22 @@ export default class MapConroler extends cc.Component {
}
}
initMagicEffects() {
// 初始化两个特效节点,如果还没有创建的话
if (!this.magicEffect1) {
this.magicEffect1 = this.magics; // 第一个特效使用原来的节点
}
if (!this.magicEffect2) {
// 创建第二个特效节点,复制第一个的结构
this.magicEffect2 = cc.instantiate(this.magics);
this.magicEffect2.parent = this.magics.parent;
// 确保第二个特效初始状态是隐藏的
this.magicEffect2.active = false;
this.magicEffect2.setPosition(this.magics.position);
}
}
//使用魔法棒随机消除两个方块
useMagic() {
if (this.gameOver == true || this.gameWin == true) {
@ -3173,10 +3194,19 @@ export default class MapConroler extends cc.Component {
magicBtn.getComponent("btnControl").setTouch(true);
}, 1000);
// 初始化两个特效节点
this.initMagicEffects();
//魔法棒
this.ismagic = true;
this.magics.active = true;
this.magics.scale = 1;
// 根据索引选择要使用的特效节点
const currentEffect = this.magicEffectIndex % 2 === 0 ? this.magicEffect1 : this.magicEffect2;
this.magicEffectIndex = (this.magicEffectIndex + 1) % 2; // 更新索引
currentEffect.active = true;
currentEffect.scale = 1;
const path = [
{
"x": -522.8444229452174,
@ -3431,42 +3461,46 @@ export default class MapConroler extends cc.Component {
const smoothPts = this.getSmoothPath(pts, 10); //
// this.magics.setPosition(smoothPts[0]);
let totalLen = 0;
let lens: number[] = [];
// 1. 先把节点/粒子立即隐藏并复位
this.magics.stopAllActions(); // 立即停止旧动画
this.magics.setPosition(smoothPts[0]); // 必须在一开始就先放到起点
this.magics.active = true; // 保证节点可见
this.magics.children[0].children[2].active = false; // 先关粒子
this.magics.children[0].children[3].active = false;
currentEffect.stopAllActions(); // 立即停止旧动画
currentEffect.setPosition(smoothPts[0]); // 必须在一开始就先放到起点
// 获取粒子系统组件
const particle1 = currentEffect.children[0].children[2];
const particle2 = currentEffect.children[0].children[3];
const p1 = particle1.getComponent(cc.ParticleSystem);
const p2 = particle2.getComponent(cc.ParticleSystem);
// 先关闭所有粒子显示
particle1.active = false;
particle2.active = false;
p1 && p1.stopSystem(); // true 表示立即清零
p2 && p2.stopSystem();
for (let i = 1; i < smoothPts.length; i++) {
const len = smoothPts[i].sub(smoothPts[i - 1]).mag();
lens.push(len);
totalLen += len;
}
// 1. 立即停止并清零粒子
const p1 = this.magics.children[0].children[2].getComponent(cc.ParticleSystem);
const p2 = this.magics.children[0].children[3].getComponent(cc.ParticleSystem);
p1 && p1.stopSystem(); // true 表示立即清零
p2 && p2.stopSystem();
// 2. 把节点放到起点
this.magics.stopAllActions();
this.magics.setPosition(smoothPts[0]);
currentEffect.stopAllActions();
currentEffect.setPosition(smoothPts[0]);
// 3. 下一帧再重新播放
this.scheduleOnce(() => {
p1 && p1.resetSystem(); // 重置到初始状态再播放
p2 && p2.resetSystem();
this.magics.children[0].children[2].active = true;
this.magics.children[0].children[3].active = true;
particle1.active = true;
particle2.active = true;
// 4. tween 动画
let t = cc.tween(this.magics);
let t = cc.tween(currentEffect);
for (let i = 1; i < smoothPts.length; i++) {
const segDur = totalDur * (lens[i - 1] / totalLen);
t = t.to(segDur, { position: smoothPts[i] });
@ -3474,12 +3508,12 @@ export default class MapConroler extends cc.Component {
t.delay(0.5).call(() => {
p1 && p1.stopSystem(); // 结束后再停
p2 && p2.stopSystem();
this.magics.children[0].children[2].active = false;
this.magics.children[0].children[3].active = false;
particle1.active = false;
particle2.active = false;
}).to(0.15, { scale: 0 })
.call(() => {
this.magics.setPosition(-900, -700, 0);
this.magics.active = false;
currentEffect.setPosition(-900, -700, 0);
currentEffect.active = false;
})
.start();
}, 0);