Commit a32793c9 authored by 范雪寒's avatar 范雪寒

feat: 修改烟花效果

parent 80562f1c
...@@ -133,46 +133,63 @@ export async function asyncDelay(time) { ...@@ -133,46 +133,63 @@ export async function asyncDelay(time) {
}) })
} }
export async function showFireworks(baseNode, nodeList, pos = cc.v2(0, 0), side = cc.v2(0, 100), range = 50, number = 100) {
new Array(number).fill(' ').forEach(async (_, i) => {
let rabbonNode = new cc.Node();
rabbonNode.parent = baseNode;
rabbonNode.x = pos.x;
rabbonNode.y = pos.y;
rabbonNode.angle = 60 * Math.random() - 30;
export async function showFireworks(baseNode, nodeList, pos = cc.v2(0, 0), side = cc.v2(0, 100), range = 50, number = 100) { let node = cc.instantiate(nodeList[RandomInt(nodeList.length)]);
for (let i = 0; i < number; i++) { node.parent = rabbonNode;
const node = cc.instantiate(nodeList[RandomInt(nodeList.length)]);
node.parent = baseNode;
node.active = true; node.active = true;
node.x = pos.x; node.x = 0;
node.y = pos.y; node.y = 0;
node.angle = 360 * Math.random(); node.angle = 0;
node.scale = 0.5;
const rate = Math.random(); const rate = Math.random();
const angle = Math.PI * (Math.random() * 2 - 1); const angle = Math.PI * (Math.random() * 2 - 1);
await asyncTweenBy(rabbonNode, 0.3, {
x: side.x * rate + Math.cos(angle) * range * rate,
y: side.y * rate + Math.sin(angle) * range * rate
}, {
easing: 'quadIn'
});
cc.tween(rabbonNode)
.by(8, { y: -2000 })
.start();
rabbonFall(rabbonNode);
await asyncDelay(Math.random());
cc.tween(node) cc.tween(node)
.by(0.3, { .by(0.15, { x: -10, angle: -10 })
x: side.x * rate + Math.cos(angle) * range * rate, .by(0.3, { x: 20, angle: 20 })
y: side.y * rate + Math.sin(angle) * range * rate .by(0.15, { x: -10, angle: -10 })
}) .union()
.call(async () => { .repeatForever()
for (let i = 0; i < 8; i++) { .start();
await rabbonFall(node);
} cc.tween(rabbonNode)
cc.tween(node) .delay(5)
.to(0.3, { opacity: 0 }) .to(0.3, { opacity: 0 })
.call(() => { .call(() => {
node.active = false; node.stopAllActions();
node.parent = null; node.active = false;
node = null; node.parent = null;
}) node = null;
.start();
}) })
.by(8, { y: -2000 })
.start(); .start();
} });
} }
async function rabbonFall(node) { async function rabbonFall(node) {
const time = 1 + Math.random(); const time = 1 + Math.random();
const offsetX = RandomInt(-200, 200) * time; const offsetX = RandomInt(-200, 200) * time;
await asyncTweenBy(node, time, { x: offsetX, angle: offsetX * 60 / 200 }); await asyncTweenBy(node, time, { x: offsetX, angle: offsetX * 60 / 200 });
rabbonFall(node);
} }
\ No newline at end of file
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