You have two main tools to process the player's input in Godot:

  1. The built-in input callbacks, mainly _unhandled_input(). Like _process(), it's a built-in virtual function that Godot calls every time the player presses a key. It's the tool you want to use to react to events that don't happen every frame, like pressing Space to jump. To learn more about input callbacks, see Using InputEvent.
  2. The Input singleton. A singleton is a globally accessible object. Godot provides access to several in scripts. It's the right tool to check for input every frame.

 

every script in Godot represents a class and extends one of the engine's built-in classes. The node types your classes inherit from give you access to properties like rotation and position in our sprite's case. You also inherit many functions, which we didn't get to use in this example.

 

In GDScript, the variables you put at the top of the file are your class's properties, also called member variables. Besides variables, you can define functions, which, for the most part, will be your classes' methods.

 

Godot provides several virtual functions you can define to connect your class with the engine. These include _process(), to apply changes to the node every frame, and _unhandled_input(), to receive input events like key and button presses from the users. There are quite a few more.

 

The Input singleton allows you to react to the players' input anywhere in your code. In particular, you'll get to use it in the _process() loop.

'Godot4' 카테고리의 다른 글

고도엔진과 Your first 2D game  (0) 2023.11.23
GDScript  (0) 2023.11.23
signals  (0) 2023.11.22
extends  (0) 2023.11.22
Godot Basics  (0) 2023.11.22