فهرست منبع

顶部货币动画上传

薛鸿潇 5 سال پیش
والد
کامیت
208d4ac3a1

+ 92 - 66
assets/resources/game/prefab/game.prefab

@@ -30,13 +30,13 @@
         "__id__": 16
       },
       {
-        "__id__": 157
+        "__id__": 159
       },
       {
-        "__id__": 160
+        "__id__": 162
       },
       {
-        "__id__": 169
+        "__id__": 171
       },
       {
         "__id__": 105
@@ -45,14 +45,14 @@
     "_active": true,
     "_components": [
       {
-        "__id__": 171
+        "__id__": 173
       },
       {
-        "__id__": 172
+        "__id__": 174
       }
     ],
     "_prefab": {
-      "__id__": 173
+      "__id__": 175
     },
     "_opacity": 255,
     "_color": {
@@ -528,7 +528,7 @@
       }
     ],
     "_prefab": {
-      "__id__": 156
+      "__id__": 158
     },
     "_opacity": 255,
     "_color": {
@@ -3362,26 +3362,26 @@
     },
     "_children": [
       {
-        "__id__": 141
+        "__id__": 142
       },
       {
-        "__id__": 144
+        "__id__": 145
       },
       {
-        "__id__": 148
+        "__id__": 150
       },
       {
-        "__id__": 151
+        "__id__": 153
       }
     ],
     "_active": true,
     "_components": [
       {
-        "__id__": 154
+        "__id__": 156
       }
     ],
     "_prefab": {
-      "__id__": 155
+      "__id__": 157
     },
     "_opacity": 255,
     "_color": {
@@ -3457,11 +3457,11 @@
     "_active": true,
     "_components": [
       {
-        "__id__": 139
+        "__id__": 140
       }
     ],
     "_prefab": {
-      "__id__": 140
+      "__id__": 141
     },
     "_opacity": 255,
     "_color": {
@@ -4115,20 +4115,20 @@
         "__id__": 127
       },
       {
-        "__id__": 131
+        "__id__": 132
       },
       {
-        "__id__": 134
+        "__id__": 135
       }
     ],
     "_active": true,
     "_components": [
       {
-        "__id__": 137
+        "__id__": 138
       }
     ],
     "_prefab": {
-      "__id__": 138
+      "__id__": 139
     },
     "_opacity": 255,
     "_color": {
@@ -4299,10 +4299,13 @@
       },
       {
         "__id__": 129
+      },
+      {
+        "__id__": 130
       }
     ],
     "_prefab": {
-      "__id__": 130
+      "__id__": 131
     },
     "_opacity": 255,
     "_color": {
@@ -4405,6 +4408,16 @@
     "_id": ""
   },
   {
+    "__type__": "88626F5Zl9BIKjmKaYlyRWH",
+    "_name": "",
+    "_objFlags": 0,
+    "node": {
+      "__id__": 127
+    },
+    "_enabled": true,
+    "_id": ""
+  },
+  {
     "__type__": "cc.PrefabInfo",
     "root": {
       "__id__": 1
@@ -4426,11 +4439,11 @@
     "_active": true,
     "_components": [
       {
-        "__id__": 132
+        "__id__": 133
       }
     ],
     "_prefab": {
-      "__id__": 133
+      "__id__": 134
     },
     "_opacity": 255,
     "_color": {
@@ -4484,7 +4497,7 @@
     "_name": "",
     "_objFlags": 0,
     "node": {
-      "__id__": 131
+      "__id__": 132
     },
     "_enabled": true,
     "_materials": [
@@ -4533,11 +4546,11 @@
     "_active": true,
     "_components": [
       {
-        "__id__": 135
+        "__id__": 136
       }
     ],
     "_prefab": {
-      "__id__": 136
+      "__id__": 137
     },
     "_opacity": 255,
     "_color": {
@@ -4591,7 +4604,7 @@
     "_name": "",
     "_objFlags": 0,
     "node": {
-      "__id__": 134
+      "__id__": 135
     },
     "_enabled": true,
     "_materials": [
@@ -4705,11 +4718,11 @@
     "_active": true,
     "_components": [
       {
-        "__id__": 142
+        "__id__": 143
       }
     ],
     "_prefab": {
-      "__id__": 143
+      "__id__": 144
     },
     "_opacity": 255,
     "_color": {
@@ -4763,7 +4776,7 @@
     "_name": "",
     "_objFlags": 0,
     "node": {
-      "__id__": 141
+      "__id__": 142
     },
     "_enabled": true,
     "_materials": [
@@ -4812,14 +4825,17 @@
     "_active": true,
     "_components": [
       {
-        "__id__": 145
+        "__id__": 146
       },
       {
-        "__id__": 146
+        "__id__": 147
+      },
+      {
+        "__id__": 148
       }
     ],
     "_prefab": {
-      "__id__": 147
+      "__id__": 149
     },
     "_opacity": 255,
     "_color": {
@@ -4873,7 +4889,7 @@
     "_name": "",
     "_objFlags": 0,
     "node": {
-      "__id__": 144
+      "__id__": 145
     },
     "_enabled": true,
     "_materials": [
@@ -4908,7 +4924,7 @@
     "_name": "",
     "_objFlags": 0,
     "node": {
-      "__id__": 144
+      "__id__": 145
     },
     "_enabled": true,
     "_color": {
@@ -4922,6 +4938,16 @@
     "_id": ""
   },
   {
+    "__type__": "88626F5Zl9BIKjmKaYlyRWH",
+    "_name": "",
+    "_objFlags": 0,
+    "node": {
+      "__id__": 145
+    },
+    "_enabled": true,
+    "_id": ""
+  },
+  {
     "__type__": "cc.PrefabInfo",
     "root": {
       "__id__": 1
@@ -4943,11 +4969,11 @@
     "_active": true,
     "_components": [
       {
-        "__id__": 149
+        "__id__": 151
       }
     ],
     "_prefab": {
-      "__id__": 150
+      "__id__": 152
     },
     "_opacity": 255,
     "_color": {
@@ -5001,7 +5027,7 @@
     "_name": "",
     "_objFlags": 0,
     "node": {
-      "__id__": 148
+      "__id__": 150
     },
     "_enabled": true,
     "_materials": [
@@ -5050,11 +5076,11 @@
     "_active": true,
     "_components": [
       {
-        "__id__": 152
+        "__id__": 154
       }
     ],
     "_prefab": {
-      "__id__": 153
+      "__id__": 155
     },
     "_opacity": 255,
     "_color": {
@@ -5108,7 +5134,7 @@
     "_name": "",
     "_objFlags": 0,
     "node": {
-      "__id__": 151
+      "__id__": 153
     },
     "_enabled": true,
     "_materials": [
@@ -5193,11 +5219,11 @@
     "_active": true,
     "_components": [
       {
-        "__id__": 158
+        "__id__": 160
       }
     ],
     "_prefab": {
-      "__id__": 159
+      "__id__": 161
     },
     "_opacity": 255,
     "_color": {
@@ -5251,7 +5277,7 @@
     "_name": "",
     "_objFlags": 0,
     "node": {
-      "__id__": 157
+      "__id__": 159
     },
     "_enabled": true,
     "_materials": [
@@ -5308,20 +5334,20 @@
     },
     "_children": [
       {
-        "__id__": 161
+        "__id__": 163
       }
     ],
     "_active": true,
     "_components": [
       {
-        "__id__": 165
+        "__id__": 167
       },
       {
-        "__id__": 167
+        "__id__": 169
       }
     ],
     "_prefab": {
-      "__id__": 168
+      "__id__": 170
     },
     "_opacity": 255,
     "_color": {
@@ -5375,20 +5401,20 @@
     "_name": "Background",
     "_objFlags": 512,
     "_parent": {
-      "__id__": 160
+      "__id__": 162
     },
     "_children": [],
     "_active": true,
     "_components": [
       {
-        "__id__": 162
+        "__id__": 164
       },
       {
-        "__id__": 163
+        "__id__": 165
       }
     ],
     "_prefab": {
-      "__id__": 164
+      "__id__": 166
     },
     "_opacity": 255,
     "_color": {
@@ -5442,7 +5468,7 @@
     "_name": "",
     "_objFlags": 0,
     "node": {
-      "__id__": 161
+      "__id__": 163
     },
     "_enabled": true,
     "_materials": [
@@ -5474,7 +5500,7 @@
     "_name": "",
     "_objFlags": 0,
     "node": {
-      "__id__": 161
+      "__id__": 163
     },
     "_enabled": true,
     "alignMode": 0,
@@ -5512,7 +5538,7 @@
     "_name": "",
     "_objFlags": 0,
     "node": {
-      "__id__": 160
+      "__id__": 162
     },
     "_enabled": true,
     "_normalMaterial": null,
@@ -5521,7 +5547,7 @@
     "zoomScale": 1.2,
     "clickEvents": [
       {
-        "__id__": 166
+        "__id__": 168
       }
     ],
     "_N$interactable": true,
@@ -5589,7 +5615,7 @@
       "__uuid__": "29158224-f8dd-4661-a796-1ffab537140e"
     },
     "_N$target": {
-      "__id__": 161
+      "__id__": 163
     },
     "_id": ""
   },
@@ -5608,7 +5634,7 @@
     "_name": "",
     "_objFlags": 0,
     "node": {
-      "__id__": 160
+      "__id__": 162
     },
     "_enabled": true,
     "_defaultClip": {
@@ -5640,7 +5666,7 @@
       "__id__": 1
     },
     "_prefab": {
-      "__id__": 170
+      "__id__": 172
     },
     "_name": "游戏核心",
     "_active": false,
@@ -5671,7 +5697,7 @@
   {
     "__type__": "cc.PrefabInfo",
     "root": {
-      "__id__": 169
+      "__id__": 171
     },
     "asset": {
       "__uuid__": "4c49ec9e-c64a-4921-84eb-9bdd737656e5"
@@ -5688,7 +5714,7 @@
     },
     "_enabled": true,
     "node_gameplay": {
-      "__id__": 169
+      "__id__": 171
     },
     "node_btn": {
       "__id__": 16
@@ -5697,16 +5723,16 @@
       "__id__": 118
     },
     "lbl_redMoney": {
-      "__id__": 145
+      "__id__": 146
     },
     "lbl_rmb": {
       "__id__": 128
     },
     "btn_cashOutNormal": {
-      "__id__": 152
+      "__id__": 154
     },
     "btn_cashOutGold": {
-      "__id__": 135
+      "__id__": 136
     },
     "btn_getRed1": {
       "__id__": 9
@@ -5718,13 +5744,13 @@
       "__id__": 13
     },
     "btn_start": {
-      "__id__": 165
+      "__id__": 167
     },
     "icon_hb": {
-      "__id__": 148
+      "__id__": 150
     },
     "icon_zb": {
-      "__id__": 131
+      "__id__": 132
     },
     "node_top_ui": {
       "__id__": 104

+ 78 - 0
assets/script/game/component/NumberAnim.ts

@@ -0,0 +1,78 @@
+
+const { ccclass, property } = cc._decorator;
+/**
+ * 数字跳动动画
+ * @author 薛鸿潇
+ */
+@ccclass
+export default class NumberAnim extends cc.Component {
+
+    /** 动画目标 */
+    private lbl_count: cc.Label = null;
+    onLoad() {
+        this.lbl_count = this.node.getComponent(cc.Label) || this.node.addComponent(cc.Label);
+    }
+
+    /**
+     * 设置数值
+     * @param new_value 目标值
+     */
+    public setValue(new_value: number) {
+        let time = new_value - this.targetProgress;
+        this.targetProgress = new_value;
+        this.PlayMoneyAni(0.3)
+    }
+
+    //////////////////////////////////数字滚动效果//////////////////////////////////
+    /** 滚动的目标值 */
+    private targetProgress: number = 0;
+
+    private delta: number = 0;
+    /** 滚动中的数字 */
+    private curValue: number = 0;
+    private curTime: number = 0;
+    private totalTime: number = 0;
+    /** 上次值 */
+    private lastNum: number = 0;
+    /** 动画中 */
+    private isPlayAni: boolean = false;
+
+    private PlayMoneyAni(time) {
+        this.totalTime = time;
+        this.delta = (this.targetProgress - this.lastNum) / time;
+        this.curValue = this.lastNum;
+        this.curTime = 0;
+        // console.log("--->Update Time: " + time + " delta: " + this.delta + " curValue: " + this.curValue + " lastNum: " + this.lastNum);
+        this.isPlayAni = true;
+    }
+
+    private PlayMoneyAniUpdate(dt) {
+        if (this.isPlayAni) {
+            if (this.curTime < this.totalTime) {
+                this.curTime += dt;
+                this.curValue += this.delta * dt;
+                if (this.curValue >= this.targetProgress) {
+                    this.isPlayAni = false;
+                    this.curValue = this.targetProgress;
+                    this.lastNum = this.targetProgress;
+                }
+                // console.log("-->CurValue:" + this.curValue);
+            } else {
+                this.isPlayAni = false;
+                this.curTime = this.totalTime;
+                //this.unschedule(this.UpdateAni);
+                this.curValue = this.targetProgress;
+                this.lastNum = this.targetProgress;
+            }
+            if (this.curValue == this.targetProgress) {
+                this.lbl_count.string = `${this.targetProgress}`;
+            } else {
+                this.lbl_count.string = `${this.curValue.toFixed(0)}`;
+            }
+        }
+    }
+
+    update(dt) {
+        this.PlayMoneyAniUpdate(dt);
+    }
+}

+ 9 - 0
assets/script/game/component/NumberAnim.ts.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.8",
+  "uuid": "88626179-665f-4120-a8e6-29a625c91587",
+  "isPlugin": false,
+  "loadPluginInWeb": true,
+  "loadPluginInNative": true,
+  "loadPluginInEditor": false,
+  "subMetas": {}
+}

+ 24 - 0
assets/script/game/data/module/RewardData.ts

@@ -43,5 +43,29 @@ export class RewardData extends Data {
                 gData.gameData.gameData.piggyBank += gData.reward.data[i].rewardNum;
             }
         }
+        gData.reward.data = [];
+    }
+
+    public flyCoinAnim() {
+        if (!gData.reward.data || !gData.reward.data.length) return;
+        let is_add_money = true;
+        const i_count = gData.reward.data.length;
+        for (let i = 0; i < i_count; i++) {
+            let target_node = gData.gameData.gameStyle.icon_hb;
+            if (gData.reward.data[i].rewardType == RewardType.redBag) {
+                target_node = gData.gameData.gameStyle.icon_hb;
+            } else if (gData.reward.data[i].rewardType == RewardType.rmb) {
+                // target_node = gData.gameData.gameStyle.icon_zb;
+            } else if (gData.reward.data[i].rewardType == RewardType.pigRmb) {
+                target_node = gData.gameData.gameStyle.icon_zb;
+            }
+            const end_world_pos = target_node.parent.convertToWorldSpaceAR(target_node.getPosition());
+            const end_node_pos = gData.gameData.gameStyle.node.parent.convertToNodeSpaceAR(end_world_pos);
+            let start_node_pos = new cc.Vec2(0, -300);
+            mk.fly.PlayCoinAnim(gData.reward.data[0].rewardType, 10, start_node_pos, end_world_pos, () => {
+                is_add_money && this.addReward();
+            })
+        }
+
     }
 }

+ 11 - 1
assets/script/game/game/Game.ts

@@ -51,7 +51,7 @@ export default class Game extends cc.Component {
     }
     update() {
         if (gData.gameData.init_coin) {
-            this.initInfo();
+            this.runMoneyAnim();
         }
 
         if (gData.gameData.init_head) {
@@ -96,6 +96,16 @@ export default class Game extends cc.Component {
         this.img_head.spriteFrame = new cc.SpriteFrame(result);
     }
 
+    
+    /**
+     * 货币变更动画
+     */
+     private runMoneyAnim() {
+        this.lbl_redMoney.getComponent('NumberAnim').setValue(gData.gameData.gameData.redMoney);
+        this.lbl_rmb.getComponent('NumberAnim').setValue(gData.gameData.gameData.piggyBank);
+        // gData.gameData.init_coin = false;
+    }
+
     //测试道具获取效果
     private testFly() {
         mk.fly.PlayCoinAnim(1, 20, cc.v2(0, -300), cc.v2(0, 0));

+ 4 - 2
assets/script/game/module/pigBank/PigBank.ts

@@ -23,11 +23,13 @@ export default class PigBank extends cc.Component {
     start() {
         this.initCashDesc();
         mk.audio.playEffect("pigBank", false);
-        // let target_node = gData.gameData.gameStyle.icon_zb;
+        // let target_node = gData.gameData.gameStyle.icon_hb;
         // const end_world_pos = target_node.parent.convertToWorldSpaceAR(target_node.getPosition());
         // const end_node_pos = gData.gameData.gameStyle.node.parent.convertToNodeSpaceAR(end_world_pos);
         // let start_node_pos = new cc.Vec2(0, -300);
-        // mk.fly.PlayCoinAnim(3, 10, start_node_pos, end_node_pos);
+        // mk.fly.PlayCoinAnim(1, 10, start_node_pos, end_node_pos, () => {
+        //     if (!gData.gameData.init_coin) gData.gameData.gameData.redMoney = 1234
+        // });
     }
 
     update(dt) {

+ 6 - 22
assets/script/game/module/reward/Reward.ts

@@ -139,6 +139,9 @@ export default class Reward extends cc.Component {
                 }
             });
         }
+        gData.reward.adData = {}
+        gData.reward.adData.videoRedMoney = {}
+        gData.reward.adData.videoRedMoney.videoRewardList = [{ rewardType: 3, rewardNum: 1000 }, { rewardType: 1, rewardNum: 1000 }]// 测试数据
     }
 
     /**
@@ -147,6 +150,7 @@ export default class Reward extends cc.Component {
     private async watchVideoCall() {
         if (gData.reward.adData) {
             // 气泡视频奖励 通关视频奖励 
+            gData.reward.adData.videoRedMoney.videoRewardList = [{ rewardType: 3, rewardNum: 1000 }, { rewardType: 1, rewardNum: 1000 }]// 测试数据
             gData.reward.data = gData.reward.adData.videoRedMoney.videoRewardList;
         }
         if (!gData.reward.data || !gData.reward.data.length) return;
@@ -164,7 +168,7 @@ export default class Reward extends cc.Component {
                 }
             }
         }
-        
+
         // 图标展示
         if (gData.reward.data[0].rewardType === RewardType.redBag) {
             this.node_coin.spriteFrame = await mk.loader.load('game/texture/coin/' + RewardType.redBag, cc.SpriteFrame);
@@ -190,9 +194,7 @@ export default class Reward extends cc.Component {
      */
     private clickGetReward() {
         cc.log('获取奖励:', gData.reward.data);
-        gData.reward.addReward();
-        this.flyCoinAnim();
-        gData.reward.data = [];
+        gData.reward.flyCoinAnim();
     }
 
     /**
@@ -203,24 +205,6 @@ export default class Reward extends cc.Component {
         mk.ui.openPanel(path);
     }
 
-    /**
-     * 飞coin动画
-     */
-    private flyCoinAnim() {
-        if (!gData.reward.data || !gData.reward.data.length) return;
-        let target_node = gData.gameData.gameStyle.icon_hb;
-        if (gData.reward.data[0].rewardType == RewardType.redBag) {
-            target_node = gData.gameData.gameStyle.icon_hb;
-        } else if (gData.reward.data[0].rewardType == RewardType.rmb) {
-            // target_node = gData.gameData.gameStyle.icon_zb;
-        } else if (gData.reward.data[0].rewardType == RewardType.pigRmb) {
-            target_node = gData.gameData.gameStyle.icon_zb;
-        }
-        const end_world_pos = target_node.parent.convertToWorldSpaceAR(target_node.getPosition());
-        const end_node_pos = gData.gameData.gameStyle.node.parent.convertToNodeSpaceAR(end_world_pos);
-        let start_node_pos = new cc.Vec2(0, -300);
-        mk.fly.PlayCoinAnim(gData.reward.data[0].rewardType, 10, start_node_pos, end_node_pos)
-    }
 
     /**
      * 下一关操作

+ 5 - 2
assets/script/mk/system/FlySystem.ts

@@ -10,6 +10,7 @@ export default class FlySystem extends cc.Component {
         mk.fly = this;
     }
 
+    private is_new_cb = true;
     /**
      * @param type 类型 道具id  10001,10002
      * @param num 特效数量
@@ -34,6 +35,7 @@ export default class FlySystem extends cc.Component {
 
             this.FlyIn(type, copyCoin, initPos, endpos, item_cb);
         }
+        this.is_new_cb = true;
     }
 
     private FlyIn(type: number, target: cc.Node, end: cc.Vec2, endpos: cc.Vec2 | string = null, item_cb: Function = null) {
@@ -72,9 +74,10 @@ export default class FlySystem extends cc.Component {
                 }
 
                 if (item_cb != null) {
-                    item_cb();
-                    this.iconScale(type);
+                    this.is_new_cb && item_cb();
+                    this.is_new_cb = false;
                 }
+                this.iconScale(type);
             })
             .start();
     }