Browse Source

日常开发

林旭祥 1 ngày trước cách đây
mục cha
commit
28677aa075
1 tập tin đã thay đổi với 12 bổ sung4 xóa
  1. 12 4
      src/views/game/fruit.vue

+ 12 - 4
src/views/game/fruit.vue

@@ -775,9 +775,12 @@ class MainScene extends Phaser.Scene {
   }
 
   fruitAnim() {
-    // 西瓜组
-    this.sandiaGroup = this.add.container(323 * wRatio, 373 * hRatio);
-    this.sandiaGroup.setScale(0);
+      // 每次创建全新的容器,避免复用旧实例
+  this.sandiaGroup = this.add.container(0, 0); // 先置0,后续重新计算
+  // 西瓜组初始位置:基于当前窗口尺寸动态计算(核心修复)
+  const initX = 323 * wRatio; 
+  const initY = 373 * hRatio;
+  this.sandiaGroup.setPosition(initX, initY); // 强制设置位置
     //圆圈
     this.new_game = this.add.sprite(0, 0, "new-game");
     this.new_game.setOrigin(0.5, 0.5);
@@ -850,6 +853,11 @@ class MainScene extends Phaser.Scene {
   resetScene() {
     this.sandia = null;
     this.start = false;
+  // 新增:销毁西瓜容器,避免残留
+  if (this.sandiaGroup) {
+    this.sandiaGroup.destroy(); // 销毁容器及其子元素
+    this.sandiaGroup = null; // 置空引用
+  }
   }
 }
 
@@ -1047,7 +1055,7 @@ class PlayScene extends Phaser.Scene {
   startFruit() {
 
     const number = Math.floor(mathTool.randomMinMax(1, 5));
-    const hasBomb = Math.random() > 0.7; // 30%概率有炸弹
+    const hasBomb = Math.random() > 0.3; // 30%概率有炸弹
     const bombIndex = hasBomb ? Math.floor(Math.random() * number) : -1;
 
     for (let i = 0; i < number; i++) {