From 80562f1c975b38c1da286f538d1316a6b5e93f3f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=8C=83=E9=9B=AA=E5=AF=92?=
 <fanxuehan@hejingguodeMacBook-Pro.local>
Date: Thu, 17 Sep 2020 09:38:19 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E4=BA=86=E5=87=A0?=
 =?UTF-8?q?=E4=B8=AA=E5=B7=A5=E5=85=B7=E5=87=BD=E6=95=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 play/assets/tmpGame/script/utils.js | 86 ++++++++++++++++++++++++++++-
 1 file changed, 84 insertions(+), 2 deletions(-)

diff --git a/play/assets/tmpGame/script/utils.js b/play/assets/tmpGame/script/utils.js
index 83ccee9..16e03db 100644
--- a/play/assets/tmpGame/script/utils.js
+++ b/play/assets/tmpGame/script/utils.js
@@ -74,13 +74,31 @@ export async function asyncTweenTo(node, duration, obj, ease = undefined) {
     });
 }
 
-export async function asyncPlayDragonBoneAnimation(node, animationName, time = 1) {
+export async function asyncTweenBy(node, duration, obj, ease = undefined) {
+    return new Promise((resolve, reject) => {
+        cc.tween(node)
+            .by(duration, obj, ease)
+            .call(() => {
+                resolve();
+            })
+            .start();
+    });
+}
+
+export async function asyncPlayDragonBoneAnimation(node, animationName, time = 1, onFrameEvent) {
     return new Promise((resolve, reject) => {
         node.getComponent(dragonBones.ArmatureDisplay)
             .once(dragonBones.EventObject.COMPLETE, () => {
-                console.log('COMPLETE');
                 resolve();
             });
+
+        node.getComponent(dragonBones.ArmatureDisplay)
+            .on(dragonBones.EventObject.FRAME_EVENT, ({ name }) => {
+                if (onFrameEvent && typeof (onFrameEvent) == 'function') {
+                    onFrameEvent(name);
+                }
+            });
+
         node.getComponent(dragonBones.ArmatureDisplay)
             .playAnimation(animationName, time);
     });
@@ -91,6 +109,70 @@ export async function asyncPlayEffectByUrl(url, loop = false) {
         cc.assetManager.loadRemote(url, (err, clip) => {
             console.log(clip);
             cc.audioEngine.playEffect(clip, loop);
+            resolve();
         });
     });
+}
+
+export async function jelly(node) {
+    return new Promise((resolve, reject) => {
+        cc.tween(node)
+            .to(0.1, { scaleX: 0.9, scaleY: 1.1 })
+            .to(0.1, { scaleX: 1.1, scaleY: 0.9 })
+            .to(0.1, { scaleX: 1, scaleY: 1 })
+            .call(resolve)
+            .start();
+    });
+}
+
+export async function asyncDelay(time) {
+    return new Promise((resolve, reject) => {
+        setTimeout(() => {
+            resolve();
+        }, time * 1000);
+    })
+}
+
+
+
+export async function showFireworks(baseNode, nodeList, pos = cc.v2(0, 0), side = cc.v2(0, 100), range = 50, number = 100) {
+    for (let i = 0; i < number; i++) {
+        const node = cc.instantiate(nodeList[RandomInt(nodeList.length)]);
+        node.parent = baseNode;
+        node.active = true;
+        node.x = pos.x;
+        node.y = pos.y;
+        node.angle = 360 * Math.random();
+        node.scale = 0.5;
+
+        const rate = Math.random();
+        const angle = Math.PI * (Math.random() * 2 - 1);
+
+        cc.tween(node)
+            .by(0.3, {
+                x: side.x * rate + Math.cos(angle) * range * rate,
+                y: side.y * rate + Math.sin(angle) * range * rate
+            })
+            .call(async () => {
+                for (let i = 0; i < 8; i++) {
+                    await rabbonFall(node);
+                }
+                cc.tween(node)
+                    .to(0.3, { opacity: 0 })
+                    .call(() => {
+                        node.active = false;
+                        node.parent = null;
+                        node = null;
+                    })
+                    .start();
+            })
+            .by(8, { y: -2000 })
+            .start();
+    }
+}
+
+async function rabbonFall(node) {
+    const time = 1 + Math.random();
+    const offsetX = RandomInt(-200, 200) * time;
+    await asyncTweenBy(node, time, { x: offsetX, angle: offsetX * 60 / 200 });
 }
\ No newline at end of file
-- 
2.21.0