在我的 2D 游戏中,玩家能够摧毁箱子、具有两种碰撞形状的物体。当被摧毁时,板条箱会产生也具有碰撞形状的物品。但是当调用以下函数时,Godot控制台中会显示许多类似的错误
Code:
func _on_Crate_item_dropped(collectible, pos):
collectible.init(pos, Vector2(rand_range(30, 100), rand_range(-10, 10)))
$CollectibleContainer.add_child(collectible) # error occurs here
Error:
ERROR: Can't change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead.
方法call_deferred()
在空闲时间调用对象的方法。它的第一个参数是方法名称字符串,其他参数是方法参数。
Replace
$CollectibleContainer.add_child(collectible)
with
$CollectibleContainer.call_deferred("add_child", collectible)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)