Pausando jogos e modo de processo¶
Introdução¶
Na maioria dos jogos é desejável, em algum momento, interromper o jogo para fazer algo mais, como fazer uma pausa ou mudar as opções. Implementar um controle refinado para o que pode ser pausado (e o que não pode) é muito trabalhoso, portanto, uma estrutura simples para pausar é fornecida no Godot.
Como a pausa funciona¶
Para pausar o jogo, o estado de pausa deve ser definido. Isto é feito atribuindo true
à propriedade SceneTree.paused:
get_tree().paused = true
GetTree().Paused = true;
Doing this will cause two things. First, 2D and 3D physics will be stopped for all nodes. Second, the behavior of certain nodes will stop or start depending on their process mode.
Nota
The physics servers can be made active while the game is
paused by using their set_active
methods.
Modos de processo¶
Each node in Godot has a "Pause Mode" that defines when it processes. It can be found and changed under a node's Node properties in the inspector.
Você também pode alterar a propriedade com o código:
func _ready():
pause_mode = Node.PAUSE_MODE_PROCESS
public override void _Ready()
{
PauseMode = Node.PauseModeEnum.Process;
}
This is what each mode tells a node to do:
Inherit: Process depending on the state of the parent, grandparent, etc. The first parent that has a state other than Inherit determines the effective value that will be used.
Stop: If the scene tree is paused, pause the node no matter what (and children in Inherit mode). When paused, this node will not process.
Process: Even if the scene tree is paused, process the node no matter what (and children in Inherit mode). Paused or not, this node will process.
Por padrão, todos os nós têm esta propriedade no estado "Herdar". Se o pai estiver configurado para "Herdar", então o avô será verificado e assim por diante. Se um estado não puder ser encontrado em nenhum dos avós, o estado de pausa no SceneTree é usado. Isto significa que, por padrão, quando o jogo for pausado, todos os nós serão pausados. Várias coisas acontecem quando um nó pára de processar.
The _process
, _physics_process
, _input
, and _input_event
functions
will not be called. However signals still work and cause their connected function to
run, even if that function's script is attached to a node that has its pause
mode set to "Stop".
Animation nodes will pause their current animation, audio nodes will pause their current audio stream, and particles will pause. These resume automatically when the game is no longer paused.
It is important to note that even if a node is processing while the game is
paused physics will NOT work for it by default. As stated earlier this is
because the physics servers are turned off. The physics servers can be made
active while the game is paused by using their set_active
methods.