Przeglądaj źródła

【BUG】修改自动消除展示位置不对问题

mojunshou 7 miesięcy temu
rodzic
commit
f5284a32ff

+ 29 - 0
assets/bundle/gui/eliminate/config/GridConfig.json

@@ -185,6 +185,35 @@
                     "column": -1
                 }
             ]
+        },
+        "BrickII": {
+            "rotateFlag": true,
+            "gridConfig": [
+                {
+                    "row": 0,
+                    "column": 0
+                },
+                {
+                    "row": 0,
+                    "column": 1
+                },
+                {
+                    "row": 0,
+                    "column": 2
+                },
+                {
+                    "row": 1,
+                    "column": 0
+                },
+                {
+                    "row": 1,
+                    "column": 1
+                },
+                {
+                    "row": 1,
+                    "column": 2
+                }
+            ]
         }
     }
 }

+ 1 - 3
assets/bundle/gui/eliminate/eliminate.prefab

@@ -6197,7 +6197,7 @@
     "_paddingBottom": 0,
     "_spacingX": 0,
     "_spacingY": 0,
-    "_verticalDirection": 1,
+    "_verticalDirection": 0,
     "_horizontalDirection": 0,
     "_constraint": 0,
     "_constraintNum": 2,
@@ -6218,8 +6218,6 @@
       "__id__": 0
     },
     "fileId": "8djaLKMGJGWKF9SshoBS23",
-    "instance": null,
-    "targetOverrides": null,
     "nestedPrefabInstanceRoots": null
   },
   {

+ 13 - 23
assets/script/game/view/EliminateViewComp.ts

@@ -2,7 +2,7 @@
  * @Author: mojunshou 1637302775@qq.com
  * @Date: 2025-03-20 15:01:09
  * @LastEditors: mojunshou 1637302775@qq.com
- * @LastEditTime: 2025-04-17 14:25:57
+ * @LastEditTime: 2025-04-17 15:58:53
  * @Description: 消除游戏主场景
  */
 import { _decorator, Button, Color, EventTouch, instantiate, JsonAsset, Label, Node, Prefab, randomRangeInt, Sprite, tween, UITransform, Vec2, Vec3, Widget } from "cc";
@@ -149,7 +149,7 @@ export class EliminateViewComp extends CCComp {
     private callback: Function | null = null; //回调函数
 
     //tween时间控制变量
-    private autoMoveTime: number = 2;
+    private autoMoveTime: number = 0.4;
 
 
 
@@ -686,10 +686,9 @@ export class EliminateViewComp extends CCComp {
 
 
     addBrick(index: number) {
-        //随机名字
-        const brickKey = Object.keys(this.brickConfig['bricks'])[randomRangeInt(0, Object.keys(this.brickConfig['bricks']).length)]
+        const brickKey = Object.keys(this.brickConfig['bricks'])[randomRangeInt(0, Object.keys(this.brickConfig['bricks']).length)];
         const brickConfig = this.brickConfig['bricks'][brickKey];
-        const randomIndex = oops.random.getRandomInt(1, 5);
+        const randomIndex = oops.random.getRandomInt(1, 5);  //颜色
         // 生成方块
         const brickData: BrickData = {
             index,
@@ -944,7 +943,6 @@ export class EliminateViewComp extends CCComp {
                     this.brickNode.addChild(brickData.brickNode)
                     //显示旋转节点
                     if (brickData.rotateNode) {
-                        console.log("显示旋转节点")
                         brickData.rotateNode.active = true;
                     }
                     brickData.brickNode.setWorldPosition(brickData.brickInitPos)
@@ -955,10 +953,9 @@ export class EliminateViewComp extends CCComp {
                     // 隐藏旋转节点
                     this.scheduleOnce(() => {
                         if (brickData.rotateNode) {
-                            console.log("隐藏旋转节点")
                             brickData.rotateNode.active = false;
                         }
-                    }, 0.2);
+                    }, 0.4);
                 }
             } else if (this.editingData.brickData && this.editingData.gridList.length > 0) {
                 // 计算放置的格子数量
@@ -1805,7 +1802,6 @@ export class EliminateViewComp extends CCComp {
                     degrees.push(next.deg)
                 }
             }
-
             // 遍历所有网格位置
             for (let rowIndex = 0; rowIndex < this.rows; rowIndex++) {
                 for (let columnIndex = 0; columnIndex < this.cols; columnIndex++) {
@@ -1838,14 +1834,13 @@ export class EliminateViewComp extends CCComp {
                                     score += this.rows * i
                                 }
                             }
-
                             // 记录此放置选项
                             placements.push({
                                 brickIndex,
                                 brickData,
                                 rowIndex,
                                 columnIndex,
-                                gridConfig: currentGridConfig,
+                                gridConfig: currentGridConfig,  //这里有问题,拿到的和显示的不对
                                 deg: currentDeg,
                                 score,
                                 canEliminate: elimination.gridEliminateList.length > 0
@@ -1855,7 +1850,6 @@ export class EliminateViewComp extends CCComp {
                 }
             }
         }
-
         // 按优先级排序:最高分 > 有分数 > 没有分数但可放置
         placements.sort((a, b) => {
             // 首先按分数排序
@@ -1885,14 +1879,13 @@ export class EliminateViewComp extends CCComp {
         }
         this.editingData.brickData = this.bricksList.splice(index, 1)[0];
         // 应用旋转
-        // if (brickData.deg !== placement.deg) {
-        //     brickData.gridConfig = placement.gridConfig
-        //     brickData.deg = placement.deg
-        //     tween(brickData.brickNode).to(0.1, { angle: placement.deg }).start()
-        // }
-
+        if (brickData.deg !== placement.deg) {
+            brickData.gridConfig = placement.gridConfig
+            brickData.deg = placement.deg
+            tween(brickData.brickNode).to(0.1, { angle: placement.deg }).start()
+        }
 
-        // 构建对应网格列表--这里就有问题了
+        // 构建对应网格列表--这里就有问题了,这算位置,有问题
         this.editingData.gridList = [];
         placement.gridConfig.forEach((gridConfigData: GridConfigData) => {
             const r = gridConfigData.row + placement.rowIndex
@@ -1919,10 +1912,7 @@ export class EliminateViewComp extends CCComp {
 
         const originPos = brickData.brickNode.getWorldPosition()
         brickData.brickNode.setParent(this.moveNode)
-        brickData.brickNode.setWorldPosition(originPos)
-        //这个数据就不对了
-        console.log("网格状态>>>>>>>>>>>", this.editingData.gridList);
-
+        brickData.brickNode.setWorldPosition(originPos);
 
         // 动画放置方块
         tween(brickData.brickNode)