你好,我在做课程项目的小型俯视角射击游戏,用 Godot 4。有两个问题,可能是一个 bug,也可能是两个。
1. 炸弹。 玩家捡到炸弹,它会调用波次管理器上的 kill_all()。有 10 个敌人的时候,只死了 5 个。另外 5 个还在,这一波一直清不掉。我在炸弹前后都打印了 alive_enemies.size()。前面显示 10,后面显示 5。我想可能是炸弹在一帧里运行的时间不对,所以我试了对它用 call_deferred。还是搞不懂。在我以前的 Godot 3 项目里,这样的循环是正常的。
func kill_all() -> void:
for e in alive_enemies:
e.take_damage(9999)
func _on_enemy_died(enemy: Enemy) -> void:
alive_enemies.erase(enemy)
score += 10
take_damage 会发出 died,然后 queue_free()。
2. 移动。 我在 _process 里移动玩家,因为我想要顺滑。
func _process(delta: float) -> void:
var dir := Input.get_vector("move_left", "move_right", "move_up", "move_down")
velocity = dir * speed
move_and_slide()
我的笔记本没问题。用 144 Hz 显示器的朋友说玩家变快了,而且会卡在墙角。
这两个都是帧时序的问题吗?还是两个不同的 bug?
从英语翻译·查看原文Hello, small top-down shooter for class project, Godot 4. Two problem, maybe one bug, maybe two.
1. Bomb. Player pick up bomb, it call kill_all() on wave manager. With 10 enemy, only 5 die. The other 5 stay and the wave never clear. I print alive_enemies.size() before and after bomb. Before it say 10, after it say 5. I think maybe bomb run at wrong time in the frame, so I try call_deferred on it. Still confusing. In my old Godot 3 project a loop like this work fine.
func kill_all() -> void:
for e in alive_enemies:
e.take_damage(9999)
func _on_enemy_died(enemy: Enemy) -> void:
alive_enemies.erase(enemy)
score += 10
take_damage emit died, then queue_free().
2. Movement. I move player in _process because I want smooth:
func _process(delta: float) -> void:
var dir := Input.get_vector("move_left", "move_right", "move_up", "move_down")
velocity = dir * speed
move_and_slide()
My laptop is OK. Friend with 144 Hz monitor say player faster and stick on wall corner.
Is this frame timing for both? Or two different bug?