Przeglądaj źródła

修改道具显示逻辑

SunnyLinSD 6 lat temu
rodzic
commit
5f59873b4d

+ 1 - 1
assets/scripts/levelHome/LevelHome.js

@@ -278,7 +278,7 @@ cc.Class({
 
                 if (buildingItems.hasOwnProperty(buildingId)) {
                     let prop = buildingItems[buildingId];
-                    itemScript.configProp(prop);
+                    itemScript.showProp(prop, false);
                 }
             }
         })

+ 22 - 5
assets/scripts/levelHome/LevelHomeItem.js

@@ -242,6 +242,9 @@ cc.Class({
         // 配置界面上的金币
         this.configCoins();
 
+        // 配置界面上的道具
+        this.configProp();
+
     },
 
     onDestroy() {
@@ -379,19 +382,33 @@ cc.Class({
         }
     },
 
-    configProp(propData) {
+    configProp() {
+
+        let propNode = cc.instantiate(this.propPrefab)
+        this.propScript = propNode.getComponent('LevelHomePropItem')
+        this.propWrap.addChild(propNode);  
+        this.propScript.node.position = cc.v2(150, -108);
+        this.propScript.node.active = false;
+        this.propScript.isPlay = false;
+        this.propScript.isPlaying = false;
+    },
+
+    showProp(propData, isPlayAnimation=true) {
 
         if (!this.isHasProp) {
-            let propNode = cc.instantiate(this.propPrefab)
-            this.propScript = propNode.getComponent('LevelHomePropItem')
             this.isHasProp = true;
             this.propScript.init(this.buildingInfo.buildingId, propData, () => {
                 this.propScript = null;
                 this.isHasProp = false; 
             });
-            this.propWrap.addChild(propNode);  
+            if (isPlayAnimation) {
+                this.propScript.showAnimation();
+            } else {
+                this.propScript.node.position = cc.v2(150, -28);
+            }
         } else {
-            this.propScript.updateProp(propData)
+            this.propScript.updateProp(propData);
+            this.propScript.updateAnimation();
         }
     },
 

+ 3 - 3
assets/scripts/levelHome/LevelHomePropItem.js

@@ -34,13 +34,13 @@ cc.Class({
     // LIFE-CYCLE CALLBACKS:
     onLoad () {
 
-        this.node.y = -26;
-        this.node.x = 150;
+        // this.node.y = -26;
+        // this.node.x = 150;
 
         this.node.on(cc.Node.EventType.TOUCH_END, _.debounce(() => {
             HomeApi.itemCollect(this.buildingId, () => {
 
-                
+
                 this.pickupCallback();
                 this.node.destroy();
             }, (err) => {