mirror of
https://github.com/godotengine/godot-docs.git
synced 2026-01-03 05:48:42 +03:00
Adapt tutorial hyperlinks after godotengine/godot#24640
This commit is contained in:
@@ -223,33 +223,33 @@ Improve formatting with BBcode style tags
|
||||
|
||||
Godot's class reference supports BBcode-like tags. They add nice formatting to the text. Here's the list of available tags:
|
||||
|
||||
+---------------------------+--------------------------------+-----------------------------------+--------------------------------------------+
|
||||
| Tag | Effect | Usage | Result |
|
||||
+===========================+================================+===================================+============================================+
|
||||
| [Class] | Link a class | Move the [Sprite]. | Move the :ref:`class_sprite`. |
|
||||
+---------------------------+--------------------------------+-----------------------------------+--------------------------------------------+
|
||||
| [method methodname] | Link to a method in this class | Call [method hide]. | See :ref:`hide <class_spatial_hide>`. |
|
||||
+---------------------------+--------------------------------+-----------------------------------+--------------------------------------------+
|
||||
| [method Class.methodname] | Link to another class's method | Call [method Spatial.hide]. | See :ref:`hide <class_spatial_hide>`. |
|
||||
+---------------------------+--------------------------------+-----------------------------------+--------------------------------------------+
|
||||
| [member membername] | Link to a member in this class | Get [member scale]. | Get :ref:`scale <class_node2d_scale>`. |
|
||||
+---------------------------+--------------------------------+-----------------------------------+--------------------------------------------+
|
||||
| [member Class.membername] | Link to another class's member | Get [member Node2D.scale]. | Get :ref:`scale <class_node2d_scale>`. |
|
||||
+---------------------------+--------------------------------+-----------------------------------+--------------------------------------------+
|
||||
| [signal signalname] | Link to a signal in this class | Emit [signal renamed]. | Emit :ref:`renamed <class_node_renamed>`. |
|
||||
+---------------------------+--------------------------------+-----------------------------------+--------------------------------------------+
|
||||
| [signal Class.signalname] | Link to another class's signal | Emit [signal Node.renamed]. | Emit :ref:`renamed <class_node_renamed>`. |
|
||||
+---------------------------+--------------------------------+-----------------------------------+--------------------------------------------+
|
||||
| [b] [/b] | Bold | Some [b]bold[/b] text. | Some **bold** text. |
|
||||
+---------------------------+--------------------------------+-----------------------------------+--------------------------------------------+
|
||||
| [i] [/i] | Italic | Some [i]italic[/i] text. | Some *italic* text. |
|
||||
+---------------------------+--------------------------------+-----------------------------------+--------------------------------------------+
|
||||
| [code] [/code] | Monospace | Some [code]monospace[/code] text. | Some ``monospace`` text. |
|
||||
+---------------------------+--------------------------------+-----------------------------------+--------------------------------------------+
|
||||
| [codeblock] [/codeblock] | Multiline preformatted block | *See below.* | *See below.* |
|
||||
+---------------------------+--------------------------------+-----------------------------------+--------------------------------------------+
|
||||
+---------------------------+--------------------------------+-----------------------------------+---------------------------------------------------+
|
||||
| Tag | Effect | Usage | Result |
|
||||
+===========================+================================+===================================+===================================================+
|
||||
| [Class] | Link a class | Move the [Sprite]. | Move the :ref:`class_sprite`. |
|
||||
+---------------------------+--------------------------------+-----------------------------------+---------------------------------------------------+
|
||||
| [method methodname] | Link to a method in this class | Call [method hide]. | See :ref:`hide <class_spatial_method_hide>`. |
|
||||
+---------------------------+--------------------------------+-----------------------------------+---------------------------------------------------+
|
||||
| [method Class.methodname] | Link to another class's method | Call [method Spatial.hide]. | See :ref:`hide <class_spatial_method_hide>`. |
|
||||
+---------------------------+--------------------------------+-----------------------------------+---------------------------------------------------+
|
||||
| [member membername] | Link to a member in this class | Get [member scale]. | Get :ref:`scale <class_node2d_property_scale>`. |
|
||||
+---------------------------+--------------------------------+-----------------------------------+---------------------------------------------------+
|
||||
| [member Class.membername] | Link to another class's member | Get [member Node2D.scale]. | Get :ref:`scale <class_node2d_property_scale>`. |
|
||||
+---------------------------+--------------------------------+-----------------------------------+---------------------------------------------------+
|
||||
| [signal signalname] | Link to a signal in this class | Emit [signal renamed]. | Emit :ref:`renamed <class_node_signal_renamed>`. |
|
||||
+---------------------------+--------------------------------+-----------------------------------+---------------------------------------------------+
|
||||
| [signal Class.signalname] | Link to another class's signal | Emit [signal Node.renamed]. | Emit :ref:`renamed <class_node_signal_renamed>`. |
|
||||
+---------------------------+--------------------------------+-----------------------------------+---------------------------------------------------+
|
||||
| [b] [/b] | Bold | Some [b]bold[/b] text. | Some **bold** text. |
|
||||
+---------------------------+--------------------------------+-----------------------------------+---------------------------------------------------+
|
||||
| [i] [/i] | Italic | Some [i]italic[/i] text. | Some *italic* text. |
|
||||
+---------------------------+--------------------------------+-----------------------------------+---------------------------------------------------+
|
||||
| [code] [/code] | Monospace | Some [code]monospace[/code] text. | Some ``monospace`` text. |
|
||||
+---------------------------+--------------------------------+-----------------------------------+---------------------------------------------------+
|
||||
| [codeblock] [/codeblock] | Multiline preformatted block | *See below.* | *See below.* |
|
||||
+---------------------------+--------------------------------+-----------------------------------+---------------------------------------------------+
|
||||
|
||||
Use ``[codeblock]`` for pre-formatted code blocks. Inside ``[codeblock]``, always use spaces for indentation (the parser will delete tabs). Example:
|
||||
Use ``[codeblock]`` for pre-formatted code blocks. Inside ``[codeblock]``, always use **four spaces** for indentation (the parser will delete tabs). Example:
|
||||
|
||||
.. code:: xml
|
||||
|
||||
@@ -277,6 +277,16 @@ You can still have a look at the methods' implementation in Godot's source code
|
||||
|
||||
|
||||
Localization
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
~~~~~~~~~~~~
|
||||
|
||||
Before we translate the documentation, we need to complete and proof-read it in English. We'll work on localization when we get past 90% completion.
|
||||
The documentation can be translated in any language on `Hosted Weblate
|
||||
<https://hosted.weblate.org/projects/godot-engine/godot-docs/>`__.
|
||||
|
||||
Translated strings are synced manually by documentation maintainers in
|
||||
the `godot-docs-l10n <https://github.com/godotengine/godot-docs-l10n>`__
|
||||
repository.
|
||||
|
||||
Languages with a good level of completion have their own localized
|
||||
instances of ReadTheDocs. Open an issue on the ``godot-docs-l10n``
|
||||
repository if you think that a new language is complete enough to get
|
||||
its own instance.
|
||||
|
||||
@@ -110,7 +110,7 @@ resources of type :ref:`PackedScene <class_PackedScene>`. The
|
||||
scene is packed inside a resource.
|
||||
|
||||
To get an instance of the scene, you have to use the
|
||||
:ref:`PackedScene.instance() <class_PackedScene_instance>` method.
|
||||
:ref:`PackedScene.instance() <class_PackedScene_method_instance>` method.
|
||||
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
@@ -135,7 +135,7 @@ returns the root node of the scene. You can then add it as a child of any other
|
||||
node.
|
||||
|
||||
The approach has several advantages. As the :ref:`PackedScene.instance()
|
||||
<class_PackedScene_instance>` function is pretty fast, you can create new
|
||||
<class_PackedScene_method_instance>` function is pretty fast, you can create new
|
||||
enemies, bullets, effects, etc. without having to load them again from disk each
|
||||
time. Remember that, as always, images, meshes, etc. are all shared between the
|
||||
scene instances.
|
||||
|
||||
@@ -65,7 +65,7 @@ important uses:
|
||||
When a node is part of the Scene Tree, the
|
||||
:ref:`SceneTree <class_SceneTree>`
|
||||
singleton can be obtained by simply calling
|
||||
:ref:`Node.get_tree() <class_Node_get_tree>`.
|
||||
:ref:`Node.get_tree() <class_Node_method_get_tree>`.
|
||||
|
||||
Root viewport
|
||||
-------------
|
||||
@@ -142,7 +142,7 @@ Changing current scene
|
||||
|
||||
After a scene is loaded, it is often desired to change this scene for
|
||||
another one. The simple way to do this is to use the
|
||||
:ref:`SceneTree.change_scene() <class_SceneTree_change_scene>`
|
||||
:ref:`SceneTree.change_scene() <class_SceneTree_method_change_scene>`
|
||||
function:
|
||||
|
||||
.. tabs::
|
||||
@@ -161,7 +161,7 @@ function:
|
||||
Rather than using file paths, one can also use ready-made
|
||||
:ref:`PackedScene <class_PackedScene>` resources using the equivalent
|
||||
function
|
||||
:ref:`SceneTree.change_scene_to(PackedScene scene) <class_SceneTree_change_scene_to>`:
|
||||
:ref:`SceneTree.change_scene_to(PackedScene scene) <class_SceneTree_method_change_scene_to>`:
|
||||
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
@@ -217,7 +217,7 @@ is a scripting tutorial, so for the sake of learning, let's dive into the
|
||||
manual process!
|
||||
|
||||
To accomplish this, we will introduce a function that is probably the most used
|
||||
by Godot programmers: :ref:`Node.get_node() <class_Node_get_node>`.
|
||||
by Godot programmers: :ref:`Node.get_node() <class_Node_method_get_node>`.
|
||||
This function uses paths to fetch nodes anywhere in the scene, relative to the
|
||||
node that owns the script.
|
||||
|
||||
@@ -257,7 +257,7 @@ Next, write a function which will be called when the button is pressed:
|
||||
}
|
||||
|
||||
Finally, connect the button's "pressed" signal to ``_ready()`` by
|
||||
using :ref:`Object.connect() <class_Object_connect>`.
|
||||
using :ref:`Object.connect() <class_Object_method_connect>`.
|
||||
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
@@ -13,9 +13,9 @@ However, it is still common to need a script to be processed on every
|
||||
frame. There are two types of processing: idle processing and physics
|
||||
processing.
|
||||
|
||||
Idle processing is activated when the method :ref:`Node._process() <class_Node__process>`
|
||||
Idle processing is activated when the method :ref:`Node._process() <class_Node_method__process>`
|
||||
is found in a script. It can be turned off and on with the
|
||||
:ref:`Node.set_process() <class_Node_set_process>` function.
|
||||
:ref:`Node.set_process() <class_Node_method_set_process>` function.
|
||||
|
||||
This method will be called every time a frame is drawn, so it's fully dependent on
|
||||
how many frames per second (FPS) the application is running at:
|
||||
@@ -109,7 +109,7 @@ which are enemies:
|
||||
|
||||
This way, if the player is discovered sneaking into a secret base,
|
||||
all enemies can be notified about its alarm sounding by using
|
||||
:ref:`SceneTree.call_group() <class_SceneTree_call_group>`:
|
||||
:ref:`SceneTree.call_group() <class_SceneTree_method_call_group>`:
|
||||
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
@@ -129,7 +129,7 @@ member of the group ``enemies``.
|
||||
|
||||
It is also possible to get the full list of ``enemies`` nodes by
|
||||
calling
|
||||
:ref:`SceneTree.get_nodes_in_group() <class_SceneTree_get_nodes_in_group>`:
|
||||
:ref:`SceneTree.get_nodes_in_group() <class_SceneTree_method_get_nodes_in_group>`:
|
||||
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
@@ -154,7 +154,7 @@ Godot has a system of notifications. These are usually not needed for
|
||||
scripting, as it's too low-level and virtual functions are provided for
|
||||
most of them. It's just good to know they exist. For example,
|
||||
you may add an
|
||||
:ref:`Object._notification() <class_Object__notification>`
|
||||
:ref:`Object._notification() <class_Object_method__notification>`
|
||||
function in your script:
|
||||
|
||||
.. tabs::
|
||||
@@ -320,7 +320,7 @@ function. This will crash the game. Running Godot
|
||||
with the debugger will often catch this case and warn you about it.
|
||||
|
||||
The safest way to delete a node is by using
|
||||
:ref:`Node.queue_free() <class_Node_queue_free>`.
|
||||
:ref:`Node.queue_free() <class_Node_method_queue_free>`.
|
||||
This erases the node safely during idle.
|
||||
|
||||
.. tabs::
|
||||
@@ -363,7 +363,7 @@ time (GDScript only):
|
||||
But ``scene`` is not yet a node. It's packed in a
|
||||
special resource called :ref:`PackedScene <class_PackedScene>`.
|
||||
To create the actual node, the function
|
||||
:ref:`PackedScene.instance() <class_PackedScene_instance>`
|
||||
:ref:`PackedScene.instance() <class_PackedScene_method_instance>`
|
||||
must be called. This will return the tree of nodes that can be added to
|
||||
the active scene:
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ Custom scene switcher
|
||||
|
||||
This tutorial will demonstrate building a scene switcher using autoload. For
|
||||
basic scene switching, you can use the
|
||||
:ref:`SceneTree.change_scene() <class_SceneTree_change_scene>`
|
||||
:ref:`SceneTree.change_scene() <class_SceneTree_method_change_scene>`
|
||||
method (see :ref:`doc_scene_tree` for details). However, if you need more
|
||||
complex behavior when changing scenes, this method provides more functionality.
|
||||
|
||||
@@ -226,7 +226,7 @@ current scene and replace it with the requested one.
|
||||
|
||||
As mentioned in the comments above, we need to avoid the situation of deleting
|
||||
the current scene while it is still being used (i.e. its code is still running),
|
||||
so using :ref:`Object.call_deferred() <class_Object_call_deferred>`
|
||||
so using :ref:`Object.call_deferred() <class_Object_method_call_deferred>`
|
||||
is required at this point. The result is that the second function will run
|
||||
at a later time when any code from the current scene has completed.
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ process will build that type of file for the chosen platform.
|
||||
build of the engine or have access to one (distributed alongside or
|
||||
perhaps in the original game's files). The tool can then use the Godot
|
||||
executable to export a PCK file from the command line with
|
||||
:ref:`OS.execute <class_OS_execute>`. It makes the most sense for the
|
||||
:ref:`OS.execute() <class_OS_method_execute>`. It makes the most sense for the
|
||||
game to not use a tool-build though (for security) and for the modding
|
||||
tools to *do* use a tool-enabled engine build.
|
||||
|
||||
|
||||
@@ -40,10 +40,10 @@ resizing or stretching the screen. This transform is used internally (as
|
||||
described in :ref:`doc_multiple_resolutions`), but can also be manually set
|
||||
on each viewport.
|
||||
|
||||
Input events received in the :ref:`MainLoop._input_event() <class_MainLoop__input_event>`
|
||||
Input events received in the :ref:`MainLoop._input_event() <class_MainLoop_method__input_event>`
|
||||
callback are multiplied by this transform but lack the ones above. To
|
||||
convert InputEvent coordinates to local CanvasItem coordinates, the
|
||||
:ref:`CanvasItem.make_input_local() <class_CanvasItem_make_input_local>`
|
||||
:ref:`CanvasItem.make_input_local() <class_CanvasItem_method_make_input_local>`
|
||||
function was added for convenience.
|
||||
|
||||
Transform order
|
||||
@@ -59,15 +59,15 @@ Transform functions
|
||||
|
||||
Obtaining each transform can be achieved with the following functions:
|
||||
|
||||
+----------------------------------+--------------------------------------------------------------------------------------+
|
||||
| Type | Transform |
|
||||
+==================================+======================================================================================+
|
||||
| CanvasItem | :ref:`CanvasItem.get_global_transform() <class_CanvasItem_get_global_transform>` |
|
||||
+----------------------------------+--------------------------------------------------------------------------------------+
|
||||
| CanvasLayer | :ref:`CanvasItem.get_canvas_transform() <class_CanvasItem_get_canvas_transform>` |
|
||||
+----------------------------------+--------------------------------------------------------------------------------------+
|
||||
| CanvasLayer+GlobalCanvas+Stretch | :ref:`CanvasItem.get_viewport_transform() <class_CanvasItem_get_viewport_transform>` |
|
||||
+----------------------------------+--------------------------------------------------------------------------------------+
|
||||
+----------------------------------+---------------------------------------------------------------------------------------------+
|
||||
| Type | Transform |
|
||||
+==================================+=============================================================================================+
|
||||
| CanvasItem | :ref:`CanvasItem.get_global_transform() <class_CanvasItem_method_get_global_transform>` |
|
||||
+----------------------------------+---------------------------------------------------------------------------------------------+
|
||||
| CanvasLayer | :ref:`CanvasItem.get_canvas_transform() <class_CanvasItem_method_get_canvas_transform>` |
|
||||
+----------------------------------+---------------------------------------------------------------------------------------------+
|
||||
| CanvasLayer+GlobalCanvas+Stretch | :ref:`CanvasItem.get_viewport_transform() <class_CanvasItem_method_get_viewport_transform>` |
|
||||
+----------------------------------+---------------------------------------------------------------------------------------------+
|
||||
|
||||
Finally, then, to convert a CanvasItem local coordinates to screen
|
||||
coordinates, just multiply in the following order:
|
||||
@@ -75,7 +75,7 @@ coordinates, just multiply in the following order:
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
var screen_coord = get_viewport_transform() * ( get_global_transform() * local_pos )
|
||||
var screen_coord = get_viewport_transform() * (get_global_transform() * local_pos)
|
||||
|
||||
.. code-tab:: csharp
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ These nodes are placed as direct or indirect children of a
|
||||
:ref:`Viewport <class_Viewport>`, and will be displayed through it.
|
||||
|
||||
Viewport has the property
|
||||
:ref:`Viewport.canvas_transform <class_Viewport_canvas_transform>`,
|
||||
:ref:`Viewport.canvas_transform <class_Viewport_property_canvas_transform>`,
|
||||
which allows to transform all the CanvasItem hierarchy by a custom
|
||||
:ref:`Transform2D <class_Transform2D>` transform. Nodes such as
|
||||
:ref:`Camera2D <class_Camera2D>` work by changing that transform.
|
||||
@@ -73,4 +73,4 @@ Even though there shouldn't be any performance limitation, it is not
|
||||
advised to use excessive amount of layers to arrange drawing order of
|
||||
nodes. The most optimal way will always be arranging them by tree order.
|
||||
2d nodes also have a property for controlling their drawing order
|
||||
(see :ref:`Node2D.z_index <class_Node2D_z_index>`).
|
||||
(see :ref:`Node2D.z_index <class_Node2D_property_z_index>`).
|
||||
|
||||
@@ -65,7 +65,7 @@ The ``_draw()`` function is only called once, and then the draw commands
|
||||
are cached and remembered, so further calls are unnecessary.
|
||||
|
||||
If re-drawing is required because a state or something else changed,
|
||||
simply call :ref:`CanvasItem.update() <class_CanvasItem_update>`
|
||||
simply call :ref:`CanvasItem.update() <class_CanvasItem_method_update>`
|
||||
in that same node and a new ``_draw()`` call will happen.
|
||||
|
||||
Here is a little more complex example, a texture variable that will be
|
||||
|
||||
@@ -62,7 +62,7 @@ Generated geometry
|
||||
|
||||
It is possible to create custom geometry by using the
|
||||
:ref:`Mesh <class_Mesh>` resource directly. Simply create your arrays
|
||||
and use the :ref:`Mesh.add_surface() <class_Mesh_add_surface>`
|
||||
and use the :ref:`Mesh.add_surface() <class_Mesh_method_add_surface>`
|
||||
function. A helper class is also available, :ref:`SurfaceTool <class_SurfaceTool>`,
|
||||
which provides a more straightforward API and helpers for indexing,
|
||||
generating normals, tangents, etc.
|
||||
|
||||
@@ -19,7 +19,7 @@ Naturally, Skeleton is intended to deform meshes and consists of
|
||||
structures called "bones". Each "bone" is represented as a Transform, which is
|
||||
applied to a group of vertices within a mesh. You can directly control a group
|
||||
of vertices from Godot. For that please reference the :ref:`class_MeshDataTool`
|
||||
class and its method :ref:`set_vertex_bones <class_MeshDataTool_set_vertex_bones>`.
|
||||
class and its method :ref:`set_vertex_bones() <class_MeshDataTool_method_set_vertex_bones>`.
|
||||
|
||||
The "bones" are organized hierarchically. Every bone, except for the root
|
||||
bone(s), has a parent. Every bone also has an associated name you can use to
|
||||
|
||||
@@ -25,8 +25,8 @@ Checking control size
|
||||
|
||||
Unlike 2D nodes, "size" is important with controls, as it helps to
|
||||
organize them in proper layouts. For this, the
|
||||
:ref:`Control.rect_size <class_Control_rect_size>`
|
||||
member variable is provided. Checking it during _draw() is vital to ensure
|
||||
:ref:`Control.rect_size <class_Control_property_rect_size>`
|
||||
property is provided. Checking it during ``_draw()`` is vital to ensure
|
||||
everything is kept in-bounds.
|
||||
|
||||
Checking focus
|
||||
@@ -35,11 +35,11 @@ Checking focus
|
||||
Some controls (such as buttons or text editors) might provide input
|
||||
focus for keyboard or joypad input. Examples of this are entering text
|
||||
or pressing a button. This is controlled with the
|
||||
:ref:`Control.focus_mode <class_Control_focus_mode>`
|
||||
member variable. When drawing, and if the control supports input focus, it is
|
||||
always desired to show some sort of indicator (highlight, box, etc) to
|
||||
:ref:`Control.focus_mode <class_Control_property_focus_mode>`
|
||||
property. When drawing, and if the control supports input focus, it is
|
||||
always desired to show some sort of indicator (highlight, box, etc.) to
|
||||
indicate that this is the currently focused control. To check for this
|
||||
status, the :ref:`Control.has_focus() <class_Control_has_focus>` method
|
||||
status, the :ref:`Control.has_focus() <class_Control_method_has_focus>` method
|
||||
exists. Example
|
||||
|
||||
.. tabs::
|
||||
@@ -77,7 +77,7 @@ the minimum size will make sure your custom control is not squished by
|
||||
the other controls in the container.
|
||||
|
||||
To provide this callback, just override
|
||||
:ref:`Control.get_minimum_size() <class_Control_get_minimum_size>`,
|
||||
:ref:`Control.get_minimum_size() <class_Control_method_get_minimum_size>`,
|
||||
for example:
|
||||
|
||||
.. tabs::
|
||||
@@ -125,10 +125,10 @@ when:
|
||||
- The button was pressed over this control (control always
|
||||
captures input until button is released)
|
||||
- Control provides keyboard/joypad focus via
|
||||
:ref:`Control.focus_mode <class_Control_focus_mode>`.
|
||||
:ref:`Control.focus_mode <class_Control_property_focus_mode>`.
|
||||
|
||||
This function is
|
||||
:ref:`Control._gui_input() <class_Control__gui_input>`.
|
||||
:ref:`Control._gui_input() <class_Control_method__gui_input>`.
|
||||
Simply override it in your control. No processing needs to be set.
|
||||
|
||||
.. tabs::
|
||||
|
||||
@@ -90,7 +90,7 @@ children and grand children labels) will use that color.
|
||||
|
||||
It is possible to override those options without using the theme
|
||||
directly and only for a specific control by using the override API in
|
||||
:ref:`Control.add_color_override() <class_Control_add_color_override>`:
|
||||
:ref:`Control.add_color_override() <class_Control_method_add_color_override>`:
|
||||
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
@@ -56,7 +56,7 @@ will automatically fetch a translation if their text matches a translation key.
|
||||
For example, if a label's text is "MAIN_SCREEN_GREETING1" and that key exists
|
||||
in the current translation, then the text will be automatically translated.
|
||||
|
||||
In code, the :ref:`Object.tr() <class_Object_tr>`
|
||||
In code, the :ref:`Object.tr() <class_Object_method_tr>`
|
||||
function can be used. This will just look up the text in the
|
||||
translations and convert it if found:
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ Create a Node and attach the following script.
|
||||
}
|
||||
|
||||
.. note::
|
||||
Check :ref:`Input.set_custom_mouse_cursor() <class_Input_set_custom_mouse_cursor>`.
|
||||
Check :ref:`Input.set_custom_mouse_cursor() <class_Input_method_set_custom_mouse_cursor>`.
|
||||
|
||||
|
||||
Demo project
|
||||
|
||||
@@ -74,30 +74,30 @@ received input, in order:
|
||||
|
||||
.. image:: img/input_event_flow.png
|
||||
|
||||
1. First of all, the standard :ref:`Node._input() <class_Node__input>` function
|
||||
will be called in any node that overrides it (and hasn't disabled input processing with :ref:`Node.set_process_input() <class_Node_set_process_input>`).
|
||||
If any function consumes the event, it can call :ref:`SceneTree.set_input_as_handled() <class_SceneTree_set_input_as_handled>`, and the event will
|
||||
1. First of all, the standard :ref:`Node._input() <class_Node_method__input>` function
|
||||
will be called in any node that overrides it (and hasn't disabled input processing with :ref:`Node.set_process_input() <class_Node_method_set_process_input>`).
|
||||
If any function consumes the event, it can call :ref:`SceneTree.set_input_as_handled() <class_SceneTree_method_set_input_as_handled>`, and the event will
|
||||
not spread any more. This ensures that you can filter all events of interest, even before the GUI.
|
||||
For gameplay input, :ref:`Node._unhandled_input() <class_Node__unhandled_input>` is generally a better fit, because it allows the GUI to intercept the events.
|
||||
For gameplay input, :ref:`Node._unhandled_input() <class_Node_method__unhandled_input>` is generally a better fit, because it allows the GUI to intercept the events.
|
||||
2. Second, it will try to feed the input to the GUI, and see if any
|
||||
control can receive it. If so, the :ref:`Control <class_Control>` will be called via the
|
||||
virtual function :ref:`Control._gui_input() <class_Control__gui_input>` and the signal
|
||||
virtual function :ref:`Control._gui_input() <class_Control_method__gui_input>` and the signal
|
||||
"input_event" will be emitted (this function is re-implementable by
|
||||
script by inheriting from it). If the control wants to "consume" the
|
||||
event, it will call :ref:`Control.accept_event() <class_Control_accept_event>` and the event will
|
||||
not spread any more. Use :ref:`Control.mouse_filter <class_Control_mouse_filter>`
|
||||
event, it will call :ref:`Control.accept_event() <class_Control_method_accept_event>` and the event will
|
||||
not spread any more. Use the :ref:`Control.mouse_filter <class_Control_property_mouse_filter>`
|
||||
property to control whether a :ref:`Control <class_Control>` is notified
|
||||
of mouse events via :ref:`Control._gui_input() <class_Control__gui_input>`
|
||||
of mouse events via :ref:`Control._gui_input() <class_Control_method__gui_input>`
|
||||
callback, and whether these events are propagated further.
|
||||
3. If so far no one consumed the event, the unhandled input callback
|
||||
will be called if overridden (and not disabled with
|
||||
:ref:`Node.set_process_unhandled_input() <class_Node_set_process_unhandled_input>`).
|
||||
If any function consumes the event, it can call :ref:`SceneTree.set_input_as_handled() <class_SceneTree_set_input_as_handled>`, and the
|
||||
:ref:`Node.set_process_unhandled_input() <class_Node_method_set_process_unhandled_input>`).
|
||||
If any function consumes the event, it can call :ref:`SceneTree.set_input_as_handled() <class_SceneTree_method_set_input_as_handled>`, and the
|
||||
event will not spread any more. The unhandled input callback is ideal for full-screen gameplay events, so they are not received when a GUI is active.
|
||||
4. If no one wanted the event so far, and a :ref:`Camera <class_Camera>` is assigned
|
||||
to the Viewport, a ray to the physics world (in the ray direction from
|
||||
the click) will be cast. If this ray hits an object, it will call the
|
||||
:ref:`CollisionObject._input_event() <class_CollisionObject__input_event>` function in the relevant
|
||||
:ref:`CollisionObject._input_event() <class_CollisionObject_method__input_event>` function in the relevant
|
||||
physics object (bodies receive this callback by default, but areas do
|
||||
not. This can be configured through :ref:`Area <class_Area>` properties).
|
||||
5. Finally, if the event was unhandled, it will be passed to the next
|
||||
@@ -172,13 +172,13 @@ logic. This allows for:
|
||||
Actions can be created from the Project Settings menu in the Actions
|
||||
tab.
|
||||
|
||||
Any event has the methods :ref:`InputEvent.is_action() <class_InputEvent_is_action>`,
|
||||
:ref:`InputEvent.is_pressed() <class_InputEvent_is_pressed>` and :ref:`InputEvent <class_InputEvent>`.
|
||||
Any event has the methods :ref:`InputEvent.is_action() <class_InputEvent_method_is_action>`,
|
||||
:ref:`InputEvent.is_pressed() <class_InputEvent_method_is_pressed>` and :ref:`InputEvent <class_InputEvent>`.
|
||||
|
||||
Alternatively, it may be desired to supply the game back with an action
|
||||
from the game code (a good example of this is detecting gestures).
|
||||
The Input singleton has a method for this:
|
||||
:ref:`Input.parse_input_event() <class_input_parse_input_event>`. You would normally use it like this:
|
||||
:ref:`Input.parse_input_event() <class_input_method_parse_input_event>`. You would normally use it like this:
|
||||
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
@@ -52,8 +52,8 @@ The next step is to serialize the data. This makes it much easier to
|
||||
read and store to disk. In this case, we're assuming each member of
|
||||
group Persist is an instanced node and thus has a path. GDScript
|
||||
has helper functions for this, such as :ref:`to_json()
|
||||
<class_@GDScript_to_json>` and :ref:`parse_json()
|
||||
<class_@GDScript_parse_json>`, so we will use a dictionary. Our node needs to
|
||||
<class_@GDScript_method_to_json>` and :ref:`parse_json()
|
||||
<class_@GDScript_method_parse_json>`, so we will use a dictionary. Our node needs to
|
||||
contain a save function that returns this data. The save function will look
|
||||
like this:
|
||||
|
||||
|
||||
@@ -264,7 +264,7 @@ This will always work in global coordinates.
|
||||
|
||||
If instead, translation is desired in *local* coordinates of the
|
||||
matrix (towards where the *basis* is oriented), there is the
|
||||
:ref:`Transform2D.translated() <class_Transform2D_translated>`
|
||||
:ref:`Transform2D.translated() <class_Transform2D_method_translated>`
|
||||
method:
|
||||
|
||||
.. tabs::
|
||||
@@ -302,8 +302,8 @@ Local to global coordinates and vice versa
|
||||
|
||||
There are helper methods for converting between local and global coordinates.
|
||||
|
||||
There are :ref:`Node2D.to_local() <class_Node2D_to_local>` and :ref:`Node2D.to_global() <class_Node2D_to_global>` for 2D
|
||||
as well as :ref:`Spatial.to_local() <class_Spatial_to_local>` and :ref:`Spatial.to_global() <class_Spatial_to_global>` for 3D.
|
||||
There are :ref:`Node2D.to_local() <class_Node2D_method_to_local>` and :ref:`Node2D.to_global() <class_Node2D_method_to_global>` for 2D
|
||||
as well as :ref:`Spatial.to_local() <class_Spatial_method_to_local>` and :ref:`Spatial.to_global() <class_Spatial_method_to_global>` for 3D.
|
||||
|
||||
Scale
|
||||
~~~~~
|
||||
@@ -613,7 +613,7 @@ vectors for the rotation matrix, and an extra one for the origin.
|
||||
Basis
|
||||
~~~~~
|
||||
|
||||
Godot has a special type for a 3x3 matrix, named :ref:`Basis <class_basis>`.
|
||||
Godot has a special type for a 3x3 matrix, named :ref:`Basis <class_Basis>`.
|
||||
It can be used to represent a 3D rotation and scale. Sub vectors can be
|
||||
accessed as:
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ scenes which one instances and adds to the tree at runtime:
|
||||
func _add_a_scene_manually():
|
||||
# This is like autoloading the scene, only
|
||||
# it happens after already loading the main scene.
|
||||
get_tree().get_root().add_child(simultaneous_scene)
|
||||
get_tree().get_root().add_child(simultaneous_scene)
|
||||
|
||||
.. code-tab:: csharp
|
||||
|
||||
@@ -30,7 +30,7 @@ scenes which one instances and adds to the tree at runtime:
|
||||
|
||||
public void _AddASceneManually()
|
||||
{
|
||||
// this is like autoloading the scene, only
|
||||
// This is like autoloading the scene, only
|
||||
// it happens after already loading the main scene.
|
||||
GetTree().GetRoot().AddChild(simultaneousScene);
|
||||
}
|
||||
@@ -42,10 +42,11 @@ balancing operation speed and memory consumption as well as balancing data
|
||||
access and integrity.
|
||||
|
||||
1. **We can delete the existing scene.**
|
||||
:ref:`SceneTree.change_scene/_to <class_SceneTree_change_scene>` will
|
||||
delete the current scene immediately. Developers can also delete the
|
||||
main scene though. Assuming the root node's name is "Main", one could do
|
||||
`get_node("/root/Main").free()` to delete the whole scene.
|
||||
:ref:`SceneTree.change_scene() <class_SceneTree_method_change_scene>` and
|
||||
:ref:`SceneTree.change_scene_to() <class_SceneTree_method_change_scene_to>`
|
||||
will delete the current scene immediately. Developers can also delete the
|
||||
main scene though. Assuming the root node's name is "Main", one could do
|
||||
``get_node("/root/Main").free()`` to delete the whole scene.
|
||||
|
||||
- Unloads memory.
|
||||
|
||||
@@ -99,7 +100,7 @@ main scene though. Assuming the root node's name is "Main", one could do
|
||||
|
||||
3. **We can remove the existing scene from the tree.** Assign a variable
|
||||
to the existing scene's root node. Then use
|
||||
:ref:`Node.remove_child(Node) <class_Node_remove_child>` to detach the entire
|
||||
:ref:`Node.remove_child(Node) <class_Node_method_remove_child>` to detach the entire
|
||||
scene from the tree.
|
||||
|
||||
- Memory still exists (similar pros/cons as with hiding it from view).
|
||||
@@ -136,4 +137,4 @@ screen. Minimaps and split-screen multiplayer are good examples.
|
||||
|
||||
Each option will have cases where it is best appropriate, so one must
|
||||
examine the effects of each and determine what path best fits
|
||||
their unique situation.
|
||||
their unique situation.
|
||||
|
||||
@@ -20,8 +20,7 @@ How pausing works
|
||||
-----------------
|
||||
|
||||
To set pause mode, the pause state must be set. This is done by assigning
|
||||
"true" to the :ref:`SceneTree.paused <class_SceneTree_paused>` member
|
||||
variable:
|
||||
``true`` to the :ref:`SceneTree.paused <class_SceneTree_property_paused>` property:
|
||||
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
@@ -35,8 +34,8 @@ variable:
|
||||
Doing so will have the following behavior:
|
||||
|
||||
- 2D and 3D physics will be stopped.
|
||||
- _process and _physics_process will not be called anymore in nodes.
|
||||
- _input and _input_event will not be called anymore either.
|
||||
- ``_process and ``_physics_process`` will not be called anymore in nodes.
|
||||
- ``_input`` and ``_input_event`` will not be called anymore either.
|
||||
|
||||
This effectively stops the whole game. Calling this function from a
|
||||
script, by default, will result in an unrecoverable state (nothing will
|
||||
|
||||
@@ -129,7 +129,7 @@ Server and Clients:
|
||||
The above signals are called on every peer connected to the server (including on the server) when a new peer connects or disconnects.
|
||||
Clients will connect with a unique ID greater than 1, while network peer ID 1 is always the server.
|
||||
Anything below 1 should be handled as invalid.
|
||||
You can retrieve the ID for the local system via :ref:`SceneTree.get_network_unique_id() <class_SceneTree_get_network_unique_id>`.
|
||||
You can retrieve the ID for the local system via :ref:`SceneTree.get_network_unique_id() <class_SceneTree_method_get_network_unique_id>`.
|
||||
These IDs will be useful mostly for lobby management and should generally be stored as they identify connected peers and thus players. You can also use IDs to send messages only to certain peers.
|
||||
|
||||
Clients:
|
||||
@@ -347,9 +347,9 @@ The network master of a node is the peer that has the ultimate authority over it
|
||||
When not explicitly set the network master is inherited from the parent node, which if not changed is always going to be the server (ID 1). Thus the server has authority over all nodes by default.
|
||||
|
||||
The network master can be set
|
||||
with the function :ref:`Node.set_network_master(id, recursive) <class_Node_set_network_master>` (recursive is true by default and means the network master is recursively set on all child nodes of the node as well).
|
||||
with the function :ref:`Node.set_network_master(id, recursive) <class_Node_method_set_network_master>` (recursive is true by default and means the network master is recursively set on all child nodes of the node as well).
|
||||
|
||||
Checking that a specific node instance on a peer is the network master for this node for all connected peers is done by calling :ref:`Node.is_network_master() <class_Node_is_network_master>`. This will return true when executed on the server and false on all client peers.
|
||||
Checking that a specific node instance on a peer is the network master for this node for all connected peers is done by calling :ref:`Node.is_network_master() <class_Node_method_is_network_master>`. This will return true when executed on the server and false on all client peers.
|
||||
|
||||
If you have paid attention to the previous example, it's possible you noticed that the local peer is set to have network master authority for their own player instead of the server:
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ Moving the Kinematic character
|
||||
Go back to the character scene, and open the script, the magic begins
|
||||
now! Kinematic body will do nothing by default, but it has a
|
||||
useful function called
|
||||
:ref:`KinematicBody2D.move_and_collide() <class_KinematicBody2D_move_and_collide>`.
|
||||
:ref:`KinematicBody2D.move_and_collide() <class_KinematicBody2D_method_move_and_collide>`.
|
||||
This function takes a :ref:`Vector2 <class_Vector2>` as
|
||||
an argument, and tries to apply that motion to the kinematic body. If a
|
||||
collision happens, it stops right at the moment of the collision.
|
||||
|
||||
@@ -82,7 +82,7 @@ of a body's state variables such as ``position`` or ``linear velocity``
|
||||
may not be accurate for the current frame.
|
||||
|
||||
In order to avoid this inaccuracy, any code that needs to access a body's properties should
|
||||
be run in the :ref:`Node._physics_process() <class_Node__physics_process>`
|
||||
be run in the :ref:`Node._physics_process() <class_Node_method__physics_process>`
|
||||
callback, which is called before each physics step at a constant frame rate
|
||||
(60 times per second by default).
|
||||
|
||||
@@ -207,7 +207,7 @@ automatically be calculated by the physics engine.
|
||||
However, if you do wish to have some control over the body, you should take
|
||||
care - altering the ``position``, ``linear_velocity``, or other physics properties
|
||||
of a rigid body can result in unexpected behavior. If you need to alter any
|
||||
of the physics-related properties, you should use the :ref:`_integrate_forces() <class_RigidBody2D__integrate_forces>`
|
||||
of the physics-related properties, you should use the :ref:`_integrate_forces() <class_RigidBody2D_method__integrate_forces>`
|
||||
callback instead of ``_physics_process()``. In this callback, you have access
|
||||
to the body's :ref:`Physics2DDirectBodyState <class_Physics2DDirectBodyState>`,
|
||||
which allows for safely changing properties and synchronizing them with
|
||||
@@ -265,7 +265,7 @@ the body and letting the physics engine calculate the resulting movement.
|
||||
.. note:: When a rigid body goes to sleep, the ``_integrate_forces()``
|
||||
function will not be called. To override this behavior, you will
|
||||
need to keep the body awake by creating a collision, applying a
|
||||
force to it, or by disabling the :ref:`can_sleep <class_RigidBody2D_can_sleep>`
|
||||
force to it, or by disabling the :ref:`can_sleep <class_RigidBody2D_property_can_sleep>`
|
||||
property. Be aware that this can have a negative effect on performance.
|
||||
|
||||
Contact reporting
|
||||
@@ -273,12 +273,12 @@ Contact reporting
|
||||
|
||||
By default, rigid bodies do not keep track of contacts, because this can
|
||||
require a huge amount of memory if many bodies are in the scene. To enable
|
||||
contact reporting, set the :ref:`contacts_reported <class_RigidBody2D_contacts_reported>`
|
||||
contact reporting, set the :ref:`contacts_reported <class_RigidBody2D_property_contacts_reported>`
|
||||
property to a non-zero value. The contacts can then be obtained via
|
||||
:ref:`Physics2DDirectBodyState.get_contact_count() <class_Physics2DDirectBodyState_get_contact_count>`
|
||||
:ref:`Physics2DDirectBodyState.get_contact_count() <class_Physics2DDirectBodyState_method_get_contact_count>`
|
||||
and related functions.
|
||||
|
||||
Contact monitoring via signals can be enabled via the :ref:`contact_monitor <class_RigidBody2D_contact_monitor>`
|
||||
Contact monitoring via signals can be enabled via the :ref:`contact_monitor <class_RigidBody2D_property_contact_monitor>`
|
||||
property. See :ref:`RigidBody2D <class_RigidBody2D>` for the list of available
|
||||
signals.
|
||||
|
||||
@@ -303,8 +303,8 @@ After a collision, you may want the body to bounce, to slide along a wall,
|
||||
or to alter the properties of the object it hit. The way you handle collision
|
||||
response depends on which method you used to move the KinematicBody2D.
|
||||
|
||||
:ref:`move_and_collide <class_KinematicBody2D_move_and_collide>`
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
:ref:`move_and_collide <class_KinematicBody2D_method_move_and_collide>`
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
When using ``move_and_collide()``, the function returns a
|
||||
:ref:`KinematicCollision2D <class_KinematicCollision2D>` object, which contains
|
||||
@@ -370,8 +370,8 @@ Or to bounce off of the colliding object:
|
||||
}
|
||||
}
|
||||
|
||||
:ref:`move_and_slide <class_KinematicBody2D_move_and_slide>`
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
:ref:`move_and_slide <class_KinematicBody2D_method_move_and_slide>`
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Sliding is a common collision response; imagine a player moving along walls
|
||||
in a top-down game or running up and down slopes in a platformer. While it's
|
||||
|
||||
@@ -27,8 +27,8 @@ Space
|
||||
In the physics world, Godot stores all the low level collision and
|
||||
physics information in a *space*. The current 2d space (for 2D Physics)
|
||||
can be obtained by accessing
|
||||
:ref:`CanvasItem.get_world_2d().space <class_CanvasItem_get_world_2d>`.
|
||||
For 3D, it's :ref:`Spatial.get_world().space <class_Spatial_get_world>`.
|
||||
:ref:`CanvasItem.get_world_2d().space <class_CanvasItem_method_get_world_2d>`.
|
||||
For 3D, it's :ref:`Spatial.get_world().space <class_Spatial_method_get_world>`.
|
||||
|
||||
The resulting space :ref:`RID <class_RID>` can be used in
|
||||
:ref:`PhysicsServer <class_PhysicsServer>` and
|
||||
@@ -40,7 +40,7 @@ Accessing space
|
||||
Godot physics runs by default in the same thread as game logic, but may
|
||||
be set to run on a separate thread to work more efficiently. Due to
|
||||
this, the only time accessing space is safe is during the
|
||||
:ref:`Node._physics_process() <class_Node__physics_process>`
|
||||
:ref:`Node._physics_process() <class_Node_method__physics_process>`
|
||||
callback. Accessing it from outside this function may result in an error
|
||||
due to space being *locked*.
|
||||
|
||||
@@ -100,7 +100,7 @@ Raycast query
|
||||
-------------
|
||||
|
||||
For performing a 2D raycast query, the method
|
||||
:ref:`Physics2DDirectSpaceState.intersect_ray() <class_Physics2DDirectSpaceState_intersect_ray>`
|
||||
:ref:`Physics2DDirectSpaceState.intersect_ray() <class_Physics2DDirectSpaceState_method_intersect_ray>`
|
||||
may be used. For example:
|
||||
|
||||
.. tabs::
|
||||
|
||||
@@ -65,10 +65,10 @@ when needed:
|
||||
|
||||
When this plugin is activated, it will create a new instance of the import
|
||||
plugin (which we'll soon make) and add it to the editor using the
|
||||
:ref:`add_import_plugin<class_EditorPlugin_add_import_plugin>` method. We store
|
||||
:ref:`add_import_plugin() <class_EditorPlugin_method_add_import_plugin>` method. We store
|
||||
a reference to it in a class member ``import_plugin`` so we can refer to it
|
||||
later when removing it. The
|
||||
:ref:`remove_import_plugin<class_EditorPlugin_remove_import_plugin>` method is
|
||||
:ref:`remove_import_plugin() <class_EditorPlugin_method_remove_import_plugin>` method is
|
||||
called when the plugin is deactivated to clean up the memory and let the editor
|
||||
know the import plugin isn't available anymore.
|
||||
|
||||
@@ -80,7 +80,7 @@ The EditorImportPlugin class
|
||||
----------------------------
|
||||
|
||||
The main character of the show is the
|
||||
:ref:`EditorImportPlugin class<class_EditorImportPlugin>`. It is responsible to
|
||||
:ref:`EditorImportPlugin class <class_EditorImportPlugin>`. It is responsible to
|
||||
implement the methods that are called by Godot when it needs to know how to deal
|
||||
with files.
|
||||
|
||||
@@ -96,7 +96,7 @@ Let's begin to code our plugin, one method at time:
|
||||
return "demos.sillymaterial"
|
||||
|
||||
The first method is the
|
||||
:ref:`get_importer_name<class_EditorImportPlugin_get_importer_name>`. This is a
|
||||
:ref:`get_importer_name()<class_EditorImportPlugin_method_get_importer_name>`. This is a
|
||||
unique name to your plugin that is used by Godot to know which import was used
|
||||
in a certain file. When the files needs to be reimported, the editor will know
|
||||
which plugin to call.
|
||||
@@ -106,7 +106,7 @@ which plugin to call.
|
||||
func get_visible_name():
|
||||
return "Silly Material"
|
||||
|
||||
The :ref:`get_visible_name<class_EditorImportPlugin_get_visible_name>` method is
|
||||
The :ref:`get_visible_name()<class_EditorImportPlugin_method_get_visible_name>` method is
|
||||
responsible to inform the name of the type it imports and will be shown to the
|
||||
user in the Import dock.
|
||||
|
||||
@@ -120,7 +120,7 @@ with a descriptive name for your plugin.
|
||||
return ["mtxt"]
|
||||
|
||||
Godot's import system detects file types by their extension. In the
|
||||
:ref:`get_recognized_extensions<class_EditorImportPlugin_get_recognized_extensions>`
|
||||
:ref:`get_recognized_extensions()<class_EditorImportPlugin_method_get_recognized_extensions>`
|
||||
method you return an array of strings to represent each extension that this
|
||||
plugin can understand. If an extension is recognized by more than one plugin,
|
||||
the user can select which one to use when importing the files.
|
||||
@@ -192,7 +192,7 @@ plugin:
|
||||
func get_preset_count():
|
||||
return Presets.size()
|
||||
|
||||
The :ref:`get_preset_count<class_EditorImportPlugin_get_preset_count>` method
|
||||
The :ref:`get_preset_count() <class_EditorImportPlugin_method_get_preset_count>` method
|
||||
returns the amount of presets that this plugins defines. We only have one preset
|
||||
now, but we can make this method future-proof by returning the size of our
|
||||
``Presets`` enumeration.
|
||||
@@ -208,7 +208,7 @@ now, but we can make this method future-proof by returning the size of our
|
||||
|
||||
|
||||
Here we have the
|
||||
:ref:`get_preset_name<class_EditorImportPlugin_get_preset_name>` method, which
|
||||
:ref:`get_preset_name() <class_EditorImportPlugin_method_get_preset_name>` method, which
|
||||
gives names to the presets as they will be presented to the user, so be sure to
|
||||
use short and clear names.
|
||||
|
||||
@@ -233,24 +233,24 @@ you do this you have to be careful when you add more presets.
|
||||
return []
|
||||
|
||||
This is the method which defines the available options.
|
||||
:ref:`get_import_options<class_EditorImportPlugin_get_import_options>` returns
|
||||
:ref:`get_import_options() <class_EditorImportPlugin_method_get_import_options>` returns
|
||||
an array of dictionaries, and each dictionary contains a few keys that are
|
||||
checked to customize the option as its shown to the user. The following table
|
||||
shows the possible keys:
|
||||
|
||||
+-------------------+------------+---------------------------------------------------------------------------------------------------------+
|
||||
| Key | Type | Description |
|
||||
+===================+============+=========================================================================================================+
|
||||
| ``name`` | String | The name of the option. When showed, underscores become spaces and first letters are capitalized. |
|
||||
+-------------------+------------+---------------------------------------------------------------------------------------------------------+
|
||||
| ``default_value`` | Any | The default value of the option for this preset. |
|
||||
+-------------------+------------+---------------------------------------------------------------------------------------------------------+
|
||||
| ``property_hint`` | Enum value | One of the :ref:`PropertyHint<enum_@GlobalScope_PropertyHint>` values to use as hint. |
|
||||
+-------------------+------------+---------------------------------------------------------------------------------------------------------+
|
||||
| ``hint_string`` | String | The hint text of the property. The same as you'd add in the ``export`` statement in GDScript. |
|
||||
+-------------------+------------+---------------------------------------------------------------------------------------------------------+
|
||||
| ``usage`` | Enum value | One of the :ref:`PropertyUsageFlags<enum_@GlobalScope_PropertyUsageFlags>` values to define the usage. |
|
||||
+-------------------+------------+---------------------------------------------------------------------------------------------------------+
|
||||
+-------------------+------------+----------------------------------------------------------------------------------------------------------+
|
||||
| Key | Type | Description |
|
||||
+===================+============+==========================================================================================================+
|
||||
| ``name`` | String | The name of the option. When showed, underscores become spaces and first letters are capitalized. |
|
||||
+-------------------+------------+----------------------------------------------------------------------------------------------------------+
|
||||
| ``default_value`` | Any | The default value of the option for this preset. |
|
||||
+-------------------+------------+----------------------------------------------------------------------------------------------------------+
|
||||
| ``property_hint`` | Enum value | One of the :ref:`PropertyHint <enum_@GlobalScope_PropertyHint>` values to use as hint. |
|
||||
+-------------------+------------+----------------------------------------------------------------------------------------------------------+
|
||||
| ``hint_string`` | String | The hint text of the property. The same as you'd add in the ``export`` statement in GDScript. |
|
||||
+-------------------+------------+----------------------------------------------------------------------------------------------------------+
|
||||
| ``usage`` | Enum value | One of the :ref:`PropertyUsageFlags <enum_@GlobalScope_PropertyUsageFlags>` values to define the usage. |
|
||||
+-------------------+------------+----------------------------------------------------------------------------------------------------------+
|
||||
|
||||
The ``name`` and ``default_value`` keys are **mandatory**, the rest are optional.
|
||||
|
||||
@@ -271,7 +271,7 @@ of options first and then change it based on the preset.
|
||||
return true
|
||||
|
||||
For the
|
||||
:ref:`get_option_visibility<class_EditorImportPlugin_get_option_visibility>`
|
||||
:ref:`get_option_visibility() <class_EditorImportPlugin_method_get_option_visibility>`
|
||||
method, we simply return ``true`` because all of our options (i.e. the single
|
||||
one we defined) are visible all the time.
|
||||
|
||||
@@ -282,7 +282,7 @@ The ``import`` method
|
||||
---------------------
|
||||
|
||||
The heavy part of the process, responsible for the converting the files into
|
||||
resources, is covered by the :ref:`import<class_EditorImportPlugin_import>`
|
||||
resources, is covered by the :ref:`import() <class_EditorImportPlugin_method_import>`
|
||||
method. Our sample code is a bit long, so let's split in a few parts:
|
||||
|
||||
::
|
||||
@@ -298,7 +298,7 @@ method. Our sample code is a bit long, so let's split in a few parts:
|
||||
file.close()
|
||||
|
||||
The first part of our import method opens and reads the source file. We use the
|
||||
:ref:`File<class_File>` class to do that, passing the ``source_file``
|
||||
:ref:`File <class_File>` class to do that, passing the ``source_file``
|
||||
parameter which is provided by the editor.
|
||||
|
||||
If there's an error when opening the file, we return it to let the editor know
|
||||
@@ -320,7 +320,7 @@ This code takes the line of the file it read before and splits it in pieces
|
||||
that are separated by a comma. If there are more or less than the three values,
|
||||
it considers the file invalid and reports an error.
|
||||
|
||||
Then it creates a new :ref:`Color<class_Color>` variable and sets its values
|
||||
Then it creates a new :ref:`Color <class_Color>` variable and sets its values
|
||||
according to the input file. If the ``use_red_anyway`` option is enabled, then
|
||||
it sets the color as a pure red instead.
|
||||
|
||||
@@ -329,7 +329,7 @@ it sets the color as a pure red instead.
|
||||
var material = SpatialMaterial.new()
|
||||
material.albedo_color = color
|
||||
|
||||
This part makes a new :ref:`SpatialMaterial<class_SpatialMaterial>` that is the
|
||||
This part makes a new :ref:`SpatialMaterial <class_SpatialMaterial>` that is the
|
||||
imported resource. We create a new instance of it and then set its albedo color
|
||||
as the value we got before.
|
||||
|
||||
@@ -340,12 +340,12 @@ as the value we got before.
|
||||
This is the last part and quite an important one, because here we save the made
|
||||
resource to the disk. The path of the saved file is generated and informed by
|
||||
the editor via the ``save_path`` parameter. Note that this comes **without** the
|
||||
extension, so we add it using :ref:`string formatting<doc_gdscript_printf>`. For
|
||||
extension, so we add it using :ref:`string formatting <doc_gdscript_printf>`. For
|
||||
this we call the ``get_save_extension`` method that we defined earlier, so we
|
||||
can be sure that they won't get out of sync.
|
||||
|
||||
We also return the result from the
|
||||
:ref:`ResourceSaver.save<class_ResourceSaver_save>` method, so if there's an
|
||||
:ref:`ResourceSaver.save() <class_ResourceSaver_method_save>` method, so if there's an
|
||||
error in this step, the editor will know about it.
|
||||
|
||||
Platform variants and generated files
|
||||
@@ -358,7 +358,7 @@ method. Both of them are arrays that you can fill with information.
|
||||
|
||||
The ``r_platform_variants`` argument is used if you need to import the resource
|
||||
differently depending on the target platform. While it's called *platform*
|
||||
variants, it is based on the presence of :ref:`feature tags<doc_feature_tags>`,
|
||||
variants, it is based on the presence of :ref:`feature tags <doc_feature_tags>`,
|
||||
so even the same platform can have multiple variants depending on the setup.
|
||||
|
||||
To import a platform variant, you need to save it with the feature tag before
|
||||
|
||||
@@ -63,8 +63,8 @@ inherit from :ref:`class_EditorPlugin`.
|
||||
|
||||
It's important to deal with initialization and clean-up of resources.
|
||||
A good practice is to use the virtual function
|
||||
:ref:`_enter_tree() <class_Node__enter_tree>` to initialize your plugin and
|
||||
:ref:`_exit_tree() <class_Node__exit_tree>` to clean it up. You can delete the
|
||||
:ref:`_enter_tree() <class_Node_method__enter_tree>` to initialize your plugin and
|
||||
:ref:`_exit_tree() <class_Node_method__exit_tree>` to clean it up. You can delete the
|
||||
default GDScript template from your file and replace it with the following
|
||||
structure:
|
||||
|
||||
@@ -94,7 +94,7 @@ projects. A good solution to this is to make a plugin that adds a node with a
|
||||
custom behavior.
|
||||
|
||||
To create a new node type, you can use the function
|
||||
:ref:`add_custom_type() <class_EditorPlugin_add_custom_type>` from the
|
||||
:ref:`add_custom_type() <class_EditorPlugin_method_add_custom_type>` from the
|
||||
:ref:`class_EditorPlugin` class. This function can add new types to the editor
|
||||
(nodes or resources). However, before you can create the type, you need a script
|
||||
that will act as the logic for the type. While that script doesn't have to use
|
||||
@@ -188,7 +188,7 @@ Also, don't forget to add some text to your button.
|
||||
|
||||
Save this scene as ``my_dock.tscn``. Now, we need to grab the scene we created
|
||||
then add it as a dock in the editor. For this, you can rely on the function
|
||||
:ref:`add_control_to_dock() <class_EditorPlugin_add_control_to_dock>` from the
|
||||
:ref:`add_control_to_dock() <class_EditorPlugin_method_add_control_to_dock>` from the
|
||||
:ref:`EditorPlugin <class_EditorPlugin>` class.
|
||||
|
||||
You need to select a dock position and define the control to add
|
||||
|
||||
@@ -188,4 +188,4 @@ From scripts
|
||||
|
||||
To configure stretching at runtime from a script, use the
|
||||
``get_tree().set_screen_stretch()`` function (see
|
||||
:ref:`SceneTree.set_screen_stretch<class_SceneTree_set_screen_stretch>`).
|
||||
:ref:`SceneTree.set_screen_stretch() <class_SceneTree_method_set_screen_stretch>`).
|
||||
|
||||
@@ -13,7 +13,7 @@ AR/VR server
|
||||
|
||||
When Godot starts each available interface will make itself known to the AR/VR server. GDNative interfaces are setup as singletons, as long as they are added to the list of GDNative singletons in your project they will make themselves known to the server.
|
||||
|
||||
You can use the function :ref:`get_interfaces <class_ARVRServer_get_interfaces>` to return a list of available interfaces but for this tutorial we're going to use the :ref:`native mobile VR interface <class_MobileVRInterface>` in our examples. This interface is a straightforward implementation that uses the 3DOF sensors on your phone for orientation and outputs a stereoscopic image to screen. It is also available in the Godot core and outputs to screen on desktop which makes it ideal for prototyping or a tutorial such as this one.
|
||||
You can use the function :ref:`get_interfaces() <class_ARVRServer_method_get_interfaces>` to return a list of available interfaces but for this tutorial we're going to use the :ref:`native mobile VR interface <class_MobileVRInterface>` in our examples. This interface is a straightforward implementation that uses the 3DOF sensors on your phone for orientation and outputs a stereoscopic image to screen. It is also available in the Godot core and outputs to screen on desktop which makes it ideal for prototyping or a tutorial such as this one.
|
||||
|
||||
To enable an interface you execute the following code:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user