Skip to content

Commit 25dd0ac

Browse files
committed
修复漩涡核心的物理问题
1 parent 1102fc8 commit 25dd0ac

File tree

8 files changed

+13
-30
lines changed

8 files changed

+13
-30
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,7 @@ dist-ssr
3434

3535
.cooperation
3636
public/assets/pending
37-
public/assets/video_alpha_test
37+
public/assets/video_alpha_test
38+
android/build/*
39+
android/app/build/*
40+
android/app/release/*

src/entities/summons/BaseSummon.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export interface ISummonInitData {
1818
/**
1919
* 类似于 Unity 的 MonoBehaviour (针对召唤物)
2020
*/
21-
export abstract class BaseSummon extends Phaser.Physics.Arcade.Sprite {
21+
export abstract class BaseSummon extends Phaser.GameObjects.Sprite {
2222
protected isDespawning: boolean = false; // ✅ 移到基类,统一管理状态
2323
protected lifeTimer: number = 0;
2424
protected maxLifeTime: number = -1;
@@ -36,17 +36,13 @@ export abstract class BaseSummon extends Phaser.Physics.Arcade.Sprite {
3636
public onSpawn(data: ISummonInitData) {
3737
this.setActive(true);
3838
this.setVisible(true);
39-
this.body!.enable = true; // 确保物理开启
4039
this.isDespawning = false; // ✅ 关键:复活时重置状态
4140

4241
this.setPosition(data.x, data.y);
4342
this.lifeTimer = 0;
4443
this.maxLifeTime = data.lifeTime ?? -1;
4544
this.target = data.target || null;
4645

47-
// 重置物理状态
48-
this.setVelocity(0, 0);
49-
this.setAcceleration(0, 0);
5046
this.setAlpha(1);
5147
this.setScale(1);
5248

@@ -101,7 +97,6 @@ export abstract class BaseSummon extends Phaser.Physics.Arcade.Sprite {
10197
protected kill() {
10298
this.setActive(false);
10399
this.setVisible(false);
104-
if (this.body) this.body.enable = false;
105100
// 状态已在 onSpawn 重置,这里不需要改 isDespawning
106101
console.log(`[BaseSummon] ${this.constructor.name} returned to pool.`);
107102
}
@@ -117,4 +112,4 @@ export abstract class BaseSummon extends Phaser.Physics.Arcade.Sprite {
117112
// 默认行为:没有动画,直接死
118113
this.kill();
119114
}
120-
}
115+
}

src/entities/summons/FogOverlay.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export class FogOverlay extends BaseSummon {
2424

2525
protected onStart(_data: ISummonInitData): void {
2626
this.isDespawning = false;
27-
if (this.body) this.body.enable = false;
2827

2928
// --- 1. 计算尺寸 ---
3029
const { width, height } = this.scene.scale;
@@ -111,4 +110,4 @@ export class FogOverlay extends BaseSummon {
111110
this.kill();
112111
}
113112
}
114-
}
113+
}

src/entities/summons/LightningColumn.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class LightningColumn extends BaseSummon {
2222
constructor(scene: Phaser.Scene, x: number, y: number) {
2323
super(scene, x, y, 'pixel');
2424
this.setVisible(false); // 本体仅仅是逻辑锚点
25+
this.setAlpha(0);
2526
}
2627

2728
protected onStart(_data: ISummonInitData): void {
@@ -84,8 +85,6 @@ export class LightningColumn extends BaseSummon {
8485
duration: 180
8586
});
8687

87-
// 3. 禁用物理 (手动判定)
88-
if (this.body) this.body.enable = false;
8988
}
9089

9190
private strike() {
@@ -218,4 +217,3 @@ export class LightningColumn extends BaseSummon {
218217
}
219218

220219

221-

src/entities/summons/Shield.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export class Shield extends BaseSummon {
2323
this.setAlpha(0);
2424
// 也许你需要重置旋转角度
2525
this.setRotation(0);
26-
2726
this.scene.tweens.add({
2827
targets: this,
2928
alpha: 1,

src/entities/summons/ThermalVent.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ export class ThermalVent extends BaseSummon {
4242
// 确保位置在屏幕垂直中间 (因为 y 传进来的是 screenHeight/2)
4343
this.y = screenHeight / 2;
4444

45-
// 3. 关闭不必要的物理
46-
// 我们手动检测,不需要 Arcade Body 参与碰撞
47-
if (this.body) {
48-
this.body.enable = false;
49-
}
50-
5145
// 进场动画
5246
this.scene.tweens.add({
5347
targets: this,
@@ -58,7 +52,7 @@ export class ThermalVent extends BaseSummon {
5852

5953
protected onUpdate(_dt: number): void {
6054
// ✅ 如果正在消失,不再生效,避免玩家觉得"明明看不见了怎么还有力"
61-
if (this.isDespawning) return;
55+
// 视觉更新可以继续进行
6256
// ✅ 核心:自定义屏幕空间碰撞检测
6357
// 思路:将玩家的世界坐标映射到屏幕坐标,然后看是否在光柱范围内
6458

@@ -76,6 +70,7 @@ export class ThermalVent extends BaseSummon {
7670
const rightBound = this.x + halfWidth;
7771

7872
// 3. 判断是否在区间内
73+
if (this.isDespawning) return;
7974
if (playerScreenX >= leftBound && playerScreenX <= rightBound) {
8075
this.onPlayerStay();
8176
}
@@ -110,4 +105,4 @@ export class ThermalVent extends BaseSummon {
110105
}
111106
});
112107
}
113-
}
108+
}

src/entities/summons/WindVane.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ export class WindVane extends BaseSummon {
2222
// 2. 监听风力变化
2323
gameEvents.on(EVENTS.WIND_CHANGE, this.onWindChange, this);
2424

25-
// 3. 物理? 不需要
26-
if (this.body) this.body.enable = false;
2725
}
2826

2927
private onWindChange(windValue: number) {
@@ -66,4 +64,4 @@ export class WindVane extends BaseSummon {
6664
}
6765
});
6866
}
69-
}
67+
}

src/managers/SummonManager.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@ export default class SummonManager {
7474

7575
if (entity) {
7676
// 确保物理组件存在 (如果是首次创建)
77-
if (!entity.body) {
78-
this.scene.physics.add.existing(entity);
79-
}
80-
8177
// 设置空间
8278
entity.setSpaceType(config.defaultSpace);
8379

@@ -125,4 +121,4 @@ export default class SummonManager {
125121
});
126122
console.log("[SummonManager] All entities cleared.");
127123
}
128-
}
124+
}

0 commit comments

Comments
 (0)