mirror of
https://github.com/Relintai/pandemonium_engine_docs.git
synced 2025-02-06 16:16:00 +01:00
Remvoed class rst references.
This commit is contained in:
parent
d4b40dfad4
commit
ad9a190287
@ -71,7 +71,7 @@ Some games have a special menu (often in the settings) to display licenses.
|
|||||||
Output log
|
Output log
|
||||||
^^^^^^^^^^
|
^^^^^^^^^^
|
||||||
|
|
||||||
Just printing the licensing text using the `print() <class_@GDScript_method_print>`
|
Just printing the licensing text using the `print()`
|
||||||
function may be enough on platforms where a global output log is readable.
|
function may be enough on platforms where a global output log is readable.
|
||||||
This is the case on desktop platforms, Android and HTML5 (but not iOS and UWP).
|
This is the case on desktop platforms, Android and HTML5 (but not iOS and UWP).
|
||||||
|
|
||||||
|
@ -433,7 +433,7 @@ Yes! Godot features an extensive built-in UI system, and its small distribution
|
|||||||
size can make it a suitable alternative to frameworks like Electron or Qt.
|
size can make it a suitable alternative to frameworks like Electron or Qt.
|
||||||
|
|
||||||
When creating a non-game application, make sure to enable
|
When creating a non-game application, make sure to enable
|
||||||
`low-processor mode <class_ProjectSettings_property_application/run/low_processor_mode>`
|
`low-processor mode`
|
||||||
in the Project Settings to decrease CPU and GPU usage.
|
in the Project Settings to decrease CPU and GPU usage.
|
||||||
|
|
||||||
That said, we wouldn't recommend using Godot to create a *mobile* application
|
That said, we wouldn't recommend using Godot to create a *mobile* application
|
||||||
|
@ -563,11 +563,11 @@ The editor UI can easily be extended in many ways using add-ons.
|
|||||||
- Anchors to keep GUI elements in a specific corner, edge or centered.
|
- Anchors to keep GUI elements in a specific corner, edge or centered.
|
||||||
- Containers to place GUI elements automatically following certain rules.
|
- Containers to place GUI elements automatically following certain rules.
|
||||||
|
|
||||||
- `Stack <class_BoxContainer>` layouts.
|
- `Stack` layouts.
|
||||||
- `Grid <class_GridContainer>` layouts.
|
- `Grid` layouts.
|
||||||
- `Margin <class_MarginContainer>` and `centered <class_CenterContainer>`
|
- `Margin`
|
||||||
layouts.
|
layouts.
|
||||||
- `Draggable splitter <class_SplitContainer>` layouts.
|
- `Draggable splitter` layouts.
|
||||||
|
|
||||||
- Scale to multiple resolutions using the ``2d`` or ``viewport`` stretch modes.
|
- Scale to multiple resolutions using the ``2d`` or ``viewport`` stretch modes.
|
||||||
- Support any aspect ratio using anchors and the ``expand`` stretch aspect.
|
- Support any aspect ratio using anchors and the ``expand`` stretch aspect.
|
||||||
@ -591,7 +591,7 @@ Animation
|
|||||||
^^^^^^^^^
|
^^^^^^^^^
|
||||||
|
|
||||||
- Direct kinematics and inverse kinematics.
|
- Direct kinematics and inverse kinematics.
|
||||||
- `Tween <class_Tween>` node to easily perform procedural animations by code.
|
- `Tween` node to easily perform procedural animations by code.
|
||||||
- Support for animating any property with customizable interpolation.
|
- Support for animating any property with customizable interpolation.
|
||||||
- Support for calling methods in animation tracks.
|
- Support for calling methods in animation tracks.
|
||||||
- Support for playing sounds in animation tracks.
|
- Support for playing sounds in animation tracks.
|
||||||
|
@ -127,17 +127,17 @@ the text. Here's the list of available tags:
|
|||||||
+============================+======================================+===================================+===================================================+
|
+============================+======================================+===================================+===================================================+
|
||||||
| [Class] | Link a class | Move the [Sprite]. | Move the `class_Sprite`. |
|
| [Class] | Link a class | Move the [Sprite]. | Move the `class_Sprite`. |
|
||||||
+----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
|
+----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
|
||||||
| [method methodname] | Link to a method in this class | Call [method hide]. | Call `hide <class_Spatial_method_hide>`. |
|
| [method methodname] | Link to a method in this class | Call [method hide]. | Call `hide`. |
|
||||||
+----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
|
+----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
|
||||||
| [method Class.methodname] | Link to another class's method | Call [method Spatial.hide]. | Call `hide <class_Spatial_method_hide>`. |
|
| [method Class.methodname] | Link to another class's method | Call [method Spatial.hide]. | Call `hide`. |
|
||||||
+----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
|
+----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
|
||||||
| [member membername] | Link to a member in this class | Get [member scale]. | Get `scale <class_Node2D_property_scale>`. |
|
| [member membername] | Link to a member in this class | Get [member scale]. | Get `scale`. |
|
||||||
+----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
|
+----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
|
||||||
| [member Class.membername] | Link to another class's member | Get [member Node2D.scale]. | Get `scale <class_Node2D_property_scale>`. |
|
| [member Class.membername] | Link to another class's member | Get [member Node2D.scale]. | Get `scale`. |
|
||||||
+----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
|
+----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
|
||||||
| [signal signalname] | Link to a signal in this class | Emit [signal renamed]. | Emit `renamed <class_Node_signal_renamed>`. |
|
| [signal signalname] | Link to a signal in this class | Emit [signal renamed]. | Emit `renamed`. |
|
||||||
+----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
|
+----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
|
||||||
| [signal Class.signalname] | Link to another class's signal | Emit [signal Node.renamed]. | Emit `renamed <class_Node_signal_renamed>`. |
|
| [signal Class.signalname] | Link to another class's signal | Emit [signal Node.renamed]. | Emit `renamed`. |
|
||||||
+----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
|
+----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
|
||||||
| [b] [/b] | Bold | Some [b]bold[/b] text. | Some **bold** text. |
|
| [b] [/b] | Bold | Some [b]bold[/b] text. | Some **bold** text. |
|
||||||
+----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
|
+----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
|
||||||
|
@ -6,12 +6,12 @@ Object class
|
|||||||
.. seealso::
|
.. seealso::
|
||||||
|
|
||||||
This page describes the C++ implementation of objects in Godot.
|
This page describes the C++ implementation of objects in Godot.
|
||||||
Looking for the Object class reference? `Have a look here. <class_Object>`
|
Looking for the Object class reference? `Have a look here.`
|
||||||
|
|
||||||
General definition
|
General definition
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
`Object <class_object>` is the base class for almost everything. Most classes in Godot
|
`Object` is the base class for almost everything. Most classes in Godot
|
||||||
inherit directly or indirectly from it. Objects provide reflection and
|
inherit directly or indirectly from it. Objects provide reflection and
|
||||||
editable properties, and declaring them is a matter of using a single
|
editable properties, and declaring them is a matter of using a single
|
||||||
macro like this.
|
macro like this.
|
||||||
@ -240,14 +240,14 @@ Adding signals to a class is done in ``_bind_methods``, using the
|
|||||||
Notifications
|
Notifications
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
All objects in Godot have a `_notification <class_Object_method__notification>`
|
All objects in Godot have a `_notification`
|
||||||
method that allows it to respond to engine level callbacks that may relate to it.
|
method that allows it to respond to engine level callbacks that may relate to it.
|
||||||
More information can be found on the `doc_godot_notifications` page.
|
More information can be found on the `doc_godot_notifications` page.
|
||||||
|
|
||||||
References
|
References
|
||||||
----------
|
----------
|
||||||
|
|
||||||
`Reference <class_reference>` inherits from Object and holds a
|
`Reference` inherits from Object and holds a
|
||||||
reference count. It is the base for reference counted object types.
|
reference count. It is the base for reference counted object types.
|
||||||
Declaring them must be done using Ref<> template. For example:
|
Declaring them must be done using Ref<> template. For example:
|
||||||
|
|
||||||
@ -270,7 +270,7 @@ References:
|
|||||||
Resources:
|
Resources:
|
||||||
----------
|
----------
|
||||||
|
|
||||||
`Resource <class_resource>` inherits from Reference, so all resources
|
`Resource` inherits from Reference, so all resources
|
||||||
are reference counted. Resources can optionally contain a path, which
|
are reference counted. Resources can optionally contain a path, which
|
||||||
reference a file on disk. This can be set with ``resource.set_path(path)``.
|
reference a file on disk. This can be set with ``resource.set_path(path)``.
|
||||||
This is normally done by the resource loader though. No two different
|
This is normally done by the resource loader though. No two different
|
||||||
|
@ -80,7 +80,7 @@ heading.
|
|||||||
|
|
||||||
.. image:: img/player_scale.png
|
.. image:: img/player_scale.png
|
||||||
|
|
||||||
Finally, add a `CollisionShape2D <class_CollisionShape2D>` as a child of
|
Finally, add a `CollisionShape2D` as a child of
|
||||||
``Player``. This will determine the player's "hitbox", or the bounds of its
|
``Player``. This will determine the player's "hitbox", or the bounds of its
|
||||||
collision area. For this character, a ``CapsuleShape2D`` node gives the best
|
collision area. For this character, a ``CapsuleShape2D`` node gives the best
|
||||||
fit, so next to "Shape" in the Inspector, click "[empty]"" -> "New
|
fit, so next to "Shape" in the Inspector, click "[empty]"" -> "New
|
||||||
|
@ -15,23 +15,23 @@ Node setup
|
|||||||
|
|
||||||
Click Scene -> New Scene and add the following nodes:
|
Click Scene -> New Scene and add the following nodes:
|
||||||
|
|
||||||
- `RigidBody2D <class_RigidBody2D>` (named ``Mob``)
|
- `RigidBody2D` (named ``Mob``)
|
||||||
|
|
||||||
- `AnimatedSprite <class_AnimatedSprite>`
|
- `AnimatedSprite`
|
||||||
- `CollisionShape2D <class_CollisionShape2D>`
|
- `CollisionShape2D`
|
||||||
- `VisibilityNotifier2D <class_VisibilityNotifier2D>`
|
- `VisibilityNotifier2D`
|
||||||
|
|
||||||
Don't forget to set the children so they can't be selected, like you did with
|
Don't forget to set the children so they can't be selected, like you did with
|
||||||
the Player scene.
|
the Player scene.
|
||||||
|
|
||||||
In the `RigidBody2D <class_RigidBody2D>` properties, set ``Gravity Scale``
|
In the `RigidBody2D` properties, set ``Gravity Scale``
|
||||||
to ``0``, so the mob will not fall downward. In addition, under the
|
to ``0``, so the mob will not fall downward. In addition, under the
|
||||||
`CollisionObject2D <class_CollisionObject2D>` section, click the ``Mask`` property and uncheck the first
|
`CollisionObject2D` section, click the ``Mask`` property and uncheck the first
|
||||||
box. This will ensure the mobs do not collide with each other.
|
box. This will ensure the mobs do not collide with each other.
|
||||||
|
|
||||||
.. image:: img/set_collision_mask.png
|
.. image:: img/set_collision_mask.png
|
||||||
|
|
||||||
Set up the `AnimatedSprite <class_AnimatedSprite>` like you did for the
|
Set up the `AnimatedSprite` like you did for the
|
||||||
player. This time, we have 3 animations: ``fly``, ``swim``, and ``walk``. There
|
player. This time, we have 3 animations: ``fly``, ``swim``, and ``walk``. There
|
||||||
are two images for each animation in the art folder.
|
are two images for each animation in the art folder.
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ The main game scene
|
|||||||
|
|
||||||
Now it's time to bring everything we did together into a playable game scene.
|
Now it's time to bring everything we did together into a playable game scene.
|
||||||
|
|
||||||
Create a new scene and add a `Node <class_Node>` named ``Main``.
|
Create a new scene and add a `Node` named ``Main``.
|
||||||
(The reason we are using Node instead of Node2D is because this node will
|
(The reason we are using Node instead of Node2D is because this node will
|
||||||
be a container for handling game logic. It does not require 2D functionality itself.)
|
be a container for handling game logic. It does not require 2D functionality itself.)
|
||||||
|
|
||||||
@ -17,13 +17,13 @@ Click the **Instance** button (represented by a chain link icon) and select your
|
|||||||
Now, add the following nodes as children of ``Main``, and name them as shown
|
Now, add the following nodes as children of ``Main``, and name them as shown
|
||||||
(values are in seconds):
|
(values are in seconds):
|
||||||
|
|
||||||
- `Timer <class_Timer>` (named ``MobTimer``) - to control how often mobs
|
- `Timer` (named ``MobTimer``) - to control how often mobs
|
||||||
spawn
|
spawn
|
||||||
- `Timer <class_Timer>` (named ``ScoreTimer``) - to increment the score
|
- `Timer` (named ``ScoreTimer``) - to increment the score
|
||||||
every second
|
every second
|
||||||
- `Timer <class_Timer>` (named ``StartTimer``) - to give a delay before
|
- `Timer` (named ``StartTimer``) - to give a delay before
|
||||||
starting
|
starting
|
||||||
- `Position2D <class_Position2D>` (named ``StartPosition``) - to indicate
|
- `Position2D` (named ``StartPosition``) - to indicate
|
||||||
the player's start position
|
the player's start position
|
||||||
|
|
||||||
Set the ``Wait Time`` property of each of the ``Timer`` nodes as follows:
|
Set the ``Wait Time`` property of each of the ``Timer`` nodes as follows:
|
||||||
@ -39,7 +39,7 @@ Spawning mobs
|
|||||||
~~~~~~~~~~~~~
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
The Main node will be spawning new mobs, and we want them to appear at a random
|
The Main node will be spawning new mobs, and we want them to appear at a random
|
||||||
location on the edge of the screen. Add a `Path2D <class_Path2D>` node
|
location on the edge of the screen. Add a `Path2D` node
|
||||||
named ``MobPath`` as a child of ``Main``. When you select ``Path2D``, you will
|
named ``MobPath`` as a child of ``Main``. When you select ``Path2D``, you will
|
||||||
see some new buttons at the top of the editor:
|
see some new buttons at the top of the editor:
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ intersecting lines, respectively.
|
|||||||
After placing point ``4`` in the image, click the "Close Curve" button and your
|
After placing point ``4`` in the image, click the "Close Curve" button and your
|
||||||
curve will be complete.
|
curve will be complete.
|
||||||
|
|
||||||
Now that the path is defined, add a `PathFollow2D <class_PathFollow2D>`
|
Now that the path is defined, add a `PathFollow2D`
|
||||||
node as a child of ``MobPath`` and name it ``MobSpawnLocation``. This node will
|
node as a child of ``MobPath`` and name it ``MobSpawnLocation``. This node will
|
||||||
automatically rotate and follow the path as it moves, so we can use it to select
|
automatically rotate and follow the path as it moves, so we can use it to select
|
||||||
a random position and direction along the path.
|
a random position and direction along the path.
|
||||||
|
@ -6,11 +6,11 @@ Heads up display
|
|||||||
The final piece our game needs is a User Interface (UI) to display things like
|
The final piece our game needs is a User Interface (UI) to display things like
|
||||||
score, a "game over" message, and a restart button.
|
score, a "game over" message, and a restart button.
|
||||||
|
|
||||||
Create a new scene, and add a `CanvasLayer <class_CanvasLayer>` node named
|
Create a new scene, and add a `CanvasLayer` node named
|
||||||
``HUD``. "HUD" stands for "heads-up display", an informational display that
|
``HUD``. "HUD" stands for "heads-up display", an informational display that
|
||||||
appears as an overlay on top of the game view.
|
appears as an overlay on top of the game view.
|
||||||
|
|
||||||
The `CanvasLayer <class_CanvasLayer>` node lets us draw our UI elements on
|
The `CanvasLayer` node lets us draw our UI elements on
|
||||||
a layer above the rest of the game, so that the information it displays isn't
|
a layer above the rest of the game, so that the information it displays isn't
|
||||||
covered up by any game elements like the player or mobs.
|
covered up by any game elements like the player or mobs.
|
||||||
|
|
||||||
@ -20,16 +20,16 @@ The HUD needs to display the following information:
|
|||||||
- A message, such as "Game Over" or "Get Ready!"
|
- A message, such as "Game Over" or "Get Ready!"
|
||||||
- A "Start" button to begin the game.
|
- A "Start" button to begin the game.
|
||||||
|
|
||||||
The basic node for UI elements is `Control <class_Control>`. To create our
|
The basic node for UI elements is `Control`. To create our
|
||||||
UI, we'll use two types of `Control <class_Control>` nodes: `Label
|
UI, we'll use two types of `Control` nodes: `Label
|
||||||
<class_Label>` and `Button <class_Button>`.
|
<class_Label>` and `Button`.
|
||||||
|
|
||||||
Create the following as children of the ``HUD`` node:
|
Create the following as children of the ``HUD`` node:
|
||||||
|
|
||||||
- `Label <class_Label>` named ``ScoreLabel``.
|
- `Label` named ``ScoreLabel``.
|
||||||
- `Label <class_Label>` named ``Message``.
|
- `Label` named ``Message``.
|
||||||
- `Button <class_Button>` named ``StartButton``.
|
- `Button` named ``StartButton``.
|
||||||
- `Timer <class_Timer>` named ``MessageTimer``.
|
- `Timer` named ``MessageTimer``.
|
||||||
|
|
||||||
Click on the ``ScoreLabel`` and type a number into the ``Text`` field in the
|
Click on the ``ScoreLabel`` and type a number into the ``Text`` field in the
|
||||||
Inspector. The default font for ``Control`` nodes is small and doesn't scale
|
Inspector. The default font for ``Control`` nodes is small and doesn't scale
|
||||||
|
@ -12,7 +12,7 @@ Background
|
|||||||
~~~~~~~~~~
|
~~~~~~~~~~
|
||||||
|
|
||||||
The default gray background is not very appealing, so let's change its color.
|
The default gray background is not very appealing, so let's change its color.
|
||||||
One way to do this is to use a `ColorRect <class_ColorRect>` node. Make it
|
One way to do this is to use a `ColorRect` node. Make it
|
||||||
the first node under ``Main`` so that it will be drawn behind the other nodes.
|
the first node under ``Main`` so that it will be drawn behind the other nodes.
|
||||||
``ColorRect`` only has one property: ``Color``. Choose a color you like and
|
``ColorRect`` only has one property: ``Color``. Choose a color you like and
|
||||||
select "Layout" -> "Full Rect" so that it covers the screen.
|
select "Layout" -> "Full Rect" so that it covers the screen.
|
||||||
@ -28,7 +28,7 @@ experience. In your game assets folder, you have two sound files: "House In a
|
|||||||
Forest Loop.ogg" for background music, and "gameover.wav" for when the player
|
Forest Loop.ogg" for background music, and "gameover.wav" for when the player
|
||||||
loses.
|
loses.
|
||||||
|
|
||||||
Add two `AudioStreamPlayer <class_AudioStreamPlayer>` nodes as children of
|
Add two `AudioStreamPlayer` nodes as children of
|
||||||
``Main``. Name one of them ``Music`` and the other ``DeathSound``. On each one,
|
``Main``. Name one of them ``Music`` and the other ``DeathSound``. On each one,
|
||||||
click on the ``Stream`` property, select "Load", and choose the corresponding
|
click on the ``Stream`` property, select "Load", and choose the corresponding
|
||||||
audio file.
|
audio file.
|
||||||
|
@ -15,8 +15,8 @@ pack information about your scene's content.
|
|||||||
|
|
||||||
Here's an example of a ball. It's composed of a `RigidBody2D
|
Here's an example of a ball. It's composed of a `RigidBody2D
|
||||||
<class_RigidBody2D>` node as its root named Ball, which allows the ball to fall
|
<class_RigidBody2D>` node as its root named Ball, which allows the ball to fall
|
||||||
and bounce on walls, a `Sprite <class_Sprite>` node, and a
|
and bounce on walls, a `Sprite` node, and a
|
||||||
`CollisionShape2D <class_CollisionShape2D>`.
|
`CollisionShape2D`.
|
||||||
|
|
||||||
.. image:: img/instancing_ball_scene.png
|
.. image:: img/instancing_ball_scene.png
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ node, including classes it extends, like ``Node2D``, ``CanvasItem``, and
|
|||||||
``Node``.
|
``Node``.
|
||||||
|
|
||||||
.. note:: In GDScript, if you omit the line with the ``extends`` keyword, your
|
.. note:: In GDScript, if you omit the line with the ``extends`` keyword, your
|
||||||
class will implicitly extend `Reference <class_Reference>`, which
|
class will implicitly extend `Reference`, which
|
||||||
Godot uses to manage your application's memory.
|
Godot uses to manage your application's memory.
|
||||||
|
|
||||||
Inherited properties include the ones you can see in the Inspector dock, like
|
Inherited properties include the ones you can see in the Inspector dock, like
|
||||||
@ -253,7 +253,7 @@ is a vector pointing forward relative to our icon. Multiplied by our ``speed``
|
|||||||
property, it gives us a velocity we can use to move the node forward.
|
property, it gives us a velocity we can use to move the node forward.
|
||||||
|
|
||||||
We add ``velocity * delta`` to the node's ``position`` to move it. The position
|
We add ``velocity * delta`` to the node's ``position`` to move it. The position
|
||||||
itself is of type `Vector2 <class_Vector2>`, a built-in type in Godot
|
itself is of type `Vector2`, a built-in type in Godot
|
||||||
representing a 2D vector.
|
representing a 2D vector.
|
||||||
|
|
||||||
Run the scene to see the Godot head run in circles.
|
Run the scene to see the Godot head run in circles.
|
||||||
|
@ -198,7 +198,7 @@ Connecting a signal via code
|
|||||||
You can connect signals via code instead of using the editor. This is necessary
|
You can connect signals via code instead of using the editor. This is necessary
|
||||||
when you create nodes or instantiate scenes inside of a script.
|
when you create nodes or instantiate scenes inside of a script.
|
||||||
|
|
||||||
Let's use a different node here. Godot has a `Timer <class_Timer>` node
|
Let's use a different node here. Godot has a `Timer` node
|
||||||
that's useful to implement skill cooldown times, weapon reloading, and more.
|
that's useful to implement skill cooldown times, weapon reloading, and more.
|
||||||
|
|
||||||
Head back to the 2D workspace. You can either click the "2D" text at the top of
|
Head back to the 2D workspace. You can either click the "2D" text at the top of
|
||||||
@ -229,11 +229,11 @@ We need to do two operations to connect the nodes via code:
|
|||||||
listen to the Timer's "timeout" signal.
|
listen to the Timer's "timeout" signal.
|
||||||
|
|
||||||
We want to connect the signal when the scene is instantiated, and we can do that
|
We want to connect the signal when the scene is instantiated, and we can do that
|
||||||
using the `Node._ready() <class_Node_method__ready>` built-in function,
|
using the `Node._ready()` built-in function,
|
||||||
which is called automatically by the engine when a node is fully instantiated.
|
which is called automatically by the engine when a node is fully instantiated.
|
||||||
|
|
||||||
To get a reference to a node relative to the current one, we use the method
|
To get a reference to a node relative to the current one, we use the method
|
||||||
`Node.get_node() <class_Node_method_get_node>`. We can store the reference
|
`Node.get_node()`. We can store the reference
|
||||||
in a variable.
|
in a variable.
|
||||||
|
|
||||||
gdscript GDScript
|
gdscript GDScript
|
||||||
@ -393,7 +393,7 @@ Signals have many uses. With them, you can react to a node entering or exiting
|
|||||||
the game world, to a collision, to a character entering or leaving an area, to
|
the game world, to a collision, to a character entering or leaving an area, to
|
||||||
an element of the interface changing size, and much more.
|
an element of the interface changing size, and much more.
|
||||||
|
|
||||||
For example, an `Area2D <class_Area2D>` representing a coin emits a
|
For example, an `Area2D` representing a coin emits a
|
||||||
``body_entered`` signal whenever the player's physics body enters its collision
|
``body_entered`` signal whenever the player's physics body enters its collision
|
||||||
shape, allowing you to know when the player collected it.
|
shape, allowing you to know when the player collected it.
|
||||||
|
|
||||||
|
@ -46,33 +46,33 @@ Nodes
|
|||||||
-----
|
-----
|
||||||
|
|
||||||
The demo uses four different nodes:
|
The demo uses four different nodes:
|
||||||
* `CanvasModulate <class_CanvasModulate>`
|
* `CanvasModulate`
|
||||||
* `Sprite <class_Sprite>`
|
* `Sprite`
|
||||||
* `Light2D <class_Light2D>`
|
* `Light2D`
|
||||||
* `LightOccluder2D <class_LightOccluder2D>`
|
* `LightOccluder2D`
|
||||||
|
|
||||||
`CanvasModulate<class_CanvasModulate>` is used to darken the scene.
|
`CanvasModulate<class_CanvasModulate>` is used to darken the scene.
|
||||||
|
|
||||||
`Sprites <class_Sprite>` are used to display the textures for the light blobs, the
|
`Sprites` are used to display the textures for the light blobs, the
|
||||||
background, and for the shadow casters.
|
background, and for the shadow casters.
|
||||||
|
|
||||||
`Light2Ds <class_Light2D>` are used to light the scene. The way a light typically works
|
`Light2Ds` are used to light the scene. The way a light typically works
|
||||||
is by adding a selected texture over the rest of the scene to simulate lighting. But it can be
|
is by adding a selected texture over the rest of the scene to simulate lighting. But it can be
|
||||||
used in other ways, for example masking out parts of the scene.
|
used in other ways, for example masking out parts of the scene.
|
||||||
|
|
||||||
`LightOccluder2Ds <class_LightOccluder2D>` are used to tell the shader which parts of
|
`LightOccluder2Ds` are used to tell the shader which parts of
|
||||||
the scene cast shadows. The shadows appear only on areas covered by the `Light2D <class_Light2D>` and
|
the scene cast shadows. The shadows appear only on areas covered by the `Light2D` and
|
||||||
their direction is based on the center of the `Light <class_Light2D>`.
|
their direction is based on the center of the `Light`.
|
||||||
|
|
||||||
Lights
|
Lights
|
||||||
------
|
------
|
||||||
|
|
||||||
`Lights <class_Light2D>` cover the entire extent of their respective Texture. They use additive
|
`Lights` cover the entire extent of their respective Texture. They use additive
|
||||||
blending to add the color of their texture to the scene.
|
blending to add the color of their texture to the scene.
|
||||||
|
|
||||||
.. image:: img/light_shadow_light.png
|
.. image:: img/light_shadow_light.png
|
||||||
|
|
||||||
`Lights <class_Light2D>` have four ``Modes``: ``Add``, ``Sub``, ``Mix``, and ``Mask``.
|
`Lights` have four ``Modes``: ``Add``, ``Sub``, ``Mix``, and ``Mask``.
|
||||||
|
|
||||||
``Add`` adds the color of the light texture to the scene. It brightens the area under the light.
|
``Add`` adds the color of the light texture to the scene. It brightens the area under the light.
|
||||||
|
|
||||||
@ -84,24 +84,24 @@ halfway between the color of the light and the color underneath.
|
|||||||
``Mask`` is used to mask out areas that are covered by the light. Masked out areas are hidden or revealed based on
|
``Mask`` is used to mask out areas that are covered by the light. Masked out areas are hidden or revealed based on
|
||||||
the color of the light.
|
the color of the light.
|
||||||
|
|
||||||
For the demo the lights have two components, the `Light <class_Light2D>` itself (which
|
For the demo the lights have two components, the `Light` itself (which
|
||||||
is the effect of the light), and a `Sprite <class_Sprite>` blob which is an image showing the
|
is the effect of the light), and a `Sprite` blob which is an image showing the
|
||||||
location of the light source. A child `Sprite <class_Sprite>` is not necessary to make a
|
location of the light source. A child `Sprite` is not necessary to make a
|
||||||
`Light <class_Light2D>` work.
|
`Light` work.
|
||||||
|
|
||||||
.. image:: img/light_shadow_light_blob.png
|
.. image:: img/light_shadow_light_blob.png
|
||||||
|
|
||||||
Shadows
|
Shadows
|
||||||
-------
|
-------
|
||||||
|
|
||||||
Shadows are made by intersecting a `Light <class_Light2D>` with a `LightOccluder2D <class_LightOccluder2D>`.
|
Shadows are made by intersecting a `Light`.
|
||||||
|
|
||||||
By default shadows are turned off. To turn them on click on the `Light <class_Light2D>`
|
By default shadows are turned off. To turn them on click on the `Light`
|
||||||
and under the Shadows section check ``Enabled``.
|
and under the Shadows section check ``Enabled``.
|
||||||
|
|
||||||
In the demo we are using a `Sprite <class_Sprite>` with a Texture on it to make the "Shadow Casters",
|
In the demo we are using a `Sprite` with a Texture on it to make the "Shadow Casters",
|
||||||
but in reality all you need is a couple of `LightOccluder2Ds <class_LightOccluder2D>`. By itself
|
but in reality all you need is a couple of `LightOccluder2Ds`. By itself
|
||||||
the `LightOccluder2D <class_LightOccluder2D>` looks like a dark spot and in this demo the `Sprite <class_Sprite>` is
|
the `LightOccluder2D` is
|
||||||
just a black square.
|
just a black square.
|
||||||
|
|
||||||
Step by step
|
Step by step
|
||||||
@ -110,23 +110,23 @@ Step by step
|
|||||||
Now that we have covered the basics of the nodes being used, we can now walk step by step through
|
Now that we have covered the basics of the nodes being used, we can now walk step by step through
|
||||||
the process of making a scene like the one found in the demo.
|
the process of making a scene like the one found in the demo.
|
||||||
|
|
||||||
First add a `Sprite <class_Sprite>` and set its texture to the `background image <https://raw.githubusercontent.com/godotengine/godot-demo-projects/master/2d/lights_and_shadows/background.png>`_. For your game this can be any
|
First add a `Sprite`_. For your game this can be any
|
||||||
background you choose. For this style of shadow it is most likely to be a floor texture.
|
background you choose. For this style of shadow it is most likely to be a floor texture.
|
||||||
|
|
||||||
.. image:: img/light_shadow_background.png
|
.. image:: img/light_shadow_background.png
|
||||||
|
|
||||||
Next create three `Light2D's <class_Light2D>` and set their textures to the `light image <https://raw.githubusercontent.com/godotengine/godot-demo-projects/master/2d/lights_and_shadows/light.png>`_. You can alter their
|
Next create three `Light2D's`_. You can alter their
|
||||||
color in the top section. By default shadows are turned off and the ``mode`` is set to ``add``. This
|
color in the top section. By default shadows are turned off and the ``mode`` is set to ``add``. This
|
||||||
means that each light adds its own color to whatever is underneath.
|
means that each light adds its own color to whatever is underneath.
|
||||||
|
|
||||||
.. image:: img/light_shadow_all_lights_no_blob.png
|
.. image:: img/light_shadow_all_lights_no_blob.png
|
||||||
|
|
||||||
Next add a child `Sprite <class_Sprite>` to each of the `Light <class_Light2D>` nodes, and set
|
Next add a child `Sprite` nodes, and set
|
||||||
the `Sprite's <class_Sprite>` texture to the `blob image <https://raw.githubusercontent.com/godotengine/godot-demo-projects/master/2d/lights_and_shadows/spot.png>`_. Each of these
|
the `Sprite's`_. Each of these
|
||||||
should stay centered on the `Light <class_Light2D>` node. The blob is the image of the light
|
should stay centered on the `Light` node. The blob is the image of the light
|
||||||
itself while the `Light <class_Light2D>` shows the effect that the light has on the scene. The
|
itself while the `Light` shows the effect that the light has on the scene. The
|
||||||
`LightOccluder2D's <class_LightOccluder2D>` will treat the position of the light as the center of the `Light <class_Light2D>`
|
`LightOccluder2D's`
|
||||||
node, which is why we want the blob to be centered on its parent `Light <class_Light2D>`.
|
node, which is why we want the blob to be centered on its parent `Light`.
|
||||||
|
|
||||||
.. image:: img/light_shadow_all_lights.png
|
.. image:: img/light_shadow_all_lights.png
|
||||||
|
|
||||||
@ -134,30 +134,30 @@ node, which is why we want the blob to be centered on its parent `Light <class_L
|
|||||||
for information on creating animations.
|
for information on creating animations.
|
||||||
|
|
||||||
Right now the scene should look too bright. This is because all three lights are adding color to the scene.
|
Right now the scene should look too bright. This is because all three lights are adding color to the scene.
|
||||||
This is why the demo uses a `CanvasModulate <class_CanvasModulate>` in the scene. The
|
This is why the demo uses a `CanvasModulate` in the scene. The
|
||||||
`CanvasModulate <class_CanvasModulate>` multiples the entire viewport by a specific color.
|
`CanvasModulate` multiples the entire viewport by a specific color.
|
||||||
|
|
||||||
Add a `CanvasModulate <class_CanvasModulate>` to the scene and set its color to ``rgb(70, 70, 70)``.
|
Add a `CanvasModulate` to the scene and set its color to ``rgb(70, 70, 70)``.
|
||||||
This will make the scene sufficiently dark to see the effects of the lights distinctly.
|
This will make the scene sufficiently dark to see the effects of the lights distinctly.
|
||||||
|
|
||||||
.. image:: img/light_shadow_ambient.png
|
.. image:: img/light_shadow_ambient.png
|
||||||
|
|
||||||
Now we add the shadow casters.
|
Now we add the shadow casters.
|
||||||
|
|
||||||
The demo uses a `Node <class_Node2D>` named "casters" to organize the shadow casters. Add a
|
The demo uses a `Node` named "casters" to organize the shadow casters. Add a
|
||||||
`Node2D <class_Node2D>` to the scene. It will be used to group all the shadow casters together.
|
`Node2D` to the scene. It will be used to group all the shadow casters together.
|
||||||
This way we can show and hide them all at the same time.
|
This way we can show and hide them all at the same time.
|
||||||
|
|
||||||
Each shadow caster is made of a `Sprite <class_Sprite>`, with a `LightOccluder2D <class_LightOccluder2D>`
|
Each shadow caster is made of a `Sprite`
|
||||||
child. For the demo the `Sprite <class_Sprite>` has a texture
|
child. For the demo the `Sprite` has a texture
|
||||||
set to the `caster image <https://raw.githubusercontent.com/godotengine/godot-demo-projects/master/2d/lights_and_shadows/caster.png>`_ and nothing else. The child `LightOccluder2D <class_LightOccluder2D>` is where all the magic happens. In a
|
set to the `caster image <https://raw.githubusercontent.com/godotengine/godot-demo-projects/master/2d/lights_and_shadows/caster.png>`_ and nothing else. The child `LightOccluder2D` is where all the magic happens. In a
|
||||||
game the `Sprite <class_Sprite>` could be more than a black box; it could be an image of whatever object is casting
|
game the `Sprite` could be more than a black box; it could be an image of whatever object is casting
|
||||||
the shadow: a wall, a magical chest, or anything else.
|
the shadow: a wall, a magical chest, or anything else.
|
||||||
|
|
||||||
.. image:: img/light_shadow_sprites.png
|
.. image:: img/light_shadow_sprites.png
|
||||||
|
|
||||||
`LightOccluder2Ds <class_LightOccluder2D>` tell the game what shape the occluder has. They hold
|
`LightOccluder2Ds` tell the game what shape the occluder has. They hold
|
||||||
an `OccluderPolygon2D <class_OccluderPolygon2D>`, which is a container
|
an `OccluderPolygon2D`, which is a container
|
||||||
for a polygon and some other information. For this demo, since our wall is a square, we
|
for a polygon and some other information. For this demo, since our wall is a square, we
|
||||||
set ``Polygon`` to a square. The other default settings are fine.
|
set ``Polygon`` to a square. The other default settings are fine.
|
||||||
|
|
||||||
@ -169,8 +169,8 @@ will cast a shadow no matter which side the light is on. The other two settings
|
|||||||
``Counter-Clockwise`` refer to the winding order of the vertices of the polygon. The winding order
|
``Counter-Clockwise`` refer to the winding order of the vertices of the polygon. The winding order
|
||||||
is used to determine which side of the line is inside the polygon. Only outward facing lines cast shadows.
|
is used to determine which side of the line is inside the polygon. Only outward facing lines cast shadows.
|
||||||
|
|
||||||
To illustrate the difference, here is an image of a `LightOccluder2D <class_LightOccluder2D>` with ``Closed``
|
To illustrate the difference, here is an image of a `LightOccluder2D` with ``Closed``
|
||||||
set to ``off`` in the corresponding `OccluderPolygon2D <class_OccluderPolygon2D>`, so that the
|
set to ``off`` in the corresponding `OccluderPolygon2D`, so that the
|
||||||
lines of the polygon can be seen:
|
lines of the polygon can be seen:
|
||||||
|
|
||||||
.. image:: img/light_shadow_cull_disabled.png
|
.. image:: img/light_shadow_cull_disabled.png
|
||||||
@ -187,8 +187,8 @@ lines of the polygon can be seen:
|
|||||||
If ``Closed`` was set to ``on`` there would be an additional vertical line on the
|
If ``Closed`` was set to ``on`` there would be an additional vertical line on the
|
||||||
left which would cast a shadow as well.
|
left which would cast a shadow as well.
|
||||||
|
|
||||||
When you have added the `LightOccluder2Ds <class_LightOccluder2D>` the shadows still won't
|
When you have added the `LightOccluder2Ds` the shadows still won't
|
||||||
appear. You need to go back into the `Light2Ds <class_Light2D>` and under the Shadow
|
appear. You need to go back into the `Light2Ds` and under the Shadow
|
||||||
section set ``Enable`` to ``on``. This turns on shadows with hard edges like in the image below.
|
section set ``Enable`` to ``on``. This turns on shadows with hard edges like in the image below.
|
||||||
|
|
||||||
.. image:: img/light_shadow_filter0_pcf0.png
|
.. image:: img/light_shadow_filter0_pcf0.png
|
||||||
@ -219,7 +219,7 @@ forming between the samples.
|
|||||||
|
|
||||||
.. note:: ``filter smooth`` is set to ``30``.
|
.. note:: ``filter smooth`` is set to ``30``.
|
||||||
|
|
||||||
The different `Light <class_Light2D>` nodes in the demo use different values for filter smooth.
|
The different `Light` nodes in the demo use different values for filter smooth.
|
||||||
Play around with it and see what you like.
|
Play around with it and see what you like.
|
||||||
|
|
||||||
.. image:: img/light_shadow_filter0.png
|
.. image:: img/light_shadow_filter0.png
|
||||||
|
@ -10,7 +10,7 @@ Every beginner has been there: "How do I move my character?" Depending on the
|
|||||||
style of game you're making, you may have special requirements, but in general
|
style of game you're making, you may have special requirements, but in general
|
||||||
the movement in most 2D games is based on a small number of designs.
|
the movement in most 2D games is based on a small number of designs.
|
||||||
|
|
||||||
We'll use `KinematicBody2D <class_KinematicBody2D>` for these examples,
|
We'll use `KinematicBody2D` for these examples,
|
||||||
but the principles will apply to other node types (Area2D, RigidBody2D) as well.
|
but the principles will apply to other node types (Area2D, RigidBody2D) as well.
|
||||||
|
|
||||||
.. _doc_2d_movement_setup:
|
.. _doc_2d_movement_setup:
|
||||||
@ -159,7 +159,7 @@ gdscript GDScript
|
|||||||
velocity = move_and_slide(velocity)
|
velocity = move_and_slide(velocity)
|
||||||
```
|
```
|
||||||
|
|
||||||
Here we're using the `Node2D <class_Node2D>` ``look_at()`` method to
|
Here we're using the `Node2D` ``look_at()`` method to
|
||||||
point the player towards a given position. Without this function, you
|
point the player towards a given position. Without this function, you
|
||||||
could get the same effect by setting the angle like this:
|
could get the same effect by setting the angle like this:
|
||||||
|
|
||||||
|
@ -11,10 +11,10 @@ characters with the AnimatedSprite class and the AnimationPlayer. Typically, whe
|
|||||||
will come in one of two ways: as individual images or as a single sprite sheet
|
will come in one of two ways: as individual images or as a single sprite sheet
|
||||||
containing all the animation's frames. Both can be animated in Godot with the AnimatedSprite class.
|
containing all the animation's frames. Both can be animated in Godot with the AnimatedSprite class.
|
||||||
|
|
||||||
First, we'll use `AnimatedSprite <class_AnimatedSprite>` to
|
First, we'll use `AnimatedSprite` to
|
||||||
animate a collection of individual images. Then we will animate a sprite sheet using this class. Finally, we will learn another way to animate a sprite sheet
|
animate a collection of individual images. Then we will animate a sprite sheet using this class. Finally, we will learn another way to animate a sprite sheet
|
||||||
with `AnimationPlayer <class_AnimationPlayer>` and the *Animation*
|
with `AnimationPlayer` and the *Animation*
|
||||||
property of `Sprite <class_Sprite>`.
|
property of `Sprite`.
|
||||||
|
|
||||||
.. note:: Art for the following examples by https://opengameart.org/users/ansimuz and by
|
.. note:: Art for the following examples by https://opengameart.org/users/ansimuz and by
|
||||||
https://opengameart.org/users/tgfcoder
|
https://opengameart.org/users/tgfcoder
|
||||||
@ -36,8 +36,8 @@ with the following nodes:
|
|||||||
|
|
||||||
.. image:: img/2d_animation_tree1.png
|
.. image:: img/2d_animation_tree1.png
|
||||||
|
|
||||||
.. note:: The root node could also be `Area2D <class_Area2D>` or
|
.. note:: The root node could also be `Area2D` or
|
||||||
`RigidBody2D <class_RigidBody2D>`. The animation will still be
|
`RigidBody2D`. The animation will still be
|
||||||
made in the same way. Once the animation is completed, you can
|
made in the same way. Once the animation is completed, you can
|
||||||
assign a shape to the CollisionShape2D. See
|
assign a shape to the CollisionShape2D. See
|
||||||
`Physics Introduction <doc_physics_introduction>` for more
|
`Physics Introduction <doc_physics_introduction>` for more
|
||||||
@ -128,8 +128,8 @@ Sprite sheet with AnimationPlayer
|
|||||||
---------------------------------
|
---------------------------------
|
||||||
|
|
||||||
Another way that you can animate when using a sprite sheet is to use a standard
|
Another way that you can animate when using a sprite sheet is to use a standard
|
||||||
`Sprite <class_Sprite>` node to display the texture, and then animating the
|
`Sprite` node to display the texture, and then animating the
|
||||||
change from texture to texture with `AnimationPlayer <class_AnimationPlayer>`.
|
change from texture to texture with `AnimationPlayer`.
|
||||||
|
|
||||||
Consider this sprite sheet, which contains 6 frames of animation:
|
Consider this sprite sheet, which contains 6 frames of animation:
|
||||||
|
|
||||||
@ -143,8 +143,8 @@ setting up your scene tree:
|
|||||||
|
|
||||||
.. image:: img/2d_animation_tree2.png
|
.. image:: img/2d_animation_tree2.png
|
||||||
|
|
||||||
.. note:: The root node could also be `Area2D <class_Area2D>` or
|
.. note:: The root node could also be `Area2D` or
|
||||||
`RigidBody2D <class_RigidBody2D>`. The animation will still be
|
`RigidBody2D`. The animation will still be
|
||||||
made in the same way. Once the animation is completed, you can
|
made in the same way. Once the animation is completed, you can
|
||||||
assign a shape to the CollisionShape2D. See
|
assign a shape to the CollisionShape2D. See
|
||||||
`Physics Introduction <doc_physics_introduction>` for more
|
`Physics Introduction <doc_physics_introduction>` for more
|
||||||
@ -208,7 +208,7 @@ gdscript GDScript
|
|||||||
(for example, a platformer may update the sprite's ``h_flip``/``v_flip``
|
(for example, a platformer may update the sprite's ``h_flip``/``v_flip``
|
||||||
properties when a character turns while starting a 'turning' animation),
|
properties when a character turns while starting a 'turning' animation),
|
||||||
it's important to keep in mind that ``play()`` isn't applied instantly.
|
it's important to keep in mind that ``play()`` isn't applied instantly.
|
||||||
Instead, it's applied the next time the `AnimationPlayer <class_AnimationPlayer>` is processed.
|
Instead, it's applied the next time the `AnimationPlayer` is processed.
|
||||||
This may end up being on the next frame, causing a 'glitch' frame,
|
This may end up being on the next frame, causing a 'glitch' frame,
|
||||||
where the property change was applied but the animation was not.
|
where the property change was applied but the animation was not.
|
||||||
If this turns out to be a problem, after calling ``play()``, you can call ``advance(0)``
|
If this turns out to be a problem, after calling ``play()``, you can call ``advance(0)``
|
||||||
|
@ -17,7 +17,7 @@ As mentioned in the previous tutorial, `doc_canvas_layers`, every
|
|||||||
CanvasItem node (remember that Node2D and Control based nodes use
|
CanvasItem node (remember that Node2D and Control based nodes use
|
||||||
CanvasItem as their common root) will reside in a *Canvas Layer*. Every
|
CanvasItem as their common root) will reside in a *Canvas Layer*. Every
|
||||||
canvas layer has a transform (translation, rotation, scale, etc.) that
|
canvas layer has a transform (translation, rotation, scale, etc.) that
|
||||||
can be accessed as a `Transform2D <class_Transform2D>`.
|
can be accessed as a `Transform2D`.
|
||||||
|
|
||||||
Also covered in the previous tutorial, nodes are drawn by default in Layer 0,
|
Also covered in the previous tutorial, nodes are drawn by default in Layer 0,
|
||||||
in the built-in canvas. To put nodes in a different layer, a `CanvasLayer
|
in the built-in canvas. To put nodes in a different layer, a `CanvasLayer
|
||||||
@ -27,7 +27,7 @@ Global canvas transform
|
|||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
Viewports also have a Global Canvas transform (also a
|
Viewports also have a Global Canvas transform (also a
|
||||||
`Transform2D <class_Transform2D>`). This is the master transform and
|
`Transform2D`). This is the master transform and
|
||||||
affects all individual *Canvas Layer* transforms. Generally, this
|
affects all individual *Canvas Layer* transforms. Generally, this
|
||||||
transform is not of much use, but is used in the CanvasItem Editor
|
transform is not of much use, but is used in the CanvasItem Editor
|
||||||
in Godot's editor.
|
in Godot's editor.
|
||||||
@ -40,10 +40,10 @@ resizing or stretching the screen. This transform is used internally (as
|
|||||||
described in `doc_multiple_resolutions`), but can also be manually set
|
described in `doc_multiple_resolutions`), but can also be manually set
|
||||||
on each viewport.
|
on each viewport.
|
||||||
|
|
||||||
Input events received in the `MainLoop._input_event() <class_MainLoop_method__input_event>`
|
Input events received in the `MainLoop._input_event()`
|
||||||
callback are multiplied by this transform but lack the ones above. To
|
callback are multiplied by this transform but lack the ones above. To
|
||||||
convert InputEvent coordinates to local CanvasItem coordinates, the
|
convert InputEvent coordinates to local CanvasItem coordinates, the
|
||||||
`CanvasItem.make_input_local() <class_CanvasItem_method_make_input_local>`
|
`CanvasItem.make_input_local()`
|
||||||
function was added for convenience.
|
function was added for convenience.
|
||||||
|
|
||||||
Transform order
|
Transform order
|
||||||
@ -62,11 +62,11 @@ Obtaining each transform can be achieved with the following functions:
|
|||||||
+----------------------------------+---------------------------------------------------------------------------------------------+
|
+----------------------------------+---------------------------------------------------------------------------------------------+
|
||||||
| Type | Transform |
|
| Type | Transform |
|
||||||
+==================================+=============================================================================================+
|
+==================================+=============================================================================================+
|
||||||
| CanvasItem | `CanvasItem.get_global_transform() <class_CanvasItem_method_get_global_transform>` |
|
| CanvasItem | `CanvasItem.get_global_transform()` |
|
||||||
+----------------------------------+---------------------------------------------------------------------------------------------+
|
+----------------------------------+---------------------------------------------------------------------------------------------+
|
||||||
| CanvasLayer | `CanvasItem.get_canvas_transform() <class_CanvasItem_method_get_canvas_transform>` |
|
| CanvasLayer | `CanvasItem.get_canvas_transform()` |
|
||||||
+----------------------------------+---------------------------------------------------------------------------------------------+
|
+----------------------------------+---------------------------------------------------------------------------------------------+
|
||||||
| CanvasLayer+GlobalCanvas+Stretch | `CanvasItem.get_viewport_transform() <class_CanvasItem_method_get_viewport_transform>` |
|
| CanvasLayer+GlobalCanvas+Stretch | `CanvasItem.get_viewport_transform()` |
|
||||||
+----------------------------------+---------------------------------------------------------------------------------------------+
|
+----------------------------------+---------------------------------------------------------------------------------------------+
|
||||||
|
|
||||||
Finally, then, to convert a CanvasItem local coordinates to screen
|
Finally, then, to convert a CanvasItem local coordinates to screen
|
||||||
|
@ -6,20 +6,20 @@ Canvas layers
|
|||||||
Viewport and Canvas items
|
Viewport and Canvas items
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
`CanvasItem <class_CanvasItem>` is the base for all 2D nodes, be it regular
|
`CanvasItem` is the base for all 2D nodes, be it regular
|
||||||
2D nodes, such as `Node2D <class_Node2D>`, or `Control <class_Control>`.
|
2D nodes, such as `Node2D`.
|
||||||
Both inherit from `CanvasItem <class_CanvasItem>`.
|
Both inherit from `CanvasItem`.
|
||||||
You can arrange canvas items in trees. Each item will inherit its parent's
|
You can arrange canvas items in trees. Each item will inherit its parent's
|
||||||
transform: when the parent moves, its children move too.
|
transform: when the parent moves, its children move too.
|
||||||
|
|
||||||
CanvasItem nodes, and nodes inheriting from them, are direct or indirect children of a
|
CanvasItem nodes, and nodes inheriting from them, are direct or indirect children of a
|
||||||
`Viewport <class_Viewport>`, that display them.
|
`Viewport`, that display them.
|
||||||
|
|
||||||
A Viewport has the property
|
A Viewport has the property
|
||||||
`Viewport.canvas_transform <class_Viewport_property_canvas_transform>`,
|
`Viewport.canvas_transform`,
|
||||||
allows to apply a custom `Transform2D <class_Transform2D>`
|
allows to apply a custom `Transform2D`
|
||||||
transform to the CanvasItem hierarchy it contains. Nodes such as
|
transform to the CanvasItem hierarchy it contains. Nodes such as
|
||||||
`Camera2D <class_Camera2D>` work by changing that transform.
|
`Camera2D` work by changing that transform.
|
||||||
|
|
||||||
To achieve effects like scrolling, manipulating the canvas transform property is
|
To achieve effects like scrolling, manipulating the canvas transform property is
|
||||||
more efficient than moving the root canvas item and the entire scene with it.
|
more efficient than moving the root canvas item and the entire scene with it.
|
||||||
@ -37,7 +37,7 @@ How can these problems be solved in a single scene tree?
|
|||||||
CanvasLayers
|
CanvasLayers
|
||||||
------------
|
------------
|
||||||
|
|
||||||
The answer is `CanvasLayer <class_CanvasLayer>`,
|
The answer is `CanvasLayer`,
|
||||||
which is a node that adds a separate 2D rendering layer for all its
|
which is a node that adds a separate 2D rendering layer for all its
|
||||||
children and grand-children. Viewport children will draw by default at
|
children and grand-children. Viewport children will draw by default at
|
||||||
layer "0", while a CanvasLayer will draw at any numeric layer. Layers
|
layer "0", while a CanvasLayer will draw at any numeric layer. Layers
|
||||||
@ -61,4 +61,4 @@ their layer number, so they can be instantiated when needed.
|
|||||||
The standard way to ensuring that a node is correctly drawn 'in front' or 'behind' others is to manipulate the
|
The standard way to ensuring that a node is correctly drawn 'in front' or 'behind' others is to manipulate the
|
||||||
order of the nodes in the scene panel. Perhaps counterintuitively, the topmost nodes in the scene panel are drawn
|
order of the nodes in the scene panel. Perhaps counterintuitively, the topmost nodes in the scene panel are drawn
|
||||||
on *behind* lower ones in the viewport. 2d nodes also have a property for controlling their drawing order
|
on *behind* lower ones in the viewport. 2d nodes also have a property for controlling their drawing order
|
||||||
(see `Node2D.z_index <class_Node2D_property_z_index>`).
|
(see `Node2D.z_index`).
|
||||||
|
@ -10,7 +10,7 @@ Godot has nodes to draw sprites, polygons, particles, and all sorts of
|
|||||||
stuff. For most cases, this is enough; but not always. Before crying in fear,
|
stuff. For most cases, this is enough; but not always. Before crying in fear,
|
||||||
angst, and rage because a node to draw that specific *something* does not exist...
|
angst, and rage because a node to draw that specific *something* does not exist...
|
||||||
it would be good to know that it is possible to easily make any 2D node (be it
|
it would be good to know that it is possible to easily make any 2D node (be it
|
||||||
`Control <class_Control>` or `Node2D <class_Node2D>`
|
`Control`
|
||||||
based) draw custom commands. It is *really* easy to do it, too.
|
based) draw custom commands. It is *really* easy to do it, too.
|
||||||
|
|
||||||
Custom drawing in a 2D node is *really* useful. Here are some use cases:
|
Custom drawing in a 2D node is *really* useful. Here are some use cases:
|
||||||
@ -30,9 +30,9 @@ Custom drawing in a 2D node is *really* useful. Here are some use cases:
|
|||||||
Drawing
|
Drawing
|
||||||
-------
|
-------
|
||||||
|
|
||||||
Add a script to any `CanvasItem <class_CanvasItem>`
|
Add a script to any `CanvasItem`
|
||||||
derived node, like `Control <class_Control>` or
|
derived node, like `Control` or
|
||||||
`Node2D <class_Node2D>`. Then override the ``_draw()`` function.
|
`Node2D`. Then override the ``_draw()`` function.
|
||||||
|
|
||||||
gdscript GDScript
|
gdscript GDScript
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ gdscript GDScript
|
|||||||
pass
|
pass
|
||||||
```
|
```
|
||||||
|
|
||||||
Draw commands are described in the `CanvasItem <class_CanvasItem>`
|
Draw commands are described in the `CanvasItem`
|
||||||
class reference. There are plenty of them.
|
class reference. There are plenty of them.
|
||||||
|
|
||||||
Updating
|
Updating
|
||||||
@ -54,7 +54,7 @@ The ``_draw()`` function is only called once, and then the draw commands
|
|||||||
are cached and remembered, so further calls are unnecessary.
|
are cached and remembered, so further calls are unnecessary.
|
||||||
|
|
||||||
If re-drawing is required because a state or something else changed,
|
If re-drawing is required because a state or something else changed,
|
||||||
call `CanvasItem.update() <class_CanvasItem_method_update>`
|
call `CanvasItem.update()`
|
||||||
in that same node and a new ``_draw()`` call will happen.
|
in that same node and a new ``_draw()`` call will happen.
|
||||||
|
|
||||||
Here is a little more complex example, a texture variable that will be
|
Here is a little more complex example, a texture variable that will be
|
||||||
|
@ -7,9 +7,9 @@ Introduction
|
|||||||
------------
|
------------
|
||||||
|
|
||||||
A tilemap is a grid of tiles used to create a game's layout. There are several
|
A tilemap is a grid of tiles used to create a game's layout. There are several
|
||||||
benefits to using `TileMap <class_TileMap>` nodes to design your levels.
|
benefits to using `TileMap` nodes to design your levels.
|
||||||
First, they make it possible to draw the layout by "painting" the tiles onto a
|
First, they make it possible to draw the layout by "painting" the tiles onto a
|
||||||
grid, which is much faster than placing individual `Sprite <class_Sprite>`
|
grid, which is much faster than placing individual `Sprite`
|
||||||
nodes one by one. Second, they allow for much larger levels because they are
|
nodes one by one. Second, they allow for much larger levels because they are
|
||||||
optimized for drawing large numbers of tiles. Finally, you can add collision,
|
optimized for drawing large numbers of tiles. Finally, you can add collision,
|
||||||
occlusion, and navigation shapes to tiles, adding additional functionality to
|
occlusion, and navigation shapes to tiles, adding additional functionality to
|
||||||
@ -36,7 +36,7 @@ off ``Filter`` and click "Reimport". See `doc_import_images` for details.
|
|||||||
TileMap node
|
TileMap node
|
||||||
------------
|
------------
|
||||||
|
|
||||||
Add a new `TileMap <class_TileMap>` node to the scene. By default, a TileMap
|
Add a new `TileMap` node to the scene. By default, a TileMap
|
||||||
uses a square grid of tiles. You can also use a perspective-based "Isometric" mode
|
uses a square grid of tiles. You can also use a perspective-based "Isometric" mode
|
||||||
or define your own custom tile shape.
|
or define your own custom tile shape.
|
||||||
|
|
||||||
@ -71,8 +71,8 @@ Creating a TileSet
|
|||||||
------------------
|
------------------
|
||||||
|
|
||||||
Once you've configured your tilemap, it's time to add a
|
Once you've configured your tilemap, it's time to add a
|
||||||
`TileSet <class_TileSet>`. A TileSet is a
|
`TileSet`. A TileSet is a
|
||||||
`Resource <class_Resource>` that contains the data about your
|
`Resource` that contains the data about your
|
||||||
tiles - their textures, collision shapes, and other properties. When the game
|
tiles - their textures, collision shapes, and other properties. When the game
|
||||||
runs, the TileMap combines the individual tiles into a single object.
|
runs, the TileMap combines the individual tiles into a single object.
|
||||||
|
|
||||||
@ -340,7 +340,7 @@ to take effect.
|
|||||||
Tips and tricks
|
Tips and tricks
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
- If you're using a `Camera2D <class_Camera2D>` to scroll your level, you
|
- If you're using a `Camera2D` to scroll your level, you
|
||||||
may notice lines appearing between your tiles. To fix this, open Project
|
may notice lines appearing between your tiles. To fix this, open Project
|
||||||
Settings and enable **Use Gpu Pixel Snap** in the **Rendering > 2d > Snapping** section.
|
Settings and enable **Use Gpu Pixel Snap** in the **Rendering > 2d > Snapping** section.
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ In Godot, transparent materials are drawn after opaque materials. Transparent
|
|||||||
objects are sorted back to front before being drawn based on the Spatial's
|
objects are sorted back to front before being drawn based on the Spatial's
|
||||||
position, not the vertex position in world space. Due to this, overlapping
|
position, not the vertex position in world space. Due to this, overlapping
|
||||||
objects may often be sorted out of order. To fix improperly sorted objects, tweak
|
objects may often be sorted out of order. To fix improperly sorted objects, tweak
|
||||||
the material's `Render Priority <class_Material_property_render_priority>`
|
the material's `Render Priority`
|
||||||
property. This will force specific materials to appear in front or behind of
|
property. This will force specific materials to appear in front or behind of
|
||||||
other transparent materials. Even then, this may not always be sufficient.
|
other transparent materials. Even then, this may not always be sufficient.
|
||||||
|
|
||||||
|
@ -29,13 +29,13 @@ Introduction to CSG nodes
|
|||||||
Like other features of Godot, CSG is supported in the form of nodes. These are
|
Like other features of Godot, CSG is supported in the form of nodes. These are
|
||||||
the CSG nodes:
|
the CSG nodes:
|
||||||
|
|
||||||
- `CSGBox <class_CSGBox>`
|
- `CSGBox`
|
||||||
- `CSGCylinder <class_CSGCylinder>` (also supports cone)
|
- `CSGCylinder` (also supports cone)
|
||||||
- `CSGSphere <class_CSGSphere>`
|
- `CSGSphere`
|
||||||
- `CSGTorus <class_CSGTorus>`
|
- `CSGTorus`
|
||||||
- `CSGPolygon <class_CSGPolygon>`
|
- `CSGPolygon`
|
||||||
- `CSGMesh <class_CSGMesh>`
|
- `CSGMesh`
|
||||||
- `CSGCombiner <class_CSGcombiner>`
|
- `CSGCombiner`
|
||||||
|
|
||||||
.. image:: img/csg_nodes.png
|
.. image:: img/csg_nodes.png
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ Every CSG node supports 3 kinds of boolean operations:
|
|||||||
CSGPolygon
|
CSGPolygon
|
||||||
~~~~~~~~~~
|
~~~~~~~~~~
|
||||||
|
|
||||||
The `CSGPolygon <class_CSGPolygon>` node extrude along a Polygon drawn in
|
The `CSGPolygon` node extrude along a Polygon drawn in
|
||||||
2D (in X, Y coordinates) in the following ways:
|
2D (in X, Y coordinates) in the following ways:
|
||||||
|
|
||||||
- **Depth:** Extruded back a given amount.
|
- **Depth:** Extruded back a given amount.
|
||||||
@ -71,7 +71,7 @@ The `CSGPolygon <class_CSGPolygon>` node extrude along a Polygon drawn in
|
|||||||
|
|
||||||
.. image:: img/csg_poly.png
|
.. image:: img/csg_poly.png
|
||||||
|
|
||||||
.. note:: The **Path** mode must be provided with a `Path <class_Path>`
|
.. note:: The **Path** mode must be provided with a `Path`
|
||||||
node to work. In the Path node, draw the path and the polygon in
|
node to work. In the Path node, draw the path and the polygon in
|
||||||
CSGPolygon will extrude along the given path.
|
CSGPolygon will extrude along the given path.
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ The `CSGPolygon <class_CSGPolygon>` node extrude along a Polygon drawn in
|
|||||||
Custom meshes
|
Custom meshes
|
||||||
~~~~~~~~~~~~~
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
Any mesh can be used for `CSGMesh <class_CSGMesh>`; the mesh can be
|
Any mesh can be used for `CSGMesh`; the mesh can be
|
||||||
modelled in other software and imported into Godot. Multiple materials are
|
modelled in other software and imported into Godot. Multiple materials are
|
||||||
supported. There are some restrictions for geometry:
|
supported. There are some restrictions for geometry:
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ supported. There are some restrictions for geometry:
|
|||||||
CSGCombiner
|
CSGCombiner
|
||||||
~~~~~~~~~~~
|
~~~~~~~~~~~
|
||||||
|
|
||||||
The `CSGCombiner <class_CSGCombiner>` node is an empty shape used for
|
The `CSGCombiner` node is an empty shape used for
|
||||||
organization. It will only combine children nodes.
|
organization. It will only combine children nodes.
|
||||||
|
|
||||||
Processing order
|
Processing order
|
||||||
|
@ -101,7 +101,7 @@ Scene linear to display-referred nonlinear
|
|||||||
|
|
||||||
After all the rendering is done, the scene linear render requires transforming
|
After all the rendering is done, the scene linear render requires transforming
|
||||||
to a suitable output such as an sRGB display. To do this, enable sRGB conversion
|
to a suitable output such as an sRGB display. To do this, enable sRGB conversion
|
||||||
in the current `Environment <class_Environment>` (more on that below).
|
in the current `Environment` (more on that below).
|
||||||
|
|
||||||
Keep in mind that the **sRGB -> Display Linear** and **Display Linear -> sRGB**
|
Keep in mind that the **sRGB -> Display Linear** and **Display Linear -> sRGB**
|
||||||
conversions must always be **both** enabled. Failing to enable one of them will
|
conversions must always be **both** enabled. Failing to enable one of them will
|
||||||
@ -111,8 +111,8 @@ indie games.
|
|||||||
Parameters of HDR
|
Parameters of HDR
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
HDR settings can be found in the `Environment <class_Environment>`
|
HDR settings can be found in the `Environment`
|
||||||
resource. Most of the time, these are found inside a
|
resource. Most of the time, these are found inside a
|
||||||
`WorldEnvironment <class_WorldEnvironment>`
|
`WorldEnvironment`
|
||||||
node or set in a Camera node. For more information, see
|
node or set in a Camera node. For more information, see
|
||||||
`doc_environment_and_post_processing`.
|
`doc_environment_and_post_processing`.
|
||||||
|
@ -19,9 +19,9 @@ to develop 3D games efficiently.
|
|||||||
Spatial node
|
Spatial node
|
||||||
~~~~~~~~~~~~
|
~~~~~~~~~~~~
|
||||||
|
|
||||||
`Node2D <class_Node2D>` is the base node for 2D.
|
`Node2D` is the base node for 2D.
|
||||||
`Control <class_Control>` is the base node for everything GUI.
|
`Control` is the base node for everything GUI.
|
||||||
Following this reasoning, the 3D engine uses the `Spatial <class_Spatial>`
|
Following this reasoning, the 3D engine uses the `Spatial`
|
||||||
node for everything 3D.
|
node for everything 3D.
|
||||||
|
|
||||||
.. image:: img/tuto_3d1.png
|
.. image:: img/tuto_3d1.png
|
||||||
@ -29,7 +29,7 @@ node for everything 3D.
|
|||||||
Spatial nodes have a local transform, which is relative to the parent
|
Spatial nodes have a local transform, which is relative to the parent
|
||||||
node (as long as the parent node is also of **or inherits from** the type
|
node (as long as the parent node is also of **or inherits from** the type
|
||||||
Spatial). This transform can be accessed as a 4×3
|
Spatial). This transform can be accessed as a 4×3
|
||||||
`Transform <class_Transform>`, or as 3 `Vector3 <class_Vector3>`
|
`Transform`
|
||||||
members representing location, Euler rotation (X, Y and Z angles) and
|
members representing location, Euler rotation (X, Y and Z angles) and
|
||||||
scale.
|
scale.
|
||||||
|
|
||||||
@ -56,16 +56,16 @@ entire scenes (just as they look in the DCC), including animation,
|
|||||||
skeletal rigs, blend shapes, etc.
|
skeletal rigs, blend shapes, etc.
|
||||||
|
|
||||||
The second pipeline is by importing simple .OBJ files as mesh resources,
|
The second pipeline is by importing simple .OBJ files as mesh resources,
|
||||||
which can be then put inside a `MeshInstance <class_MeshInstance>`
|
which can be then put inside a `MeshInstance`
|
||||||
node for display.
|
node for display.
|
||||||
|
|
||||||
Generated geometry
|
Generated geometry
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
It is possible to create custom geometry by using the
|
It is possible to create custom geometry by using the
|
||||||
`ArrayMesh <class_ArrayMesh>` resource directly. Simply create your arrays
|
`ArrayMesh` resource directly. Simply create your arrays
|
||||||
and use the `ArrayMesh.add_surface_from_arrays() <class_ArrayMesh_method_add_surface_from_arrays>`
|
and use the `ArrayMesh.add_surface_from_arrays()`
|
||||||
function. A helper class is also available, `SurfaceTool <class_SurfaceTool>`,
|
function. A helper class is also available, `SurfaceTool`,
|
||||||
which provides a more straightforward API and helpers for indexing,
|
which provides a more straightforward API and helpers for indexing,
|
||||||
generating normals, tangents, etc.
|
generating normals, tangents, etc.
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ Immediate geometry
|
|||||||
|
|
||||||
If, instead, there is a requirement to generate simple geometry that
|
If, instead, there is a requirement to generate simple geometry that
|
||||||
will be updated often, Godot provides a special node,
|
will be updated often, Godot provides a special node,
|
||||||
`ImmediateGeometry <class_ImmediateGeometry>`,
|
`ImmediateGeometry`,
|
||||||
which provides an OpenGL 1.x style immediate-mode API to create points,
|
which provides an OpenGL 1.x style immediate-mode API to create points,
|
||||||
lines, triangles, etc.
|
lines, triangles, etc.
|
||||||
|
|
||||||
@ -88,8 +88,8 @@ lines, triangles, etc.
|
|||||||
While Godot packs a powerful 2D engine, many types of games use 2D in a
|
While Godot packs a powerful 2D engine, many types of games use 2D in a
|
||||||
3D environment. By using a fixed camera (either orthogonal or
|
3D environment. By using a fixed camera (either orthogonal or
|
||||||
perspective) that does not rotate, nodes such as
|
perspective) that does not rotate, nodes such as
|
||||||
`Sprite3D <class_Sprite3D>` and
|
`Sprite3D` and
|
||||||
`AnimatedSprite3D <class_AnimatedSprite3D>`
|
`AnimatedSprite3D`
|
||||||
can be used to create 2D games that take advantage of mixing with 3D
|
can be used to create 2D games that take advantage of mixing with 3D
|
||||||
backgrounds, more realistic parallax, lighting/shadow effects, etc.
|
backgrounds, more realistic parallax, lighting/shadow effects, etc.
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ Environment
|
|||||||
~~~~~~~~~~~
|
~~~~~~~~~~~
|
||||||
|
|
||||||
Besides editing a scene, it is often common to edit the environment.
|
Besides editing a scene, it is often common to edit the environment.
|
||||||
Godot provides a `WorldEnvironment <class_WorldEnvironment>`
|
Godot provides a `WorldEnvironment`
|
||||||
node that allows changing the background color, mode (as in, put a
|
node that allows changing the background color, mode (as in, put a
|
||||||
skybox), and applying several types of built-in post-processing effects.
|
skybox), and applying several types of built-in post-processing effects.
|
||||||
Environments can also be overridden in the Camera.
|
Environments can also be overridden in the Camera.
|
||||||
@ -193,7 +193,7 @@ Cameras
|
|||||||
-------
|
-------
|
||||||
|
|
||||||
No matter how many objects are placed in the 3D space, nothing will be
|
No matter how many objects are placed in the 3D space, nothing will be
|
||||||
displayed unless a `Camera <class_Camera>` is
|
displayed unless a `Camera` is
|
||||||
also added to the scene. Cameras can work in either orthogonal or
|
also added to the scene. Cameras can work in either orthogonal or
|
||||||
perspective projections:
|
perspective projections:
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ result. Light can come from several types of sources in a scene:
|
|||||||
it does not affect nearby objects unless baked).
|
it does not affect nearby objects unless baked).
|
||||||
- Light Nodes: Directional, Omni and Spot.
|
- Light Nodes: Directional, Omni and Spot.
|
||||||
- Ambient Light in the
|
- Ambient Light in the
|
||||||
`Environment <class_Environment>`.
|
`Environment`.
|
||||||
- Baked Light (read `doc_baked_lightmaps`).
|
- Baked Light (read `doc_baked_lightmaps`).
|
||||||
|
|
||||||
The emission color is a material property. You can read more about it
|
The emission color is a material property. You can read more about it
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
Using the ArrayMesh
|
Using the ArrayMesh
|
||||||
===================
|
===================
|
||||||
|
|
||||||
This tutorial will present the basics of using an `ArrayMesh <class_arraymesh>`.
|
This tutorial will present the basics of using an `ArrayMesh`.
|
||||||
|
|
||||||
To do so, we will use the function `add_surface_from_arrays() <class_ArrayMesh_method_add_surface_from_arrays>`,
|
To do so, we will use the function `add_surface_from_arrays()`,
|
||||||
which takes up to four parameters. The first two are required, while the second two are optional.
|
which takes up to four parameters. The first two are required, while the second two are optional.
|
||||||
|
|
||||||
The first parameter is the ``PrimitiveType``, an OpenGL concept that instructs the GPU
|
The first parameter is the ``PrimitiveType``, an OpenGL concept that instructs the GPU
|
||||||
@ -32,40 +32,40 @@ See also `Mesh.ArrayType <enum_Mesh_ArrayType>`.
|
|||||||
|
|
||||||
* - 0
|
* - 0
|
||||||
- ``ARRAY_VERTEX``
|
- ``ARRAY_VERTEX``
|
||||||
- `PoolVector3Array <class_PoolVector3Array>` or `PoolVector2Array <class_PoolVector2Array>`
|
- `PoolVector3Array`
|
||||||
|
|
||||||
* - 1
|
* - 1
|
||||||
- ``ARRAY_NORMAL``
|
- ``ARRAY_NORMAL``
|
||||||
- `PoolVector3Array <class_PoolVector3Array>`
|
- `PoolVector3Array`
|
||||||
|
|
||||||
* - 2
|
* - 2
|
||||||
- ``ARRAY_TANGENT``
|
- ``ARRAY_TANGENT``
|
||||||
- `PoolRealArray <class_PoolRealArray>` of groups of 4 floats. First 3 floats determine the tangent, and
|
- `PoolRealArray` of groups of 4 floats. First 3 floats determine the tangent, and
|
||||||
the last the binormal direction as -1 or 1.
|
the last the binormal direction as -1 or 1.
|
||||||
|
|
||||||
* - 3
|
* - 3
|
||||||
- ``ARRAY_COLOR``
|
- ``ARRAY_COLOR``
|
||||||
- `PoolColorArray <class_PoolColorArray>`
|
- `PoolColorArray`
|
||||||
|
|
||||||
* - 4
|
* - 4
|
||||||
- ``ARRAY_TEX_UV``
|
- ``ARRAY_TEX_UV``
|
||||||
- `PoolVector2Array <class_PoolVector2Array>` or `PoolVector3Array <class_PoolVector3Array>`
|
- `PoolVector2Array`
|
||||||
|
|
||||||
* - 5
|
* - 5
|
||||||
- ``ARRAY_TEX_UV2``
|
- ``ARRAY_TEX_UV2``
|
||||||
- `PoolVector2Array <class_PoolVector2Array>` or `PoolVector3Array <class_PoolVector3Array>`
|
- `PoolVector2Array`
|
||||||
|
|
||||||
* - 6
|
* - 6
|
||||||
- ``ARRAY_BONES``
|
- ``ARRAY_BONES``
|
||||||
- `PoolRealArray <class_PoolRealArray>` of groups of 4 floats or `PoolIntArray <class_PoolIntArray>` of groups of 4 ints. Each group lists indexes of 4 bones that affects a given vertex.
|
- `PoolRealArray` of groups of 4 ints. Each group lists indexes of 4 bones that affects a given vertex.
|
||||||
|
|
||||||
* - 7
|
* - 7
|
||||||
- ``ARRAY_WEIGHTS``
|
- ``ARRAY_WEIGHTS``
|
||||||
- `PoolRealArray <class_PoolRealArray>` of groups of 4 floats. Each float lists the amount of weight an determined bone on ``ARRAY_BONES`` has on a given vertex.
|
- `PoolRealArray` of groups of 4 floats. Each float lists the amount of weight an determined bone on ``ARRAY_BONES`` has on a given vertex.
|
||||||
|
|
||||||
* - 8
|
* - 8
|
||||||
- ``ARRAY_INDEX``
|
- ``ARRAY_INDEX``
|
||||||
- `PoolIntArray <class_PoolIntArray>`
|
- `PoolIntArray`
|
||||||
|
|
||||||
The array of vertices (at index 0) is always required. The index array is optional and will only be used if included. We won't use it in this tutorial.
|
The array of vertices (at index 0) is always required. The index array is optional and will only be used if included. We won't use it in this tutorial.
|
||||||
|
|
||||||
@ -73,12 +73,12 @@ All the other arrays carry information about the vertices. They are also optiona
|
|||||||
use one entry per vertex to provide extra information about vertices. They must have the same size as the vertex array. Other arrays (e.g. ``ARRAY_TANGENT``) use
|
use one entry per vertex to provide extra information about vertices. They must have the same size as the vertex array. Other arrays (e.g. ``ARRAY_TANGENT``) use
|
||||||
four entries to describe a single vertex. These must be exactly four times larger than the vertex array.
|
four entries to describe a single vertex. These must be exactly four times larger than the vertex array.
|
||||||
|
|
||||||
For normal usage, the last two parameters in `add_surface_from_arrays() <class_arraymesh_method_add_surface_from_arrays>` are typically left empty.
|
For normal usage, the last two parameters in `add_surface_from_arrays()` are typically left empty.
|
||||||
|
|
||||||
ArrayMesh
|
ArrayMesh
|
||||||
---------
|
---------
|
||||||
|
|
||||||
In the editor, create a `MeshInstance <class_meshinstance>` and add an `ArrayMesh <class_arraymesh>` to it in the Inspector.
|
In the editor, create a `MeshInstance` to it in the Inspector.
|
||||||
Normally, adding an ArrayMesh in the editor is not useful, but in this case it allows us to access the ArrayMesh
|
Normally, adding an ArrayMesh in the editor is not useful, but in this case it allows us to access the ArrayMesh
|
||||||
from code without creating one.
|
from code without creating one.
|
||||||
|
|
||||||
@ -239,7 +239,7 @@ gdscript GDScript
|
|||||||
Saving
|
Saving
|
||||||
------
|
------
|
||||||
|
|
||||||
Finally, we can use the `ResourceSaver <class_resourcesaver>` class to save the ArrayMesh.
|
Finally, we can use the `ResourceSaver` class to save the ArrayMesh.
|
||||||
This is useful when you want to generate a mesh and then use it later without having to re-generate it.
|
This is useful when you want to generate a mesh and then use it later without having to re-generate it.
|
||||||
|
|
||||||
gdscript GDScript
|
gdscript GDScript
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
Using ImmediateGeometry
|
Using ImmediateGeometry
|
||||||
=======================
|
=======================
|
||||||
|
|
||||||
Unlike the SurfaceTool or ArrayMesh, `ImmediateGeometry <class_ImmediateGeometry>` is an actual
|
Unlike the SurfaceTool or ArrayMesh, `ImmediateGeometry` is an actual
|
||||||
node. Being a node makes it quick to add to a scene and get visual output. It uses an OpenGL 1.x-style
|
node. Being a node makes it quick to add to a scene and get visual output. It uses an OpenGL 1.x-style
|
||||||
API like SurfaceTool, but it's actually designed to create meshes on the fly.
|
API like SurfaceTool, but it's actually designed to create meshes on the fly.
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ not call ``clear()``.
|
|||||||
To begin generating geometry you must call ``begin()``. ``begin()`` takes a ``PrimitiveType`` as an argument.
|
To begin generating geometry you must call ``begin()``. ``begin()`` takes a ``PrimitiveType`` as an argument.
|
||||||
``PrimitiveType`` is an OpenGL concept that instructs the GPU how to arrange the primitive based on the
|
``PrimitiveType`` is an OpenGL concept that instructs the GPU how to arrange the primitive based on the
|
||||||
vertices given whether it is triangles, lines, points, etc. A complete list can be found under
|
vertices given whether it is triangles, lines, points, etc. A complete list can be found under
|
||||||
the `Mesh <class_mesh>` class reference page.
|
the `Mesh` class reference page.
|
||||||
|
|
||||||
Once you have called ``begin()`` you are ready to start adding vertices. You add vertices one at a time.
|
Once you have called ``begin()`` you are ready to start adding vertices. You add vertices one at a time.
|
||||||
First you add vertex specific attributes such as normals or UVs using ``set_****()`` (e.g. ``set_normal()``).
|
First you add vertex specific attributes such as normals or UVs using ``set_****()`` (e.g. ``set_normal()``).
|
||||||
|
@ -25,9 +25,9 @@ by an array of positions called "vertices". In Godot, geometry is represented by
|
|||||||
What is a Mesh?
|
What is a Mesh?
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
Many things in Godot have mesh in their name: the `Mesh <class_Mesh>`, the `ArrayMesh <class_ArrayMesh>`,
|
Many things in Godot have mesh in their name: the `Mesh`,
|
||||||
the `MeshInstance <class_MeshInstance>`, the `MultiMesh <class_MultiMesh>`, and
|
the `MeshInstance`, and
|
||||||
the `MultiMeshInstance <class_MultiMeshInstance>`. While they are all related, they have slightly different uses.
|
the `MultiMeshInstance`. While they are all related, they have slightly different uses.
|
||||||
|
|
||||||
Meshes and ArrayMeshes are resources that are drawn using a MeshInstance node. Resources like
|
Meshes and ArrayMeshes are resources that are drawn using a MeshInstance node. Resources like
|
||||||
Meshes and ArrayMeshes cannot be added to the scene directly. A MeshInstance represents one
|
Meshes and ArrayMeshes cannot be added to the scene directly. A MeshInstance represents one
|
||||||
@ -47,21 +47,21 @@ What a Mesh is
|
|||||||
|
|
||||||
A Mesh is composed of one or more surfaces. A surface is an array composed of multiple sub-arrays
|
A Mesh is composed of one or more surfaces. A surface is an array composed of multiple sub-arrays
|
||||||
containing vertices, normals, UVs, etc. Normally the process of constructing surfaces and meshes is
|
containing vertices, normals, UVs, etc. Normally the process of constructing surfaces and meshes is
|
||||||
hidden from the user in the `VisualServer <class_VisualServer>`, but with ArrayMeshes, the user can construct a Mesh
|
hidden from the user in the `VisualServer`, but with ArrayMeshes, the user can construct a Mesh
|
||||||
manually by passing in an array containing the surface information.
|
manually by passing in an array containing the surface information.
|
||||||
|
|
||||||
Surfaces
|
Surfaces
|
||||||
^^^^^^^^
|
^^^^^^^^
|
||||||
|
|
||||||
Each surface has its own material. Alternatively, you can override the material for all surfaces
|
Each surface has its own material. Alternatively, you can override the material for all surfaces
|
||||||
in the Mesh when you use a MeshInstance using the `material_override <class_GeometryInstance_property_material_override>` property.
|
in the Mesh when you use a MeshInstance using the `material_override` property.
|
||||||
|
|
||||||
Surface array
|
Surface array
|
||||||
^^^^^^^^^^^^^
|
^^^^^^^^^^^^^
|
||||||
|
|
||||||
The surface array is an array of length ``ArrayMesh.ARRAY_MAX``. Each position in the array is
|
The surface array is an array of length ``ArrayMesh.ARRAY_MAX``. Each position in the array is
|
||||||
filled with a sub-array containing per-vertex information. For example, the array located at
|
filled with a sub-array containing per-vertex information. For example, the array located at
|
||||||
``ArrayMesh.ARRAY_NORMAL`` is a `PoolVector3Array <class_PoolVector3Array>` of vertex normals.
|
``ArrayMesh.ARRAY_NORMAL`` is a `PoolVector3Array` of vertex normals.
|
||||||
See `Mesh.ArrayType <enum_Mesh_ArrayType>` for more information.
|
See `Mesh.ArrayType <enum_Mesh_ArrayType>` for more information.
|
||||||
|
|
||||||
The surface array can be indexed or non-indexed. Creating a non-indexed array is as easy as not assigning
|
The surface array can be indexed or non-indexed. Creating a non-indexed array is as easy as not assigning
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
Using the MeshDataTool
|
Using the MeshDataTool
|
||||||
======================
|
======================
|
||||||
|
|
||||||
The `MeshDataTool <class_meshdatatool>` is not used to generate geometry. But it is helpful for dynamically altering geometry, for example
|
The `MeshDataTool` is not used to generate geometry. But it is helpful for dynamically altering geometry, for example
|
||||||
if you want to write a script to tessellate, simplify, or deform meshes.
|
if you want to write a script to tessellate, simplify, or deform meshes.
|
||||||
|
|
||||||
The MeshDataTool is not as fast as altering arrays directly using ArrayMesh. However, it provides more information
|
The MeshDataTool is not as fast as altering arrays directly using ArrayMesh. However, it provides more information
|
||||||
@ -61,7 +61,7 @@ gdscript GDScript
|
|||||||
```
|
```
|
||||||
|
|
||||||
These modifications are not done in place on the ArrayMesh. If you are dynamically updating an existing ArrayMesh,
|
These modifications are not done in place on the ArrayMesh. If you are dynamically updating an existing ArrayMesh,
|
||||||
first delete the existing surface before adding a new one using `commit_to_surface() <class_meshdatatool_method_commit_to_surface>`:
|
first delete the existing surface before adding a new one using `commit_to_surface()`:
|
||||||
|
|
||||||
gdscript GDScript
|
gdscript GDScript
|
||||||
|
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
Using the SurfaceTool
|
Using the SurfaceTool
|
||||||
=====================
|
=====================
|
||||||
|
|
||||||
The `SurfaceTool <class_surfacetool>` provides a useful interface for constructing geometry.
|
The `SurfaceTool` provides a useful interface for constructing geometry.
|
||||||
The interface is similar to the `ImmediateGeometry <class_immediategeometry>` node. You
|
The interface is similar to the `ImmediateGeometry` node. You
|
||||||
set each per-vertex attribute (e.g. normal, uv, color) and then when you add a vertex it
|
set each per-vertex attribute (e.g. normal, uv, color) and then when you add a vertex it
|
||||||
captures the attributes.
|
captures the attributes.
|
||||||
|
|
||||||
@ -22,8 +22,8 @@ gdscript GDScript
|
|||||||
st.add_normal() # Normal never added to a vertex.
|
st.add_normal() # Normal never added to a vertex.
|
||||||
```
|
```
|
||||||
|
|
||||||
When finished generating your geometry with the `SurfaceTool <class_surfacetool>`
|
When finished generating your geometry with the `SurfaceTool`
|
||||||
call ``commit()`` to finish generating the mesh. If an `ArrayMesh <class_ArrayMesh>` is passed
|
call ``commit()`` to finish generating the mesh. If an `ArrayMesh` is passed
|
||||||
to ``commit()`` then it appends a new surface to the end of the ArrayMesh. While if nothing is passed
|
to ``commit()`` then it appends a new surface to the end of the ArrayMesh. While if nothing is passed
|
||||||
in, ``commit()`` returns an ArrayMesh.
|
in, ``commit()`` returns an ArrayMesh.
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ Using GridMaps
|
|||||||
Introduction
|
Introduction
|
||||||
------------
|
------------
|
||||||
|
|
||||||
`Gridmaps <class_GridMap>` are a tool for creating 3D
|
`Gridmaps` are a tool for creating 3D
|
||||||
game levels, similar to the way `TileMap <doc_using_tilemaps>`
|
game levels, similar to the way `TileMap <doc_using_tilemaps>`
|
||||||
works in 2D. You start with a predefined collection of 3D meshes (a
|
works in 2D. You start with a predefined collection of 3D meshes (a
|
||||||
`class_MeshLibrary`) that can be placed on a grid,
|
`class_MeshLibrary`) that can be placed on a grid,
|
||||||
|
@ -6,13 +6,13 @@ Using MultiMeshInstance
|
|||||||
Introduction
|
Introduction
|
||||||
~~~~~~~~~~~~
|
~~~~~~~~~~~~
|
||||||
|
|
||||||
In a normal scenario, you would use a `MeshInstance <class_MeshInstance>`
|
In a normal scenario, you would use a `MeshInstance`
|
||||||
node to display a 3D mesh like a human model for the main character, but in some
|
node to display a 3D mesh like a human model for the main character, but in some
|
||||||
cases, you would like to create multiple instances of the same mesh in a scene.
|
cases, you would like to create multiple instances of the same mesh in a scene.
|
||||||
You *could* duplicate the same node multiple times and adjust the transforms
|
You *could* duplicate the same node multiple times and adjust the transforms
|
||||||
manually. This may be a tedious process and the result may look mechanical.
|
manually. This may be a tedious process and the result may look mechanical.
|
||||||
Also, this method is not conducive to rapid iterations.
|
Also, this method is not conducive to rapid iterations.
|
||||||
`MultiMeshInstance <class_MultiMeshInstance>` is one of the possible
|
`MultiMeshInstance` is one of the possible
|
||||||
solutions to this problem.
|
solutions to this problem.
|
||||||
|
|
||||||
MultiMeshInstance, as the name suggests, creates multiple copies of a
|
MultiMeshInstance, as the name suggests, creates multiple copies of a
|
||||||
@ -31,7 +31,7 @@ on. In the tree example, this would be the landscape.
|
|||||||
The other node is used as the source, the mesh that you want to have duplicated.
|
The other node is used as the source, the mesh that you want to have duplicated.
|
||||||
In the tree case, this would be the tree itself.
|
In the tree case, this would be the tree itself.
|
||||||
|
|
||||||
In our example, we would use a `Spatial <class_Spatial>` node as the root node of
|
In our example, we would use a `Spatial` node as the root node of
|
||||||
the scene. Your scene tree would look like this:
|
the scene. Your scene tree would look like this:
|
||||||
|
|
||||||
.. image:: img/multimesh_scene_tree.png
|
.. image:: img/multimesh_scene_tree.png
|
||||||
|
@ -6,13 +6,13 @@ Using AnimationTree
|
|||||||
Introduction
|
Introduction
|
||||||
------------
|
------------
|
||||||
|
|
||||||
With `AnimationPlayer <class_AnimationPlayer>`, Godot has one of the most flexible animation systems that you can find in any game engine.
|
With `AnimationPlayer`, Godot has one of the most flexible animation systems that you can find in any game engine.
|
||||||
The ability to animate almost any property in any node or resource, as well as having dedicated transform, bezier,
|
The ability to animate almost any property in any node or resource, as well as having dedicated transform, bezier,
|
||||||
function calling, audio and sub-animation tracks, is pretty much unique.
|
function calling, audio and sub-animation tracks, is pretty much unique.
|
||||||
|
|
||||||
However, the support for blending those animations via ``AnimationPlayer`` is relatively limited, as only a fixed cross-fade transition time can be set.
|
However, the support for blending those animations via ``AnimationPlayer`` is relatively limited, as only a fixed cross-fade transition time can be set.
|
||||||
|
|
||||||
`AnimationTree <class_AnimationTree>` is a new node introduced in Godot 3.1 to deal with advanced transitions.
|
`AnimationTree` is a new node introduced in Godot 3.1 to deal with advanced transitions.
|
||||||
It supersedes the ancient ``AnimationTreePlayer``, while adding a huge amount of features and flexibility.
|
It supersedes the ancient ``AnimationTreePlayer``, while adding a huge amount of features and flexibility.
|
||||||
|
|
||||||
Creating an AnimationTree
|
Creating an AnimationTree
|
||||||
@ -193,7 +193,7 @@ transformation visually (the animation will stay in place).
|
|||||||
|
|
||||||
.. image:: img/animtree14.png
|
.. image:: img/animtree14.png
|
||||||
|
|
||||||
Afterwards, the actual motion can be retrieved via the `AnimationTree <class_AnimationTree>` API as a transform:
|
Afterwards, the actual motion can be retrieved via the `AnimationTree` API as a transform:
|
||||||
|
|
||||||
gdscript GDScript
|
gdscript GDScript
|
||||||
|
|
||||||
@ -201,7 +201,7 @@ gdscript GDScript
|
|||||||
anim_tree.get_root_motion_transform()
|
anim_tree.get_root_motion_transform()
|
||||||
```
|
```
|
||||||
|
|
||||||
This can be fed to functions such as `KinematicBody.move_and_slide <class_KinematicBody_method_move_and_slide>` to control the character movement.
|
This can be fed to functions such as `KinematicBody.move_and_slide` to control the character movement.
|
||||||
|
|
||||||
There is also a tool node, ``RootMotionView``, that can be placed in a scene and will act as a custom floor for your
|
There is also a tool node, ``RootMotionView``, that can be placed in a scene and will act as a custom floor for your
|
||||||
character and animations (this node is disabled by default during the game).
|
character and animations (this node is disabled by default during the game).
|
||||||
@ -250,7 +250,7 @@ current state to another one, while visiting all the intermediate ones. This is
|
|||||||
In the absence of any viable set of transitions starting at the current state and finishing at the destination state, the graph teleports
|
In the absence of any viable set of transitions starting at the current state and finishing at the destination state, the graph teleports
|
||||||
to the destination state.
|
to the destination state.
|
||||||
|
|
||||||
To use the travel ability, you should first retrieve the `AnimationNodeStateMachinePlayback <class_AnimationNodeStateMachinePlayback>`
|
To use the travel ability, you should first retrieve the `AnimationNodeStateMachinePlayback`
|
||||||
object from the ``AnimationTree`` node (it is exported as a property).
|
object from the ``AnimationTree`` node (it is exported as a property).
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ Godot provides tools for working with cutout rigs, and is ideal for the workflow
|
|||||||
selectively for complex parts such as hands, feet, changing facial expressions,
|
selectively for complex parts such as hands, feet, changing facial expressions,
|
||||||
etc.
|
etc.
|
||||||
- **Custom Shaped Elements**: Custom shapes can be created with
|
- **Custom Shaped Elements**: Custom shapes can be created with
|
||||||
`Polygon2D <class_Polygon2D>`
|
`Polygon2D`
|
||||||
allowing UV animation, deformations, etc.
|
allowing UV animation, deformations, etc.
|
||||||
- **Particle Systems**: A cutout animation rig can be combined with particle
|
- **Particle Systems**: A cutout animation rig can be combined with particle
|
||||||
systems. This can be useful for magic effects, jetpacks, etc.
|
systems. This can be useful for magic effects, jetpacks, etc.
|
||||||
@ -87,7 +87,7 @@ and dragging with the left mouse button. To exit rotate mode hit :kbd:`ESC`.
|
|||||||
|
|
||||||
The rotation pivot is wrong and needs to be adjusted.
|
The rotation pivot is wrong and needs to be adjusted.
|
||||||
|
|
||||||
This small cross in the middle of the `Sprite <class_Sprite>` is
|
This small cross in the middle of the `Sprite` is
|
||||||
the rotation pivot:
|
the rotation pivot:
|
||||||
|
|
||||||
.. image:: img/tuto_cutout4.png
|
.. image:: img/tuto_cutout4.png
|
||||||
@ -130,7 +130,7 @@ of the torso. We'll fix this problem with ``RemoteTransform2D`` nodes.
|
|||||||
RemoteTransform2D node
|
RemoteTransform2D node
|
||||||
~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
The `RemoteTransform2D <class_RemoteTransform2D>` node transforms nodes
|
The `RemoteTransform2D` node transforms nodes
|
||||||
somewhere else in the hierarchy. This node applies its own transform (including
|
somewhere else in the hierarchy. This node applies its own transform (including
|
||||||
any transformation it inherits from its parents) to the remote node it targets.
|
any transformation it inherits from its parents) to the remote node it targets.
|
||||||
|
|
||||||
@ -193,7 +193,7 @@ node with its parent. And there's currently no child of the hand node.
|
|||||||
With this knowledge let's try again.
|
With this knowledge let's try again.
|
||||||
|
|
||||||
The first step is creating an endpoint node. Any kind of node will do,
|
The first step is creating an endpoint node. Any kind of node will do,
|
||||||
but `Position2D <class_Position2D>` is preferred because it's
|
but `Position2D` is preferred because it's
|
||||||
visible in the editor. The endpoint node will ensure that the last bone
|
visible in the editor. The endpoint node will ensure that the last bone
|
||||||
has orientation.
|
has orientation.
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ There are several limitations with the current implementation of video playback
|
|||||||
- Changing playback speed is not supported. VideoPlayer also won't follow
|
- Changing playback speed is not supported. VideoPlayer also won't follow
|
||||||
`Engine.time_scale<class_Engine_property_time_scale>`.
|
`Engine.time_scale<class_Engine_property_time_scale>`.
|
||||||
- Looping is not supported, but you can connect a VideoPlayer's
|
- Looping is not supported, but you can connect a VideoPlayer's
|
||||||
`finished <class_VideoPlayer_signal_finished>` signal to a function
|
`finished` signal to a function
|
||||||
that plays the video again. However, this will cause a black frame to be
|
that plays the video again. However, this will cause a black frame to be
|
||||||
visible when the video restarts. This can be worked around by adding a fade to
|
visible when the video restarts. This can be worked around by adding a fade to
|
||||||
black in the video file before the video ends, or by hiding the video for one
|
black in the video file before the video ends, or by hiding the video for one
|
||||||
|
@ -20,11 +20,11 @@ and keep the imported resources hidden in a ``res://.import`` folder.
|
|||||||
This means that when trying to access imported assets through code you
|
This means that when trying to access imported assets through code you
|
||||||
need to use the `Resource Loader<class_ResourceLoader>` as it will
|
need to use the `Resource Loader<class_ResourceLoader>` as it will
|
||||||
automatically take into account where the internal files are saved. If you
|
automatically take into account where the internal files are saved. If you
|
||||||
try and access an imported asset using the `File <class_File>` class
|
try and access an imported asset using the `File` class
|
||||||
it will work in the editor, but break in the exported project.
|
it will work in the editor, but break in the exported project.
|
||||||
|
|
||||||
However, the `Resource Loader<class_ResourceLoader>` cannot access
|
However, the `Resource Loader<class_ResourceLoader>` cannot access
|
||||||
non imported files, only the `File <class_File>` class can.
|
non imported files, only the `File` class can.
|
||||||
|
|
||||||
Changing import parameters
|
Changing import parameters
|
||||||
--------------------------
|
--------------------------
|
||||||
|
@ -258,7 +258,7 @@ Reverb
|
|||||||
|
|
||||||
Reverb simulates rooms of different sizes. It has adjustable parameters that can
|
Reverb simulates rooms of different sizes. It has adjustable parameters that can
|
||||||
be tweaked to obtain the sound of a specific room. Reverb is commonly outputted
|
be tweaked to obtain the sound of a specific room. Reverb is commonly outputted
|
||||||
from `Areas <class_Area>`
|
from `Areas`
|
||||||
(see `Reverb buses <doc_audio_streams_reverb_buses>`), or to apply
|
(see `Reverb buses <doc_audio_streams_reverb_buses>`), or to apply
|
||||||
a "chamber" feel to all sounds.
|
a "chamber" feel to all sounds.
|
||||||
|
|
||||||
|
@ -43,9 +43,9 @@ gdscript GDScript
|
|||||||
|
|
||||||
The audio recording is handled by the `class_AudioEffectRecord` resource
|
The audio recording is handled by the `class_AudioEffectRecord` resource
|
||||||
which has three methods:
|
which has three methods:
|
||||||
`get_recording() <class_AudioEffectRecord_method_get_recording>`,
|
`get_recording()`,
|
||||||
`is_recording_active() <class_AudioEffectRecord_method_is_recording_active>`,
|
`is_recording_active()`,
|
||||||
and `set_recording_active() <class_AudioEffectRecord_method_set_recording_active>`.
|
and `set_recording_active()`.
|
||||||
|
|
||||||
gdscript GDScript
|
gdscript GDScript
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ Autoloads versus regular nodes
|
|||||||
Godot offers a feature to automatically load nodes at the root of your project,
|
Godot offers a feature to automatically load nodes at the root of your project,
|
||||||
allowing you to access them globally, that can fulfill the role of a Singleton:
|
allowing you to access them globally, that can fulfill the role of a Singleton:
|
||||||
`doc_singletons_autoload`. These auto-loaded nodes are not freed when you
|
`doc_singletons_autoload`. These auto-loaded nodes are not freed when you
|
||||||
change the scene from code with `SceneTree.change_scene <class_SceneTree_method_change_scene>`.
|
change the scene from code with `SceneTree.change_scene`.
|
||||||
|
|
||||||
In this guide, you will learn when to use the Autoload feature, and techniques
|
In this guide, you will learn when to use the Autoload feature, and techniques
|
||||||
you can use to avoid it.
|
you can use to avoid it.
|
||||||
@ -72,7 +72,7 @@ that feature for an individual scene using the `class_name
|
|||||||
|
|
||||||
When it comes to data, you can either:
|
When it comes to data, you can either:
|
||||||
|
|
||||||
1. Create a new type of `Resource <class_Resource>` to share the data.
|
1. Create a new type of `Resource` to share the data.
|
||||||
|
|
||||||
2. Store the data in an object to which each node has access, for example using
|
2. Store the data in an object to which each node has access, for example using
|
||||||
the ``owner`` property to access the scene's root node.
|
the ``owner`` property to access the scene's root node.
|
||||||
|
@ -42,8 +42,8 @@ Array vs. Dictionary vs. Object
|
|||||||
Godot stores all variables in the scripting API in the
|
Godot stores all variables in the scripting API in the
|
||||||
`Variant <https://docs.godotengine.org/en/latest/development/cpp/variant_class.html>`_
|
`Variant <https://docs.godotengine.org/en/latest/development/cpp/variant_class.html>`_
|
||||||
class. Variants can store Variant-compatible data structures such as
|
class. Variants can store Variant-compatible data structures such as
|
||||||
`Array <class_Array>` and `Dictionary <class_Dictionary>` as well as
|
`Array` as well as
|
||||||
`Object <class_Object>` s.
|
`Object` s.
|
||||||
|
|
||||||
Godot implements Array as a ``Vector<Variant>``. The engine stores the Array
|
Godot implements Array as a ``Vector<Variant>``. The engine stores the Array
|
||||||
contents in a contiguous section of memory, i.e. they are in a row adjacent
|
contents in a contiguous section of memory, i.e. they are in a row adjacent
|
||||||
@ -54,7 +54,7 @@ to each other.
|
|||||||
array object in traditional C++ libraries. It is a "templated"
|
array object in traditional C++ libraries. It is a "templated"
|
||||||
type, meaning that its records can only contain a particular type (denoted
|
type, meaning that its records can only contain a particular type (denoted
|
||||||
by angled brackets). So, for example, a
|
by angled brackets). So, for example, a
|
||||||
`PoolStringArray <class_PoolStringArray>` would be something like
|
`PoolStringArray` would be something like
|
||||||
a ``Vector<String>``.
|
a ``Vector<String>``.
|
||||||
|
|
||||||
Contiguous memory stores imply the following operation performance:
|
Contiguous memory stores imply the following operation performance:
|
||||||
@ -167,7 +167,7 @@ do not. An overview of their operational details is as follows:
|
|||||||
Godot implements Objects as stupid, but dynamic containers of data content.
|
Godot implements Objects as stupid, but dynamic containers of data content.
|
||||||
Objects query data sources when posed questions. For example, to answer
|
Objects query data sources when posed questions. For example, to answer
|
||||||
the question, "do you have a property called, 'position'?", it might ask
|
the question, "do you have a property called, 'position'?", it might ask
|
||||||
its `script <class_Script>` or the `ClassDB <class_ClassDB>`.
|
its `script`.
|
||||||
One can find more information about what objects are and how they work in
|
One can find more information about what objects are and how they work in
|
||||||
the `doc_what_are_godot_classes` article.
|
the `doc_what_are_godot_classes` article.
|
||||||
|
|
||||||
@ -283,7 +283,7 @@ AnimatedTexture vs. AnimatedSprite vs. AnimationPlayer vs. AnimationTree
|
|||||||
Under what circumstances should one use each of Godot's animation classes?
|
Under what circumstances should one use each of Godot's animation classes?
|
||||||
The answer may not be immediately clear to new Godot users.
|
The answer may not be immediately clear to new Godot users.
|
||||||
|
|
||||||
`AnimatedTexture <class_AnimatedTexture>` is a texture that
|
`AnimatedTexture` is a texture that
|
||||||
the engine draws as an animated loop rather than a static image.
|
the engine draws as an animated loop rather than a static image.
|
||||||
Users can manipulate...
|
Users can manipulate...
|
||||||
|
|
||||||
@ -291,21 +291,21 @@ Users can manipulate...
|
|||||||
|
|
||||||
2. the number of regions contained within the texture (frames).
|
2. the number of regions contained within the texture (frames).
|
||||||
|
|
||||||
Godot's `VisualServer <class_VisualServer>` then draws
|
Godot's `VisualServer` then draws
|
||||||
the regions in sequence at the prescribed rate. The good news is that this
|
the regions in sequence at the prescribed rate. The good news is that this
|
||||||
involves no extra logic on the part of the engine. The bad news is
|
involves no extra logic on the part of the engine. The bad news is
|
||||||
that users have very little control.
|
that users have very little control.
|
||||||
|
|
||||||
Also note that AnimatedTexture is a `Resource <class_Resource>` unlike
|
Also note that AnimatedTexture is a `Resource` unlike
|
||||||
the other `Node <class_Node>` objects discussed here. One might create
|
the other `Node` objects discussed here. One might create
|
||||||
a `Sprite <class_Sprite>` node that uses AnimatedTexture as its texture.
|
a `Sprite` node that uses AnimatedTexture as its texture.
|
||||||
Or (something the others can't do) one could add AnimatedTextures as tiles
|
Or (something the others can't do) one could add AnimatedTextures as tiles
|
||||||
in a `TileSet <class_TileSet>` and integrate it with a
|
in a `TileSet` and integrate it with a
|
||||||
`TileMap <class_TileMap>` for many auto-animating backgrounds that
|
`TileMap` for many auto-animating backgrounds that
|
||||||
all render in a single batched draw call.
|
all render in a single batched draw call.
|
||||||
|
|
||||||
The AnimatedSprite node, in combination with the
|
The AnimatedSprite node, in combination with the
|
||||||
`SpriteFrames <class_SpriteFrames>` resource, allows one to create a
|
`SpriteFrames` resource, allows one to create a
|
||||||
variety of animation sequences through spritesheets, flip between animations,
|
variety of animation sequences through spritesheets, flip between animations,
|
||||||
and control their speed, regional offset, and orientation. This makes them
|
and control their speed, regional offset, and orientation. This makes them
|
||||||
well-suited to controlling 2D frame-based animations.
|
well-suited to controlling 2D frame-based animations.
|
||||||
@ -313,7 +313,7 @@ well-suited to controlling 2D frame-based animations.
|
|||||||
If one needs trigger other effects in relation to animation changes (for
|
If one needs trigger other effects in relation to animation changes (for
|
||||||
example, create particle effects, call functions, or manipulate other
|
example, create particle effects, call functions, or manipulate other
|
||||||
peripheral elements besides the frame-based animation), then will need to use
|
peripheral elements besides the frame-based animation), then will need to use
|
||||||
an `AnimationPlayer <class_AnimationPlayer>` node in conjunction with
|
an `AnimationPlayer` node in conjunction with
|
||||||
the AnimatedSprite.
|
the AnimatedSprite.
|
||||||
|
|
||||||
AnimationPlayers are also the tool one will need to use if they wish to design
|
AnimationPlayers are also the tool one will need to use if they wish to design
|
||||||
@ -332,6 +332,6 @@ While one needs an AnimationPlayer to design each of the individual
|
|||||||
animation sequences for a game, it can also be useful to combine animations
|
animation sequences for a game, it can also be useful to combine animations
|
||||||
for blending, i.e. enabling smooth transitions between these animations. There
|
for blending, i.e. enabling smooth transitions between these animations. There
|
||||||
may also be a hierarchical structure between animations that one plans out for
|
may also be a hierarchical structure between animations that one plans out for
|
||||||
their object. These are the cases where the `AnimationTree <class_AnimationTree>`
|
their object. These are the cases where the `AnimationTree`
|
||||||
shines. One can find an in-depth guide on using the AnimationTree
|
shines. One can find an in-depth guide on using the AnimationTree
|
||||||
`here <doc_animation_tree>`.
|
`here <doc_animation_tree>`.
|
||||||
|
@ -15,7 +15,7 @@ The rest of this tutorial outlines the various ways of doing all this.
|
|||||||
Acquiring object references
|
Acquiring object references
|
||||||
---------------------------
|
---------------------------
|
||||||
|
|
||||||
For all `Object <class_Object>`\s, the most basic way of referencing them
|
For all `Object`\s, the most basic way of referencing them
|
||||||
is to get a reference to an existing object from another acquired instance.
|
is to get a reference to an existing object from another acquired instance.
|
||||||
|
|
||||||
gdscript GDScript
|
gdscript GDScript
|
||||||
@ -25,9 +25,9 @@ gdscript GDScript
|
|||||||
var obj = node.get_object() # Method access.
|
var obj = node.get_object() # Method access.
|
||||||
```
|
```
|
||||||
|
|
||||||
The same principle applies for `Reference <class_Reference>` objects.
|
The same principle applies for `Reference` objects.
|
||||||
While users often access `Node <class_Node>` and
|
While users often access `Node` and
|
||||||
`Resource <class_Resource>` this way, alternative measures are available.
|
`Resource` this way, alternative measures are available.
|
||||||
|
|
||||||
Instead of property or method access, one can get Resources by load
|
Instead of property or method access, one can get Resources by load
|
||||||
access.
|
access.
|
||||||
@ -72,7 +72,7 @@ Note the following:
|
|||||||
|
|
||||||
3. Keep in mind that loading a resource fetches the cached resource
|
3. Keep in mind that loading a resource fetches the cached resource
|
||||||
instance maintained by the engine. To get a new object, one must
|
instance maintained by the engine. To get a new object, one must
|
||||||
`duplicate <class_Resource_method_duplicate>` an existing reference
|
`duplicate` an existing reference
|
||||||
or instantiate one from scratch with ``new()``.
|
or instantiate one from scratch with ``new()``.
|
||||||
|
|
||||||
Nodes likewise have an alternative access point: the SceneTree.
|
Nodes likewise have an alternative access point: the SceneTree.
|
||||||
@ -140,10 +140,10 @@ Godot's scripting API is duck-typed. This means that if a script executes an
|
|||||||
operation, Godot doesn't validate that it supports the operation by **type**.
|
operation, Godot doesn't validate that it supports the operation by **type**.
|
||||||
It instead checks that the object **implements** the individual method.
|
It instead checks that the object **implements** the individual method.
|
||||||
|
|
||||||
For example, the `CanvasItem <class_CanvasItem>` class has a ``visible``
|
For example, the `CanvasItem` class has a ``visible``
|
||||||
property. All properties exposed to the scripting API are in fact a setter and
|
property. All properties exposed to the scripting API are in fact a setter and
|
||||||
getter pair bound to a name. If one tried to access
|
getter pair bound to a name. If one tried to access
|
||||||
`CanvasItem.visible <class_CanvasItem_property_visible>`, then Godot would do the
|
`CanvasItem.visible`, then Godot would do the
|
||||||
following checks, in order:
|
following checks, in order:
|
||||||
|
|
||||||
- If the object has a script attached, it will attempt to set the property
|
- If the object has a script attached, it will attempt to set the property
|
||||||
@ -166,9 +166,9 @@ following checks, in order:
|
|||||||
is also the case with the ``_get_property_list`` method.
|
is also the case with the ``_get_property_list`` method.
|
||||||
|
|
||||||
- Note that this happens even for non-legal symbol names such as in the
|
- Note that this happens even for non-legal symbol names such as in the
|
||||||
case of `TileSet <class_TileSet>`'s "1/tile_name" property. This
|
case of `TileSet`'s "1/tile_name" property. This
|
||||||
refers to the name of the tile with ID 1, i.e.
|
refers to the name of the tile with ID 1, i.e.
|
||||||
`TileSet.tile_get_name(1) <class_TileSet_method_tile_get_name>`.
|
`TileSet.tile_get_name(1)`.
|
||||||
|
|
||||||
As a result, this duck-typed system can locate a property either in the script,
|
As a result, this duck-typed system can locate a property either in the script,
|
||||||
the object's class, or any class that object inherits, but only for things
|
the object's class, or any class that object inherits, but only for things
|
||||||
@ -199,7 +199,7 @@ gdscript GDScript
|
|||||||
```
|
```
|
||||||
|
|
||||||
- A method check. In the case of
|
- A method check. In the case of
|
||||||
`CanvasItem.visible <class_CanvasItem_property_visible>`, one can
|
`CanvasItem.visible`, one can
|
||||||
access the methods, ``set_visible`` and ``is_visible`` like any other method.
|
access the methods, ``set_visible`` and ``is_visible`` like any other method.
|
||||||
|
|
||||||
gdscript GDScript
|
gdscript GDScript
|
||||||
@ -262,7 +262,7 @@ gdscript GDScript
|
|||||||
# group can fill in for it.
|
# group can fill in for it.
|
||||||
```
|
```
|
||||||
|
|
||||||
- Outsource the access to a `FuncRef <class_FuncRef>`. These may be useful
|
- Outsource the access to a `FuncRef`. These may be useful
|
||||||
in cases where one needs the max level of freedom from dependencies. In
|
in cases where one needs the max level of freedom from dependencies. In
|
||||||
this case, one relies on an external context to setup the method.
|
this case, one relies on an external context to setup the method.
|
||||||
|
|
||||||
|
@ -4,10 +4,10 @@ Godot notifications
|
|||||||
===================
|
===================
|
||||||
|
|
||||||
Every Object in Godot implements a
|
Every Object in Godot implements a
|
||||||
`_notification <class_Object_method__notification>` method. Its purpose is to
|
`_notification` method. Its purpose is to
|
||||||
allow the Object to respond to a variety of engine-level callbacks that may
|
allow the Object to respond to a variety of engine-level callbacks that may
|
||||||
relate to it. For example, if the engine tells a
|
relate to it. For example, if the engine tells a
|
||||||
`CanvasItem <class_CanvasItem>` to "draw", it will call
|
`CanvasItem` to "draw", it will call
|
||||||
``_notification(NOTIFICATION_DRAW)``.
|
``_notification(NOTIFICATION_DRAW)``.
|
||||||
|
|
||||||
Some of these notifications, like draw, are useful to override in scripts. So
|
Some of these notifications, like draw, are useful to override in scripts. So
|
||||||
@ -28,28 +28,28 @@ much so that Godot exposes many of them with dedicated functions:
|
|||||||
What users might *not* realize is that notifications exist for types other
|
What users might *not* realize is that notifications exist for types other
|
||||||
than Node alone:
|
than Node alone:
|
||||||
|
|
||||||
- `Object::NOTIFICATION_POSTINITIALIZE <class_Object_constant_NOTIFICATION_POSTINITIALIZE>`:
|
- `Object::NOTIFICATION_POSTINITIALIZE`:
|
||||||
a callback that triggers during object initialization. Not accessible to scripts.
|
a callback that triggers during object initialization. Not accessible to scripts.
|
||||||
|
|
||||||
- `Object::NOTIFICATION_PREDELETE <class_Object_constant_NOTIFICATION_PREDELETE>`:
|
- `Object::NOTIFICATION_PREDELETE`:
|
||||||
a callback that triggers before the engine deletes an Object, i.e. a
|
a callback that triggers before the engine deletes an Object, i.e. a
|
||||||
'destructor'.
|
'destructor'.
|
||||||
|
|
||||||
- `MainLoop::NOTIFICATION_WM_MOUSE_ENTER <class_MainLoop_constant_NOTIFICATION_WM_MOUSE_ENTER>`:
|
- `MainLoop::NOTIFICATION_WM_MOUSE_ENTER`:
|
||||||
a callback that triggers when the mouse enters the window in the operating
|
a callback that triggers when the mouse enters the window in the operating
|
||||||
system that displays the game content.
|
system that displays the game content.
|
||||||
|
|
||||||
And many of the callbacks that *do* exist in Nodes don't have any dedicated
|
And many of the callbacks that *do* exist in Nodes don't have any dedicated
|
||||||
methods, but are still quite useful.
|
methods, but are still quite useful.
|
||||||
|
|
||||||
- `Node::NOTIFICATION_PARENTED <class_Node_constant_NOTIFICATION_PARENTED>`:
|
- `Node::NOTIFICATION_PARENTED`:
|
||||||
a callback that triggers anytime one adds a child node to another node.
|
a callback that triggers anytime one adds a child node to another node.
|
||||||
|
|
||||||
- `Node::NOTIFICATION_UNPARENTED <class_Node_constant_NOTIFICATION_UNPARENTED>`:
|
- `Node::NOTIFICATION_UNPARENTED`:
|
||||||
a callback that triggers anytime one removes a child node from another
|
a callback that triggers anytime one removes a child node from another
|
||||||
node.
|
node.
|
||||||
|
|
||||||
- `Popup::NOTIFICATION_POST_POPUP <class_Popup_constant_NOTIFICATION_POST_POPUP>`:
|
- `Popup::NOTIFICATION_POST_POPUP`:
|
||||||
a callback that triggers after a Popup node completes any ``popup*`` method.
|
a callback that triggers after a Popup node completes any ``popup*`` method.
|
||||||
Note the difference from its ``about_to_show`` signal which triggers
|
Note the difference from its ``about_to_show`` signal which triggers
|
||||||
*before* its appearance.
|
*before* its appearance.
|
||||||
@ -62,7 +62,7 @@ One can access all these custom notifications from the universal
|
|||||||
overridden by scripts.
|
overridden by scripts.
|
||||||
|
|
||||||
A classic example is the
|
A classic example is the
|
||||||
`_init <class_Object_method__init>` method in Object. While it has no
|
`_init` method in Object. While it has no
|
||||||
``NOTIFICATION_*`` equivalent, the engine still calls the method. Most languages
|
``NOTIFICATION_*`` equivalent, the engine still calls the method. Most languages
|
||||||
(except C#) rely on it as a constructor.
|
(except C#) rely on it as a constructor.
|
||||||
|
|
||||||
@ -186,7 +186,7 @@ to the SceneTree, the ``_enter_tree`` and ``_ready`` calls occur.
|
|||||||
|
|
||||||
If one needs to trigger behavior that occurs as nodes parent to another,
|
If one needs to trigger behavior that occurs as nodes parent to another,
|
||||||
regardless of whether it occurs as part of the main/active scene or not, one
|
regardless of whether it occurs as part of the main/active scene or not, one
|
||||||
can use the `PARENTED <class_Node_constant_NOTIFICATION_PARENTED>` notification.
|
can use the `PARENTED` notification.
|
||||||
For example, here is a snippet that connects a node's method to
|
For example, here is a snippet that connects a node's method to
|
||||||
a custom signal on the parent node without failing. Useful on data-centric
|
a custom signal on the parent node without failing. Useful on data-centric
|
||||||
nodes that one might create at runtime.
|
nodes that one might create at runtime.
|
||||||
|
@ -10,15 +10,15 @@ Loading vs. preloading
|
|||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
In GDScript, there exists the global
|
In GDScript, there exists the global
|
||||||
`preload <class_@GDScript_method_preload>` method. It loads resources as
|
`preload` method. It loads resources as
|
||||||
early as possible to front-load the "loading" operations and avoid loading
|
early as possible to front-load the "loading" operations and avoid loading
|
||||||
resources while in the middle of performance-sensitive code.
|
resources while in the middle of performance-sensitive code.
|
||||||
|
|
||||||
Its counterpart, the `load <class_@GDScript_method_load>` method, loads a
|
Its counterpart, the `load` method, loads a
|
||||||
resource only when it reaches the load statement. That is, it will load a
|
resource only when it reaches the load statement. That is, it will load a
|
||||||
resource in-place which can cause slowdowns when it occurs in the middle of
|
resource in-place which can cause slowdowns when it occurs in the middle of
|
||||||
sensitive processes. The ``load`` function is also an alias for
|
sensitive processes. The ``load`` function is also an alias for
|
||||||
`ResourceLoader.load(path) <class_ResourceLoader_method_load>` which is
|
`ResourceLoader.load(path)` which is
|
||||||
accessible to *all* scripting languages.
|
accessible to *all* scripting languages.
|
||||||
|
|
||||||
So, when exactly does preloading occur versus loading, and when should one use
|
So, when exactly does preloading occur versus loading, and when should one use
|
||||||
@ -95,7 +95,7 @@ consider:
|
|||||||
would be to unload the entire script. If they are instead loaded
|
would be to unload the entire script. If they are instead loaded
|
||||||
properties, then one can set them to ``null`` and remove all references
|
properties, then one can set them to ``null`` and remove all references
|
||||||
to the resource entirely (which, as a
|
to the resource entirely (which, as a
|
||||||
`Reference <class_Reference>`-extending type, will cause the
|
`Reference`-extending type, will cause the
|
||||||
resources to delete themselves from memory).
|
resources to delete themselves from memory).
|
||||||
|
|
||||||
Large levels: static vs. dynamic
|
Large levels: static vs. dynamic
|
||||||
|
@ -13,15 +13,15 @@ Godot provides more lightweight objects for creating APIs which nodes use.
|
|||||||
Be sure to keep these in mind as options when designing how you wish to build
|
Be sure to keep these in mind as options when designing how you wish to build
|
||||||
your project's features.
|
your project's features.
|
||||||
|
|
||||||
1. `Object <class_Object>`: The ultimate lightweight object, the original
|
1. `Object`: The ultimate lightweight object, the original
|
||||||
Object must use manual memory management. With that said, it isn't too
|
Object must use manual memory management. With that said, it isn't too
|
||||||
difficult to create one's own custom data structures, even node structures,
|
difficult to create one's own custom data structures, even node structures,
|
||||||
that are also lighter than the `Node <class_Node>` class.
|
that are also lighter than the `Node` class.
|
||||||
|
|
||||||
- **Example:** See the `Tree <class_Tree>` node. It supports a high level
|
- **Example:** See the `Tree` node. It supports a high level
|
||||||
of customization for a table of content with an arbitrary number of
|
of customization for a table of content with an arbitrary number of
|
||||||
rows and columns. The data that it uses to generate its visualization
|
rows and columns. The data that it uses to generate its visualization
|
||||||
though is actually a tree of `TreeItem <class_TreeItem>` Objects.
|
though is actually a tree of `TreeItem` Objects.
|
||||||
|
|
||||||
- **Advantages:** Simplifying one's API to smaller scoped objects helps improve
|
- **Advantages:** Simplifying one's API to smaller scoped objects helps improve
|
||||||
its accessibility and improve iteration time. Rather than working with the
|
its accessibility and improve iteration time. Rather than working with the
|
||||||
@ -33,27 +33,27 @@ your project's features.
|
|||||||
For example, if the object's creator decides to delete it out of nowhere,
|
For example, if the object's creator decides to delete it out of nowhere,
|
||||||
this would trigger an error state when one next accesses it.
|
this would trigger an error state when one next accesses it.
|
||||||
|
|
||||||
2. `Reference <class_Reference>`: Only a little more complex than Object.
|
2. `Reference`: Only a little more complex than Object.
|
||||||
They track references to themselves, only deleting loaded memory when no
|
They track references to themselves, only deleting loaded memory when no
|
||||||
further references to themselves exist. These are useful in the majority of
|
further references to themselves exist. These are useful in the majority of
|
||||||
cases where one needs data in a custom class.
|
cases where one needs data in a custom class.
|
||||||
|
|
||||||
- **Example:** See the `File <class_File>` object. It functions
|
- **Example:** See the `File` object. It functions
|
||||||
just like a regular Object except that one need not delete it themselves.
|
just like a regular Object except that one need not delete it themselves.
|
||||||
|
|
||||||
- **Advantages:** same as the Object.
|
- **Advantages:** same as the Object.
|
||||||
|
|
||||||
3. `Resource <class_Resource>`: Only slightly more complex than Reference.
|
3. `Resource`: Only slightly more complex than Reference.
|
||||||
They have the innate ability to serialize/deserialize (i.e. save and load)
|
They have the innate ability to serialize/deserialize (i.e. save and load)
|
||||||
their object properties to/from Godot resource files.
|
their object properties to/from Godot resource files.
|
||||||
|
|
||||||
- **Example:** Scripts, PackedScene (for scene files), and other types like
|
- **Example:** Scripts, PackedScene (for scene files), and other types like
|
||||||
each of the `AudioEffect <class_AudioEffect>` classes. Each of these
|
each of the `AudioEffect` classes. Each of these
|
||||||
can be save and loaded, therefore they extend from Resource.
|
can be save and loaded, therefore they extend from Resource.
|
||||||
|
|
||||||
- **Advantages:** Much has
|
- **Advantages:** Much has
|
||||||
`already been said <doc_resources>`
|
`already been said <doc_resources>`
|
||||||
on `Resource <class_Resource>`'s advantages over traditional data
|
on `Resource`'s advantages over traditional data
|
||||||
storage methods. In the context of using Resources over Nodes though,
|
storage methods. In the context of using Resources over Nodes though,
|
||||||
their main advantage is in Inspector-compatibility. While nearly as
|
their main advantage is in Inspector-compatibility. While nearly as
|
||||||
lightweight as Object/Reference, they can still display and export
|
lightweight as Object/Reference, they can still display and export
|
||||||
|
@ -75,7 +75,7 @@ gdscript GDScript
|
|||||||
call(method_name) # Call parent-defined method (which child must own).
|
call(method_name) # Call parent-defined method (which child must own).
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Initialize a `FuncRef <class_FuncRef>` property. Safer than a method
|
3. Initialize a `FuncRef` property. Safer than a method
|
||||||
as ownership of the method is unnecessary. Used to start behavior.
|
as ownership of the method is unnecessary. Used to start behavior.
|
||||||
|
|
||||||
gdscript GDScript
|
gdscript GDScript
|
||||||
@ -157,12 +157,12 @@ gdscript GDScript
|
|||||||
|
|
||||||
To avoid creating and maintaining such documentation, one converts the
|
To avoid creating and maintaining such documentation, one converts the
|
||||||
dependent node ("child" above) into a tool script that implements
|
dependent node ("child" above) into a tool script that implements
|
||||||
`_get_configuration_warning() <class_Node_method__get_configuration_warning>`.
|
`_get_configuration_warning()`.
|
||||||
Returning a non-empty string from it will make the Scene dock generate a
|
Returning a non-empty string from it will make the Scene dock generate a
|
||||||
warning icon with the string as a tooltip by the node. This is the same icon
|
warning icon with the string as a tooltip by the node. This is the same icon
|
||||||
that appears for nodes such as the
|
that appears for nodes such as the
|
||||||
`Area2D <class_Area2D>` node when it has no child
|
`Area2D` node when it has no child
|
||||||
`CollisionShape2D <class_CollisionShape2D>` nodes defined. The editor
|
`CollisionShape2D` nodes defined. The editor
|
||||||
then self-documents the scene through the script code. No content duplication
|
then self-documents the scene through the script code. No content duplication
|
||||||
via documentation is necessary.
|
via documentation is necessary.
|
||||||
|
|
||||||
@ -234,7 +234,7 @@ If one has a system that...
|
|||||||
|
|
||||||
For smaller games, a simpler alternative with less control would be to have
|
For smaller games, a simpler alternative with less control would be to have
|
||||||
a "Game" singleton that simply calls the
|
a "Game" singleton that simply calls the
|
||||||
`SceneTree.change_scene() <class_SceneTree_method_change_scene>` method
|
`SceneTree.change_scene()` method
|
||||||
to swap out the main scene's content. This structure more or less keeps
|
to swap out the main scene's content. This structure more or less keeps
|
||||||
the "World" as the main game node.
|
the "World" as the main game node.
|
||||||
|
|
||||||
@ -259,11 +259,11 @@ own place in the hierarchy as a sibling or some other relation.
|
|||||||
|
|
||||||
In some cases, one needs these separated nodes to *also* position themselves
|
In some cases, one needs these separated nodes to *also* position themselves
|
||||||
relative to each other. One can use the
|
relative to each other. One can use the
|
||||||
`RemoteTransform <class_RemoteTransform>` /
|
`RemoteTransform` /
|
||||||
`RemoteTransform2D <class_RemoteTransform2D>` nodes for this purpose.
|
`RemoteTransform2D` nodes for this purpose.
|
||||||
They will allow a target node to conditionally inherit selected transform
|
They will allow a target node to conditionally inherit selected transform
|
||||||
elements from the Remote\* node. To assign the ``target``
|
elements from the Remote\* node. To assign the ``target``
|
||||||
`NodePath <class_NodePath>`, use one of the following:
|
`NodePath`, use one of the following:
|
||||||
|
|
||||||
1. A reliable third party, likely a parent node, to mediate the assignment.
|
1. A reliable third party, likely a parent node, to mediate the assignment.
|
||||||
2. A group, to easily pull a reference to the desired node (assuming there
|
2. A group, to easily pull a reference to the desired node (assuming there
|
||||||
@ -307,12 +307,12 @@ own place in the hierarchy as a sibling or some other relation.
|
|||||||
In contrast, if one ever needs to have a child node that does *not* inherit
|
In contrast, if one ever needs to have a child node that does *not* inherit
|
||||||
the transform of their parent, one has the following options:
|
the transform of their parent, one has the following options:
|
||||||
|
|
||||||
1. The **declarative** solution: place a `Node <class_Node>` in between
|
1. The **declarative** solution: place a `Node` in between
|
||||||
them. As nodes with no transform, Nodes will not pass along such
|
them. As nodes with no transform, Nodes will not pass along such
|
||||||
information to their children.
|
information to their children.
|
||||||
2. The **imperative** solution: Use the ``set_as_toplevel`` setter for the
|
2. The **imperative** solution: Use the ``set_as_toplevel`` setter for the
|
||||||
`CanvasItem <class_CanvasItem_method_set_as_toplevel>` or
|
`CanvasItem` or
|
||||||
`Spatial <class_Spatial_method_set_as_toplevel>` node. This will make
|
`Spatial` node. This will make
|
||||||
the node ignore its inherited transform.
|
the node ignore its inherited transform.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
@ -88,7 +88,7 @@ There are two systems for registering types...
|
|||||||
|
|
||||||
- Works for all scripting languages because it deals with Script resources in abstract.
|
- Works for all scripting languages because it deals with Script resources in abstract.
|
||||||
|
|
||||||
- Set up using `EditorPlugin.add_custom_type <class_EditorPlugin_method_add_custom_type>`.
|
- Set up using `EditorPlugin.add_custom_type`.
|
||||||
|
|
||||||
- `Script Classes <doc_gdscript_basics_class_name>`
|
- `Script Classes <doc_gdscript_basics_class_name>`
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ how they work under the hood.
|
|||||||
How scripts work in the engine
|
How scripts work in the engine
|
||||||
------------------------------
|
------------------------------
|
||||||
|
|
||||||
The engine provides built-in classes like `Node <class_Node>`. You can extend those to create
|
The engine provides built-in classes like `Node`. You can extend those to create
|
||||||
derived types using a script.
|
derived types using a script.
|
||||||
|
|
||||||
These scripts are not technically classes. Instead, they are resources that tell the engine a
|
These scripts are not technically classes. Instead, they are resources that tell the engine a
|
||||||
@ -35,15 +35,15 @@ This ``ClassDB`` is what objects check against when performing an operation like
|
|||||||
property or calling a method. It checks the database's records and the object's base types' records
|
property or calling a method. It checks the database's records and the object's base types' records
|
||||||
to see if the object supports the operation.
|
to see if the object supports the operation.
|
||||||
|
|
||||||
Attaching a `Script <class_Script>` to your object extends the methods, properties, and signals
|
Attaching a `Script` to your object extends the methods, properties, and signals
|
||||||
available from the ``ClassDB``.
|
available from the ``ClassDB``.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
Even scripts that don't use the ``extends`` keyword implicitly inherit from the engine's base
|
Even scripts that don't use the ``extends`` keyword implicitly inherit from the engine's base
|
||||||
`Reference <class_Reference>` class. As a result, you can instantiate scripts without the
|
`Reference` class. As a result, you can instantiate scripts without the
|
||||||
``extends`` keyword from code. Since they extend ``Reference`` though, you cannot attach them to
|
``extends`` keyword from code. Since they extend ``Reference`` though, you cannot attach them to
|
||||||
a `Node <class_Node>`.
|
a `Node`.
|
||||||
|
|
||||||
Scenes
|
Scenes
|
||||||
------
|
------
|
||||||
|
@ -60,7 +60,7 @@ Command line reference
|
|||||||
+------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
+------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||||
| ``--main-pack <file>`` | Path to a pack (.pck) file to load. |
|
| ``--main-pack <file>`` | Path to a pack (.pck) file to load. |
|
||||||
+------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
+------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||||
| ``--render-thread <mode>`` | Render thread mode ('unsafe', 'safe', 'separate'). See `Thread Model <class_ProjectSettings_property_rendering/threads/thread_model>` for more details. |
|
| ``--render-thread <mode>`` | Render thread mode ('unsafe', 'safe', 'separate'). See `Thread Model` for more details. |
|
||||||
+------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
+------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||||
| ``--remote-fs <address>`` | Remote filesystem (``<host/IP>[:<port>]`` address). |
|
| ``--remote-fs <address>`` | Remote filesystem (``<host/IP>[:<port>]`` address). |
|
||||||
+------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
+------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||||
|
@ -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
|
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
|
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
|
executable to export a PCK file from the command line with
|
||||||
`OS.execute() <class_OS_method_execute>`. The game itself shouldn't
|
`OS.execute()`. The game itself shouldn't
|
||||||
use a tool-build of the engine (for security), so it's best to keep
|
use a tool-build of the engine (for security), so it's best to keep
|
||||||
the modding tool and game separate.
|
the modding tool and game separate.
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ gdscript GDScript
|
|||||||
PCK file of this kind can fix the content of a previously loaded PCK.
|
PCK file of this kind can fix the content of a previously loaded PCK.
|
||||||
|
|
||||||
To opt out of this behavior, pass ``false`` as the second argument to
|
To opt out of this behavior, pass ``false`` as the second argument to
|
||||||
`ProjectSettings.load_resource_pack() <class_ProjectSettings_method_load_resource_pack>`.
|
`ProjectSettings.load_resource_pack()`.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
For a C# project, you need to build the DLL and place it in the project directory first.
|
For a C# project, you need to build the DLL and place it in the project directory first.
|
||||||
|
@ -130,7 +130,7 @@ After overriding, a new field is added for this specific configuration:
|
|||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
When using the
|
When using the
|
||||||
`project settings "override.cfg" functionality <class_ProjectSettings>`
|
`project settings "override.cfg" functionality`
|
||||||
(which is unrelated to feature tags), remember that feature tags still apply.
|
(which is unrelated to feature tags), remember that feature tags still apply.
|
||||||
Therefore, make sure to *also* override the setting with the desired feature
|
Therefore, make sure to *also* override the setting with the desired feature
|
||||||
tag(s) if you want them to override base project settings on all platforms
|
tag(s) if you want them to override base project settings on all platforms
|
||||||
|
@ -51,7 +51,7 @@ locale.
|
|||||||
Converting keys to text
|
Converting keys to text
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
Some controls, such as `Button <class_Button>` and `Label <class_Label>`,
|
Some controls, such as `Button`,
|
||||||
will automatically fetch a translation if their text matches a translation key.
|
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
|
For example, if a label's text is "MAIN_SCREEN_GREETING1" and that key exists
|
||||||
in the current translation, then the text will automatically be translated.
|
in the current translation, then the text will automatically be translated.
|
||||||
@ -80,7 +80,7 @@ For more complex UI nodes such as OptionButtons, you may have to use this instea
|
|||||||
option_button.get_popup().set_message_translation(false)
|
option_button.get_popup().set_message_translation(false)
|
||||||
option_button.get_popup().notification(NOTIFICATION_TRANSLATION_CHANGED)
|
option_button.get_popup().notification(NOTIFICATION_TRANSLATION_CHANGED)
|
||||||
|
|
||||||
In code, the `Object.tr() <class_Object_method_tr>`
|
In code, the `Object.tr()`
|
||||||
function can be used. This will just look up the text in the
|
function can be used. This will just look up the text in the
|
||||||
translations and convert it if found:
|
translations and convert it if found:
|
||||||
|
|
||||||
@ -95,14 +95,14 @@ Making controls resizable
|
|||||||
The same text in different languages can vary greatly in length. For
|
The same text in different languages can vary greatly in length. For
|
||||||
this, make sure to read the tutorial on `doc_size_and_anchors`, as
|
this, make sure to read the tutorial on `doc_size_and_anchors`, as
|
||||||
dynamically adjusting control sizes may help.
|
dynamically adjusting control sizes may help.
|
||||||
`Container <class_Container>` can be useful, as well as the text wrapping
|
`Container` can be useful, as well as the text wrapping
|
||||||
options available in `Label <class_Label>`.
|
options available in `Label`.
|
||||||
|
|
||||||
TranslationServer
|
TranslationServer
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
Godot has a server handling low-level translation management
|
Godot has a server handling low-level translation management
|
||||||
called the `TranslationServer <class_TranslationServer>`.
|
called the `TranslationServer`.
|
||||||
Translations can be added or removed during run-time;
|
Translations can be added or removed during run-time;
|
||||||
the current language can also be changed at run-time.
|
the current language can also be changed at run-time.
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ You can then run pybabel like so:
|
|||||||
pybabel extract -F babelrc -k text -k LineEdit/placeholder_text -k tr -o godot-l10n.pot .
|
pybabel extract -F babelrc -k text -k LineEdit/placeholder_text -k tr -o godot-l10n.pot .
|
||||||
|
|
||||||
Use the ``-k`` option to specify what needs to be extracted. In this case,
|
Use the ``-k`` option to specify what needs to be extracted. In this case,
|
||||||
arguments to `tr() <class_Object_method_tr>` will be translated, as well
|
arguments to `tr()` will be translated, as well
|
||||||
as properties named "text" (commonly used by Control nodes) and LineEdit's
|
as properties named "text" (commonly used by Control nodes) and LineEdit's
|
||||||
"placeholder_text" property.
|
"placeholder_text" property.
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ events for controller input in the first place.
|
|||||||
|
|
||||||
If you want controller buttons to send echo events, you will have to generate
|
If you want controller buttons to send echo events, you will have to generate
|
||||||
`class_InputEvent` objects by code and parse them using
|
`class_InputEvent` objects by code and parse them using
|
||||||
`Input.parse_input_event() <class_Input_method_parse_input_event>`
|
`Input.parse_input_event()`
|
||||||
at regular intervals. This can be accomplished
|
at regular intervals. This can be accomplished
|
||||||
with the help of a `class_Timer` node.
|
with the help of a `class_Timer` node.
|
||||||
|
|
||||||
@ -200,7 +200,7 @@ powershell Windows (powershell)
|
|||||||
|
|
||||||
To test mappings on non-desktop platforms or to distribute your project with
|
To test mappings on non-desktop platforms or to distribute your project with
|
||||||
additional controller mappings, you can add them by calling
|
additional controller mappings, you can add them by calling
|
||||||
`Input.add_joy_mapping() <class_Input_method_add_joy_mapping>`
|
`Input.add_joy_mapping()`
|
||||||
as early as possible in a script's ``_ready()`` function.
|
as early as possible in a script's ``_ready()`` function.
|
||||||
|
|
||||||
My controller works on a given platform, but not on another platform.
|
My controller works on a given platform, but not on another platform.
|
||||||
|
@ -59,7 +59,7 @@ gdscript GDScript
|
|||||||
```
|
```
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
Check `Input.set_custom_mouse_cursor() <class_Input_method_set_custom_mouse_cursor>`.
|
Check `Input.set_custom_mouse_cursor()`.
|
||||||
|
|
||||||
|
|
||||||
Demo project
|
Demo project
|
||||||
@ -71,4 +71,4 @@ https://github.com/guilhermefelipecgs/custom_hardware_cursor
|
|||||||
Cursor list
|
Cursor list
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
As documented in the `Input <class_Input>` class (see the **CursorShape** enum), there are multiple mouse cursors you can define. Which ones you want to use depends on your use case.
|
As documented in the `Input` class (see the **CursorShape** enum), there are multiple mouse cursors you can define. Which ones you want to use depends on your use case.
|
||||||
|
@ -14,7 +14,7 @@ to go back otherwise).
|
|||||||
Handling the notification
|
Handling the notification
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
On desktop platforms, the `MainLoop <class_MainLoop>`
|
On desktop platforms, the `MainLoop`
|
||||||
has a special ``MainLoop.NOTIFICATION_WM_QUIT_REQUEST`` notification that is
|
has a special ``MainLoop.NOTIFICATION_WM_QUIT_REQUEST`` notification that is
|
||||||
sent to all nodes when quitting is requested.
|
sent to all nodes when quitting is requested.
|
||||||
|
|
||||||
@ -53,10 +53,10 @@ gdscript GDScript
|
|||||||
Sending your own quit notification
|
Sending your own quit notification
|
||||||
----------------------------------
|
----------------------------------
|
||||||
|
|
||||||
While forcing the application to close can be done by calling `SceneTree.quit <class_SceneTree_method_quit>`,
|
While forcing the application to close can be done by calling `SceneTree.quit`,
|
||||||
doing so will not send the quit *notification*. This means the function
|
doing so will not send the quit *notification*. This means the function
|
||||||
described above won't be called. Quitting by calling
|
described above won't be called. Quitting by calling
|
||||||
`SceneTree.quit <class_SceneTree_method_quit>` will not allow custom actions
|
`SceneTree.quit` will not allow custom actions
|
||||||
to complete (such as saving, confirming the quit, or debugging), even if you try
|
to complete (such as saving, confirming the quit, or debugging), even if you try
|
||||||
to delay the line that forces the quit.
|
to delay the line that forces the quit.
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ Input examples
|
|||||||
Introduction
|
Introduction
|
||||||
------------
|
------------
|
||||||
|
|
||||||
In this tutorial, you'll learn how to use Godot's `InputEvent <class_InputEvent>`
|
In this tutorial, you'll learn how to use Godot's `InputEvent`
|
||||||
system to capture player input. There are many different types of input your
|
system to capture player input. There are many different types of input your
|
||||||
game may use - keyboard, gamepad, mouse, etc. - and many different ways to
|
game may use - keyboard, gamepad, mouse, etc. - and many different ways to
|
||||||
turn those inputs into actions in your game. This document will show you some
|
turn those inputs into actions in your game. This document will show you some
|
||||||
@ -23,7 +23,7 @@ Sometimes you want your game to respond to a certain input event - pressing
|
|||||||
the "jump" button, for example. For other situations, you might want something
|
the "jump" button, for example. For other situations, you might want something
|
||||||
to happen as long as a key is pressed, such as movement. In the first case,
|
to happen as long as a key is pressed, such as movement. In the first case,
|
||||||
you can use the ``_input()`` function, which will be called whenever an input
|
you can use the ``_input()`` function, which will be called whenever an input
|
||||||
event occurs. In the second case, Godot provides the `Input <class_Input>`
|
event occurs. In the second case, Godot provides the `Input`
|
||||||
singleton, which you can use to query the state of an input.
|
singleton, which you can use to query the state of an input.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
@ -51,7 +51,7 @@ events in ``_input()``.
|
|||||||
Input events
|
Input events
|
||||||
------------
|
------------
|
||||||
|
|
||||||
Input events are objects that inherit from `InputEvent <class_InputEvent>`.
|
Input events are objects that inherit from `InputEvent`.
|
||||||
Depending on the event type, the object will contain specific properties
|
Depending on the event type, the object will contain specific properties
|
||||||
related to that event. To see what events actually look like, add a Node and
|
related to that event. To see what events actually look like, add a Node and
|
||||||
attach the following script:
|
attach the following script:
|
||||||
@ -82,13 +82,13 @@ event scroll by in the output window. Here's an example of the output:
|
|||||||
|
|
||||||
As you can see, the results are very different for the different types of
|
As you can see, the results are very different for the different types of
|
||||||
input. Key events are even printed as their key symbols. For example, let's
|
input. Key events are even printed as their key symbols. For example, let's
|
||||||
consider `InputEventMouseButton <class_InputEventMouseButton>`.
|
consider `InputEventMouseButton`.
|
||||||
It inherits from the following classes:
|
It inherits from the following classes:
|
||||||
|
|
||||||
- `InputEvent <class_InputEvent>` - the base class for all input events
|
- `InputEvent` - the base class for all input events
|
||||||
- `InputEventWithModifiers <class_InputEventWithModifiers>` - adds the ability to check if modifiers are pressed, such as :kbd:`Shift` or :kbd:`Alt`.
|
- `InputEventWithModifiers` - adds the ability to check if modifiers are pressed, such as :kbd:`Shift` or :kbd:`Alt`.
|
||||||
- `InputEventMouse <class_InputEventMouse>` - adds mouse event properties, such as ``position``
|
- `InputEventMouse` - adds mouse event properties, such as ``position``
|
||||||
- `InputEventMouseButton <class_InputEventMouseButton>` - contains the index of the button that was pressed, whether it was a double-click, etc.
|
- `InputEventMouseButton` - contains the index of the button that was pressed, whether it was a double-click, etc.
|
||||||
|
|
||||||
.. tip:: It's a good idea to keep the class reference open while you're working
|
.. tip:: It's a good idea to keep the class reference open while you're working
|
||||||
with events so you can check the event type's available properties and
|
with events so you can check the event type's available properties and
|
||||||
@ -109,7 +109,7 @@ gdscript GDScript
|
|||||||
InputMap
|
InputMap
|
||||||
--------
|
--------
|
||||||
|
|
||||||
The `InputMap <class_InputMap>` is the most flexible way to handle a
|
The `InputMap` is the most flexible way to handle a
|
||||||
variety of inputs. You use this by creating named input *actions*, to which
|
variety of inputs. You use this by creating named input *actions*, to which
|
||||||
you can assign any number of input events, such as keypresses or mouse clicks.
|
you can assign any number of input events, such as keypresses or mouse clicks.
|
||||||
A new Godot project includes a number of default actions already defined. To
|
A new Godot project includes a number of default actions already defined. To
|
||||||
@ -136,7 +136,7 @@ gdscript GDScript
|
|||||||
Keyboard events
|
Keyboard events
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
Keyboard events are captured in `InputEventKey <class_InputEventKey>`.
|
Keyboard events are captured in `InputEventKey`.
|
||||||
While it's recommended to use input actions instead, there may be cases where
|
While it's recommended to use input actions instead, there may be cases where
|
||||||
you want to specifically look at key events. For this example, let's check for
|
you want to specifically look at key events. For this example, let's check for
|
||||||
the :kbd:`T`:
|
the :kbd:`T`:
|
||||||
@ -170,7 +170,7 @@ Keyboard modifiers
|
|||||||
~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
Modifier properties are inherited from
|
Modifier properties are inherited from
|
||||||
`InputEventWithModifiers <class_InputEventWithModifiers>`. This allows
|
`InputEventWithModifiers`. This allows
|
||||||
you to check for modifier combinations using boolean properties. Let's imagine
|
you to check for modifier combinations using boolean properties. Let's imagine
|
||||||
you want one thing to happen when the :kbd:`T` is pressed, but something
|
you want one thing to happen when the :kbd:`T` is pressed, but something
|
||||||
different when it's :kbd:`Shift + T`:
|
different when it's :kbd:`Shift + T`:
|
||||||
@ -193,9 +193,9 @@ gdscript GDScript
|
|||||||
Mouse events
|
Mouse events
|
||||||
------------
|
------------
|
||||||
|
|
||||||
Mouse events stem from the `InputEventMouse <class_InputEventMouse>` class, and
|
Mouse events stem from the `InputEventMouse` class, and
|
||||||
are separated into two types: `InputEventMouseButton <class_InputEventMouseButton>`
|
are separated into two types: `InputEventMouseButton`
|
||||||
and `InputEventMouseMotion <class_InputEventMouseMotion>`. Note that this
|
and `InputEventMouseMotion`. Note that this
|
||||||
means that all mouse events will contain a ``position`` property.
|
means that all mouse events will contain a ``position`` property.
|
||||||
|
|
||||||
Mouse buttons
|
Mouse buttons
|
||||||
@ -221,11 +221,11 @@ gdscript GDScript
|
|||||||
Mouse motion
|
Mouse motion
|
||||||
~~~~~~~~~~~~
|
~~~~~~~~~~~~
|
||||||
|
|
||||||
`InputEventMouseMotion <class_InputEventMouseMotion>` events occur whenever
|
`InputEventMouseMotion` events occur whenever
|
||||||
the mouse moves. You can find the move's distance with the ``relative``
|
the mouse moves. You can find the move's distance with the ``relative``
|
||||||
property.
|
property.
|
||||||
|
|
||||||
Here's an example using mouse events to drag-and-drop a `Sprite <class_Sprite>`
|
Here's an example using mouse events to drag-and-drop a `Sprite`
|
||||||
node:
|
node:
|
||||||
|
|
||||||
gdscript GDScript
|
gdscript GDScript
|
||||||
@ -257,8 +257,8 @@ Touch events
|
|||||||
------------
|
------------
|
||||||
|
|
||||||
If you are using a touchscreen device, you can generate touch events.
|
If you are using a touchscreen device, you can generate touch events.
|
||||||
`InputEventScreenTouch <class_InputEventScreenTouch>` is equivalent to
|
`InputEventScreenTouch` is equivalent to
|
||||||
a mouse click event, and `InputEventScreenDrag <class_InputEventScreenDrag>`
|
a mouse click event, and `InputEventScreenDrag`
|
||||||
works much the same as mouse motion.
|
works much the same as mouse motion.
|
||||||
|
|
||||||
.. tip:: To test your touch events on a non-touchscreen device, open Project
|
.. tip:: To test your touch events on a non-touchscreen device, open Project
|
||||||
|
@ -7,7 +7,7 @@ What is it?
|
|||||||
-----------
|
-----------
|
||||||
|
|
||||||
Managing input is usually complex, no matter the OS or platform. To ease
|
Managing input is usually complex, no matter the OS or platform. To ease
|
||||||
this a little, a special built-in type is provided, `InputEvent <class_InputEvent>`.
|
this a little, a special built-in type is provided, `InputEvent`.
|
||||||
This datatype can be configured to contain several types of input
|
This datatype can be configured to contain several types of input
|
||||||
events. Input events travel through the engine and can be received in
|
events. Input events travel through the engine and can be received in
|
||||||
multiple locations, depending on the purpose.
|
multiple locations, depending on the purpose.
|
||||||
@ -23,7 +23,7 @@ gdscript GDScript
|
|||||||
get_tree().quit()
|
get_tree().quit()
|
||||||
```
|
```
|
||||||
|
|
||||||
However, it is cleaner and more flexible to use the provided `InputMap <class_InputMap>` feature,
|
However, it is cleaner and more flexible to use the provided `InputMap` feature,
|
||||||
which allows you to define input actions and assign them different keys. This way,
|
which allows you to define input actions and assign them different keys. This way,
|
||||||
you can define multiple keys for the same action (e.g. the keyboard escape key and the start button on a gamepad).
|
you can define multiple keys for the same action (e.g. the keyboard escape key and the start button on a gamepad).
|
||||||
You can then more easily change this mapping in the project settings without updating your code,
|
You can then more easily change this mapping in the project settings without updating your code,
|
||||||
@ -45,44 +45,44 @@ How does it work?
|
|||||||
Every input event is originated from the user/player (though it's
|
Every input event is originated from the user/player (though it's
|
||||||
possible to generate an InputEvent and feed them back to the engine,
|
possible to generate an InputEvent and feed them back to the engine,
|
||||||
which is useful for gestures). The OS object for each platform will read
|
which is useful for gestures). The OS object for each platform will read
|
||||||
events from the device, then feed them to MainLoop. As `SceneTree <class_SceneTree>`
|
events from the device, then feed them to MainLoop. As `SceneTree`
|
||||||
is the default MainLoop implementation, events are fed to it. Godot
|
is the default MainLoop implementation, events are fed to it. Godot
|
||||||
provides a function to get the current SceneTree object :
|
provides a function to get the current SceneTree object :
|
||||||
**get_tree()**.
|
**get_tree()**.
|
||||||
|
|
||||||
But SceneTree does not know what to do with the event, so it will give
|
But SceneTree does not know what to do with the event, so it will give
|
||||||
it to the viewports, starting by the "root" `Viewport <class_Viewport>` (the first
|
it to the viewports, starting by the "root" `Viewport` (the first
|
||||||
node of the scene tree). Viewport does quite a lot of stuff with the
|
node of the scene tree). Viewport does quite a lot of stuff with the
|
||||||
received input, in order:
|
received input, in order:
|
||||||
|
|
||||||
.. image:: img/input_event_flow.png
|
.. image:: img/input_event_flow.png
|
||||||
|
|
||||||
1. First of all, the standard `Node._input() <class_Node_method__input>` function
|
1. First of all, the standard `Node._input()` function
|
||||||
will be called in any node that overrides it (and hasn't disabled input processing with `Node.set_process_input() <class_Node_method_set_process_input>`).
|
will be called in any node that overrides it (and hasn't disabled input processing with `Node.set_process_input()`).
|
||||||
If any function consumes the event, it can call `SceneTree.set_input_as_handled() <class_SceneTree_method_set_input_as_handled>`, and the event will
|
If any function consumes the event, it can call `SceneTree.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.
|
not spread any more. This ensures that you can filter all events of interest, even before the GUI.
|
||||||
For gameplay input, `Node._unhandled_input() <class_Node_method__unhandled_input>` is generally a better fit, because it allows the GUI to intercept the events.
|
For gameplay input, `Node._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
|
2. Second, it will try to feed the input to the GUI, and see if any
|
||||||
control can receive it. If so, the `Control <class_Control>` will be called via the
|
control can receive it. If so, the `Control` will be called via the
|
||||||
virtual function `Control._gui_input() <class_Control_method__gui_input>` and the signal
|
virtual function `Control._gui_input()` and the signal
|
||||||
"gui_input" will be emitted (this function is re-implementable by
|
"gui_input" will be emitted (this function is re-implementable by
|
||||||
script by inheriting from it). If the control wants to "consume" the
|
script by inheriting from it). If the control wants to "consume" the
|
||||||
event, it will call `Control.accept_event() <class_Control_method_accept_event>` and the event will
|
event, it will call `Control.accept_event()` and the event will
|
||||||
not spread any more. Use the `Control.mouse_filter <class_Control_property_mouse_filter>`
|
not spread any more. Use the `Control.mouse_filter`
|
||||||
property to control whether a `Control <class_Control>` is notified
|
property to control whether a `Control` is notified
|
||||||
of mouse events via `Control._gui_input() <class_Control_method__gui_input>`
|
of mouse events via `Control._gui_input()`
|
||||||
callback, and whether these events are propagated further.
|
callback, and whether these events are propagated further.
|
||||||
3. If so far no one consumed the event, the unhandled input callback
|
3. If so far no one consumed the event, the unhandled input callback
|
||||||
will be called if overridden (and not disabled with
|
will be called if overridden (and not disabled with
|
||||||
`Node.set_process_unhandled_input() <class_Node_method_set_process_unhandled_input>`).
|
`Node.set_process_unhandled_input()`).
|
||||||
If any function consumes the event, it can call `SceneTree.set_input_as_handled() <class_SceneTree_method_set_input_as_handled>`, and the
|
If any function consumes the event, it can call `SceneTree.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.
|
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 `Camera <class_Camera>` is assigned
|
4. If no one wanted the event so far, and a `Camera` is assigned
|
||||||
to the Viewport with `Object Picking <class_viewport_property_physics_object_picking>` turned on, a ray to the physics world (in the ray direction from
|
to the Viewport with `Object Picking` turned on, a ray to the physics world (in the ray direction from
|
||||||
the click) will be cast. (For the root viewport, this can also be enabled in `Project Settings <class_ProjectSettings_property_physics/common/enable_object_picking>`) If this ray hits an object, it will call the
|
the click) will be cast. (For the root viewport, this can also be enabled in `Project Settings`) If this ray hits an object, it will call the
|
||||||
`CollisionObject._input_event() <class_CollisionObject_method__input_event>` function in the relevant
|
`CollisionObject._input_event()` function in the relevant
|
||||||
physics object (bodies receive this callback by default, but areas do
|
physics object (bodies receive this callback by default, but areas do
|
||||||
not. This can be configured through `Area <class_Area>` properties).
|
not. This can be configured through `Area` properties).
|
||||||
5. Finally, if the event was unhandled, it will be passed to the next
|
5. Finally, if the event was unhandled, it will be passed to the next
|
||||||
Viewport in the tree, otherwise it will be ignored.
|
Viewport in the tree, otherwise it will be ignored.
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ generalized behavior if needed.
|
|||||||
Anatomy of an InputEvent
|
Anatomy of an InputEvent
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
`InputEvent <class_InputEvent>` is just a base built-in type, it does not represent
|
`InputEvent` is just a base built-in type, it does not represent
|
||||||
anything and only contains some basic information, such as event ID
|
anything and only contains some basic information, such as event ID
|
||||||
(which is increased for each event), device index, etc.
|
(which is increased for each event), device index, etc.
|
||||||
|
|
||||||
@ -112,31 +112,31 @@ There are several specialized types of InputEvent, described in the table below:
|
|||||||
+-------------------------------------------------------------------+--------------------+-----------------------------------------+
|
+-------------------------------------------------------------------+--------------------+-----------------------------------------+
|
||||||
| Event | Type Index | Description |
|
| Event | Type Index | Description |
|
||||||
+-------------------------------------------------------------------+--------------------+-----------------------------------------+
|
+-------------------------------------------------------------------+--------------------+-----------------------------------------+
|
||||||
| `InputEvent <class_InputEvent>` | NONE | Empty Input Event. |
|
| `InputEvent` | NONE | Empty Input Event. |
|
||||||
+-------------------------------------------------------------------+--------------------+-----------------------------------------+
|
+-------------------------------------------------------------------+--------------------+-----------------------------------------+
|
||||||
| `InputEventKey <class_InputEventKey>` | KEY | Contains a scancode and Unicode value, |
|
| `InputEventKey` | KEY | Contains a scancode and Unicode value, |
|
||||||
| | | as well as modifiers. |
|
| | | as well as modifiers. |
|
||||||
+-------------------------------------------------------------------+--------------------+-----------------------------------------+
|
+-------------------------------------------------------------------+--------------------+-----------------------------------------+
|
||||||
| `InputEventMouseButton <class_InputEventMouseButton>` | MOUSE_BUTTON | Contains click information, such as |
|
| `InputEventMouseButton` | MOUSE_BUTTON | Contains click information, such as |
|
||||||
| | | button, modifiers, etc. |
|
| | | button, modifiers, etc. |
|
||||||
+-------------------------------------------------------------------+--------------------+-----------------------------------------+
|
+-------------------------------------------------------------------+--------------------+-----------------------------------------+
|
||||||
| `InputEventMouseMotion <class_InputEventMouseMotion>` | MOUSE_MOTION | Contains motion information, such as |
|
| `InputEventMouseMotion` | MOUSE_MOTION | Contains motion information, such as |
|
||||||
| | | relative, absolute positions and speed. |
|
| | | relative, absolute positions and speed. |
|
||||||
+-------------------------------------------------------------------+--------------------+-----------------------------------------+
|
+-------------------------------------------------------------------+--------------------+-----------------------------------------+
|
||||||
| `InputEventJoypadMotion <class_InputEventJoypadMotion>` | JOYSTICK_MOTION | Contains Joystick/Joypad analog axis |
|
| `InputEventJoypadMotion` | JOYSTICK_MOTION | Contains Joystick/Joypad analog axis |
|
||||||
| | | information. |
|
| | | information. |
|
||||||
+-------------------------------------------------------------------+--------------------+-----------------------------------------+
|
+-------------------------------------------------------------------+--------------------+-----------------------------------------+
|
||||||
| `InputEventJoypadButton <class_InputEventJoypadButton>` | JOYSTICK_BUTTON | Contains Joystick/Joypad button |
|
| `InputEventJoypadButton` | JOYSTICK_BUTTON | Contains Joystick/Joypad button |
|
||||||
| | | information. |
|
| | | information. |
|
||||||
+-------------------------------------------------------------------+--------------------+-----------------------------------------+
|
+-------------------------------------------------------------------+--------------------+-----------------------------------------+
|
||||||
| `InputEventScreenTouch <class_InputEventScreenTouch>` | SCREEN_TOUCH | Contains multi-touch press/release |
|
| `InputEventScreenTouch` | SCREEN_TOUCH | Contains multi-touch press/release |
|
||||||
| | | information. (only available on mobile |
|
| | | information. (only available on mobile |
|
||||||
| | | devices) |
|
| | | devices) |
|
||||||
+-------------------------------------------------------------------+--------------------+-----------------------------------------+
|
+-------------------------------------------------------------------+--------------------+-----------------------------------------+
|
||||||
| `InputEventScreenDrag <class_InputEventScreenDrag>` | SCREEN_DRAG | Contains multi-touch drag information. |
|
| `InputEventScreenDrag` | SCREEN_DRAG | Contains multi-touch drag information. |
|
||||||
| | | (only available on mobile devices) |
|
| | | (only available on mobile devices) |
|
||||||
+-------------------------------------------------------------------+--------------------+-----------------------------------------+
|
+-------------------------------------------------------------------+--------------------+-----------------------------------------+
|
||||||
| `InputEventAction <class_InputEventAction>` | SCREEN_ACTION | Contains a generic action. These events |
|
| `InputEventAction` | SCREEN_ACTION | Contains a generic action. These events |
|
||||||
| | | are often generated by the programmer |
|
| | | are often generated by the programmer |
|
||||||
| | | as feedback. (more on this below) |
|
| | | as feedback. (more on this below) |
|
||||||
+-------------------------------------------------------------------+--------------------+-----------------------------------------+
|
+-------------------------------------------------------------------+--------------------+-----------------------------------------+
|
||||||
@ -155,13 +155,13 @@ logic. This allows for:
|
|||||||
Actions can be created from the Project Settings menu in the Actions
|
Actions can be created from the Project Settings menu in the Actions
|
||||||
tab.
|
tab.
|
||||||
|
|
||||||
Any event has the methods `InputEvent.is_action() <class_InputEvent_method_is_action>`,
|
Any event has the methods `InputEvent.is_action()`,
|
||||||
`InputEvent.is_pressed() <class_InputEvent_method_is_pressed>` and `InputEvent <class_InputEvent>`.
|
`InputEvent.is_pressed()`.
|
||||||
|
|
||||||
Alternatively, it may be desired to supply the game back with an action
|
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).
|
from the game code (a good example of this is detecting gestures).
|
||||||
The Input singleton has a method for this:
|
The Input singleton has a method for this:
|
||||||
`Input.parse_input_event() <class_input_method_parse_input_event>`. You would normally use it like this:
|
`Input.parse_input_event()`. You would normally use it like this:
|
||||||
|
|
||||||
gdscript GDScript
|
gdscript GDScript
|
||||||
|
|
||||||
@ -178,7 +178,7 @@ InputMap
|
|||||||
--------
|
--------
|
||||||
|
|
||||||
Customizing and re-mapping input from code is often desired. If your
|
Customizing and re-mapping input from code is often desired. If your
|
||||||
whole workflow depends on actions, the `InputMap <class_InputMap>` singleton is
|
whole workflow depends on actions, the `InputMap` singleton is
|
||||||
ideal for reassigning or creating different actions at run-time. This
|
ideal for reassigning or creating different actions at run-time. This
|
||||||
singleton is not saved (must be modified manually) and its state is run
|
singleton is not saved (must be modified manually) and its state is run
|
||||||
from the project settings (project.godot). So any dynamic system of this
|
from the project settings (project.godot). So any dynamic system of this
|
||||||
|
@ -55,14 +55,14 @@ Project Settings:
|
|||||||
`editor data path <doc_data_paths_editor_data_paths>` in the
|
`editor data path <doc_data_paths_editor_data_paths>` in the
|
||||||
``app_userdata/[project_name]`` folder. This is the default so that prototypes
|
``app_userdata/[project_name]`` folder. This is the default so that prototypes
|
||||||
and test projects stay self-contained within Godot's data folder.
|
and test projects stay self-contained within Godot's data folder.
|
||||||
- If `application/config/use_custom_user_dir <class_ProjectSettings_property_application/config/use_custom_user_dir>`
|
- If `application/config/use_custom_user_dir`
|
||||||
is enabled in the Project Settings, the ``user://`` folder is created **next
|
is enabled in the Project Settings, the ``user://`` folder is created **next
|
||||||
to** Godot's editor data path, i.e. in the standard location for applications
|
to** Godot's editor data path, i.e. in the standard location for applications
|
||||||
data.
|
data.
|
||||||
|
|
||||||
* By default, the folder name will be inferred from the project name, but it
|
* By default, the folder name will be inferred from the project name, but it
|
||||||
can be further customized with
|
can be further customized with
|
||||||
`application/config/custom_user_dir_name <class_ProjectSettings_property_application/config/custom_user_dir_name>`.
|
`application/config/custom_user_dir_name`.
|
||||||
This path can contain path separators, so you can use it e.g. to group
|
This path can contain path separators, so you can use it e.g. to group
|
||||||
projects of a given studio with a ``Studio Name/Game Name`` structure.
|
projects of a given studio with a ``Studio Name/Game Name`` structure.
|
||||||
|
|
||||||
@ -92,20 +92,20 @@ by other applications for security reasons.
|
|||||||
|
|
||||||
On HTML5 exports, ``user://`` will refer to a virtual filesystem stored on the
|
On HTML5 exports, ``user://`` will refer to a virtual filesystem stored on the
|
||||||
device via IndexedDB. (Interaction with the main filesystem can still be performed
|
device via IndexedDB. (Interaction with the main filesystem can still be performed
|
||||||
through the `JavaScript <class_JavaScript>` singleton.)
|
through the `JavaScript` singleton.)
|
||||||
|
|
||||||
Converting paths to absolute paths or "local" paths
|
Converting paths to absolute paths or "local" paths
|
||||||
---------------------------------------------------
|
---------------------------------------------------
|
||||||
|
|
||||||
You can use `ProjectSettings.globalize_path() <class_ProjectSettings_method_globalize_path>`
|
You can use `ProjectSettings.globalize_path()`
|
||||||
to convert a "local" path like ``res://path/to/file.txt`` to an absolute OS path.
|
to convert a "local" path like ``res://path/to/file.txt`` to an absolute OS path.
|
||||||
For example, `ProjectSettings.globalize_path() <class_ProjectSettings_method_globalize_path>`
|
For example, `ProjectSettings.globalize_path()`
|
||||||
can be used to open "local" paths in the OS file manager
|
can be used to open "local" paths in the OS file manager
|
||||||
using `OS.shell_open() <class_OS_method_shell_open>` since it only accepts
|
using `OS.shell_open()` since it only accepts
|
||||||
native OS paths.
|
native OS paths.
|
||||||
|
|
||||||
To convert an absolute OS path to a "local" path starting with ``res://``
|
To convert an absolute OS path to a "local" path starting with ``res://``
|
||||||
or ``user://``, use `ProjectSettings.localize_path() <class_ProjectSettings_method_localize_path>`.
|
or ``user://``, use `ProjectSettings.localize_path()`.
|
||||||
This only works for absolute paths that point to files or folders in your
|
This only works for absolute paths that point to files or folders in your
|
||||||
project's root or ``user://`` folders.
|
project's root or ``user://`` folders.
|
||||||
|
|
||||||
@ -169,7 +169,7 @@ self-contained mode by default.
|
|||||||
|
|
||||||
Self-contained mode is not supported in exported projects yet.
|
Self-contained mode is not supported in exported projects yet.
|
||||||
To read and write files relative to the executable path, use
|
To read and write files relative to the executable path, use
|
||||||
`OS.get_executable_path() <class_OS_method_get_executable_path>`.
|
`OS.get_executable_path()`.
|
||||||
Note that writing files in the executable path only works if the executable
|
Note that writing files in the executable path only works if the executable
|
||||||
is placed in a writable location (i.e. **not** Program Files or another
|
is placed in a writable location (i.e. **not** Program Files or another
|
||||||
directory that is read-only for regular users).
|
directory that is read-only for regular users).
|
||||||
|
@ -147,9 +147,9 @@ work and look in Godot.
|
|||||||
Curve2D, Curve3D, Path and Path2D
|
Curve2D, Curve3D, Path and Path2D
|
||||||
---------------------------------
|
---------------------------------
|
||||||
|
|
||||||
There are two objects that contain curves: `Curve3D <class_Curve3D>` and `Curve2D <class_Curve2D>` (for 3D and 2D respectively).
|
There are two objects that contain curves: `Curve3D` (for 3D and 2D respectively).
|
||||||
|
|
||||||
They can contain several points, allowing for longer paths. It is also possible to set them to nodes: `Path <class_Path>` and `Path2D <class_Path2D>` (also for 3D and 2D respectively):
|
They can contain several points, allowing for longer paths. It is also possible to set them to nodes: `Path` (also for 3D and 2D respectively):
|
||||||
|
|
||||||
.. image:: img/bezier_path_2d.png
|
.. image:: img/bezier_path_2d.png
|
||||||
|
|
||||||
@ -190,7 +190,7 @@ Additionally, if both control points were ``0, 0`` (remember they are relative v
|
|||||||
Before drawing Bezier curves, *tessellation* is required. This is often done with a recursive or divide and conquer function that splits the curve until the curvature amount becomes less than a certain threshold.
|
Before drawing Bezier curves, *tessellation* is required. This is often done with a recursive or divide and conquer function that splits the curve until the curvature amount becomes less than a certain threshold.
|
||||||
|
|
||||||
The *Curve* classes provide this via the
|
The *Curve* classes provide this via the
|
||||||
`Curve2D.tessellate() <class_Curve2D_method_tessellate>` function (which receives optional ``stages`` of recursion and angle ``tolerance`` arguments). This way, drawing something based on a curve is easier.
|
`Curve2D.tessellate()` function (which receives optional ``stages`` of recursion and angle ``tolerance`` arguments). This way, drawing something based on a curve is easier.
|
||||||
|
|
||||||
Traversal
|
Traversal
|
||||||
---------
|
---------
|
||||||
|
@ -28,10 +28,10 @@ There are other types of interpolations, which will not be covered here. A recom
|
|||||||
Vector interpolation
|
Vector interpolation
|
||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
Vector types (`Vector2 <class_Vector2>` and `Vector3 <class_Vector3>`) can also be interpolated, they come with handy functions to do it
|
Vector types (`Vector2`) can also be interpolated, they come with handy functions to do it
|
||||||
`Vector2.linear_interpolate() <class_Vector2_method_linear_interpolate>` and `Vector3.linear_interpolate() <class_Vector3_method_linear_interpolate>`.
|
`Vector2.linear_interpolate()`.
|
||||||
|
|
||||||
For cubic interpolation, there are also `Vector2.cubic_interpolate() <class_Vector2_method_cubic_interpolate>` and `Vector3.cubic_interpolate() <class_Vector3_method_cubic_interpolate>`, which do a `Bezier <doc_beziers_and_curves>` style interpolation.
|
For cubic interpolation, there are also `Vector2.cubic_interpolate()` style interpolation.
|
||||||
|
|
||||||
Here is simple pseudo-code for going from point A to B using interpolation:
|
Here is simple pseudo-code for going from point A to B using interpolation:
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ Transform interpolation
|
|||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
It is also possible to interpolate whole transforms (make sure they have either uniform scale or, at least, the same non-uniform scale).
|
It is also possible to interpolate whole transforms (make sure they have either uniform scale or, at least, the same non-uniform scale).
|
||||||
For this, the function `Transform.interpolate_with() <class_Transform_method_interpolate_with>` can be used.
|
For this, the function `Transform.interpolate_with()` can be used.
|
||||||
|
|
||||||
Here is an example of transforming a monkey from Position1 to Position2:
|
Here is an example of transforming a monkey from Position1 to Position2:
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ Getting a random number
|
|||||||
Let's look at some of the most commonly used functions and methods to generate
|
Let's look at some of the most commonly used functions and methods to generate
|
||||||
random numbers in Godot.
|
random numbers in Godot.
|
||||||
|
|
||||||
The function `randi() <class_@GDScript_method_randi>` returns a random
|
The function `randi()` returns a random
|
||||||
number between 0 and 2^32-1. Since the maximum value is huge, you most likely
|
number between 0 and 2^32-1. Since the maximum value is huge, you most likely
|
||||||
want to use the modulo operator (``%``) to bound the result between 0 and the
|
want to use the modulo operator (``%``) to bound the result between 0 and the
|
||||||
denominator:
|
denominator:
|
||||||
@ -97,12 +97,12 @@ gdscript GDScript
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
`randf() <class_@GDScript_method_randf>` returns a random floating-point
|
`randf()` returns a random floating-point
|
||||||
number between 0 and 1. This is useful to implement a
|
number between 0 and 1. This is useful to implement a
|
||||||
`doc_random_number_generation_weighted_random_probability` system, among
|
`doc_random_number_generation_weighted_random_probability` system, among
|
||||||
other things.
|
other things.
|
||||||
|
|
||||||
`randfn() <class_RandomNumberGenerator_method_randfn>` returns a random
|
`randfn()` returns a random
|
||||||
floating-point number following a `normal distribution
|
floating-point number following a `normal distribution
|
||||||
<https://en.wikipedia.org/wiki/Normal_distribution>`__. This means the returned
|
<https://en.wikipedia.org/wiki/Normal_distribution>`__. This means the returned
|
||||||
value is more likely to be around the mean (0.0 by default),
|
value is more likely to be around the mean (0.0 by default),
|
||||||
@ -117,7 +117,7 @@ gdscript GDScript
|
|||||||
print(random.randfn())
|
print(random.randfn())
|
||||||
```
|
```
|
||||||
|
|
||||||
`rand_range() <class_@GDScript_method_rand_range>` takes two arguments
|
`rand_range()` takes two arguments
|
||||||
``from`` and ``to``, and returns a random floating-point number between ``from``
|
``from`` and ``to``, and returns a random floating-point number between ``from``
|
||||||
and ``to``:
|
and ``to``:
|
||||||
|
|
||||||
@ -239,7 +239,7 @@ gdscript GDScript
|
|||||||
Weighted random probability
|
Weighted random probability
|
||||||
---------------------------
|
---------------------------
|
||||||
|
|
||||||
The `randf() <class_@GDScript_method_randf>` method returns a
|
The `randf()` method returns a
|
||||||
floating-point number between 0.0 and 1.0. We can use this to create a
|
floating-point number between 0.0 and 1.0. We can use this to create a
|
||||||
"weighted" probability where different outcomes have different likelihoods:
|
"weighted" probability where different outcomes have different likelihoods:
|
||||||
|
|
||||||
|
@ -69,8 +69,8 @@ gdscript GDScript
|
|||||||
$Node2D.position = Vector2(400, 300)
|
$Node2D.position = Vector2(400, 300)
|
||||||
```
|
```
|
||||||
|
|
||||||
Godot supports both `Vector2 <class_Vector2>` and
|
Godot supports both `Vector2` and
|
||||||
`Vector3 <class_Vector3>` for 2D and 3D usage, respectively. The same
|
`Vector3` for 2D and 3D usage, respectively. The same
|
||||||
mathematical rules discussed in this article apply to both types.
|
mathematical rules discussed in this article apply to both types.
|
||||||
|
|
||||||
Member access
|
Member access
|
||||||
@ -199,9 +199,9 @@ wall or other object:
|
|||||||
The surface normal has a value of ``(0, -1)`` because this is a horizontal
|
The surface normal has a value of ``(0, -1)`` because this is a horizontal
|
||||||
surface. When the ball collides, we take its remaining motion (the amount
|
surface. When the ball collides, we take its remaining motion (the amount
|
||||||
left over when it hits the surface) and reflect it using the normal. In
|
left over when it hits the surface) and reflect it using the normal. In
|
||||||
Godot, the `Vector2 <class_Vector2>` class has a ``bounce()`` method
|
Godot, the `Vector2` class has a ``bounce()`` method
|
||||||
to handle this. Here is a GDScript example of the diagram above using a
|
to handle this. Here is a GDScript example of the diagram above using a
|
||||||
`KinematicBody2D <class_KinematicBody2D>`:
|
`KinematicBody2D`:
|
||||||
|
|
||||||
|
|
||||||
gdscript GDScript
|
gdscript GDScript
|
||||||
|
@ -67,7 +67,7 @@ by N and D. For example:
|
|||||||
|
|
||||||
.. image:: img/tutovec12.png
|
.. image:: img/tutovec12.png
|
||||||
|
|
||||||
For 3D math, Godot provides a `Plane <class_Plane>`
|
For 3D math, Godot provides a `Plane`
|
||||||
built-in type that handles this.
|
built-in type that handles this.
|
||||||
|
|
||||||
Basically, N and D can represent any plane in space, be it for 2D or 3D
|
Basically, N and D can represent any plane in space, be it for 2D or 3D
|
||||||
@ -114,7 +114,7 @@ gdscript GDScript
|
|||||||
D = -D
|
D = -D
|
||||||
```
|
```
|
||||||
|
|
||||||
Of course, Godot also implements this operator in `Plane <class_Plane>`,
|
Of course, Godot also implements this operator in `Plane`,
|
||||||
so doing:
|
so doing:
|
||||||
|
|
||||||
gdscript GDScript
|
gdscript GDScript
|
||||||
|
@ -106,6 +106,6 @@ starting location, the next is a Vector3 of the end location. And the
|
|||||||
last argument is a boolean for whether or not agent properties of a
|
last argument is a boolean for whether or not agent properties of a
|
||||||
navmesh are considered when generating a path.
|
navmesh are considered when generating a path.
|
||||||
|
|
||||||
The method will return a `PoolVector3Array <class_PoolVector3Array>` consisting of
|
The method will return a `PoolVector3Array` consisting of
|
||||||
points that make a path. If there is no way to navigate to the end
|
points that make a path. If there is no way to navigate to the end
|
||||||
location the method will return a blank `PoolVector3Array <class_PoolVector3Array>`.
|
location the method will return a blank `PoolVector3Array`.
|
||||||
|
@ -23,7 +23,7 @@ This is due to the inherent limitations of the low-level protocols:
|
|||||||
In general, TCP can be thought of as reliable, ordered, and slow; UDP as unreliable, unordered and fast.
|
In general, TCP can be thought of as reliable, ordered, and slow; UDP as unreliable, unordered and fast.
|
||||||
Because of the large difference in performance, it often makes sense to re-build the parts of TCP wanted for games (optional reliability and packet order), while avoiding the unwanted parts (congestion/traffic control features, Nagle's algorithm, etc). Due to this, most game engines come with such an implementation, and Godot is no exception.
|
Because of the large difference in performance, it often makes sense to re-build the parts of TCP wanted for games (optional reliability and packet order), while avoiding the unwanted parts (congestion/traffic control features, Nagle's algorithm, etc). Due to this, most game engines come with such an implementation, and Godot is no exception.
|
||||||
|
|
||||||
In summary, you can use the low-level networking API for maximum control and implement everything on top of bare network protocols or use the high-level API based on `SceneTree <class_SceneTree>` that does most of the heavy lifting behind the scenes in a generally optimized way.
|
In summary, you can use the low-level networking API for maximum control and implement everything on top of bare network protocols or use the high-level API based on `SceneTree` that does most of the heavy lifting behind the scenes in a generally optimized way.
|
||||||
|
|
||||||
.. note:: Most of Godot's supported platforms offer all or most of the mentioned high- and low-level networking
|
.. note:: Most of Godot's supported platforms offer all or most of the mentioned high- and low-level networking
|
||||||
features. As networking is always largely hardware and operating system dependent, however,
|
features. As networking is always largely hardware and operating system dependent, however,
|
||||||
@ -56,15 +56,15 @@ Mid level abstraction
|
|||||||
|
|
||||||
Before going into how we would like to synchronize a game across the network, it can be helpful to understand how the base network API for synchronization works.
|
Before going into how we would like to synchronize a game across the network, it can be helpful to understand how the base network API for synchronization works.
|
||||||
|
|
||||||
Godot uses a mid-level object `NetworkedMultiplayerPeer <class_NetworkedMultiplayerPeer>`.
|
Godot uses a mid-level object `NetworkedMultiplayerPeer`.
|
||||||
This object is not meant to be created directly, but is designed so that several C++ implementations can provide it.
|
This object is not meant to be created directly, but is designed so that several C++ implementations can provide it.
|
||||||
|
|
||||||
This object extends from `PacketPeer <class_PacketPeer>`, so it inherits all the useful methods for serializing, sending and receiving data. On top of that, it adds methods to set a peer, transfer mode, etc. It also includes signals that will let you know when peers connect or disconnect.
|
This object extends from `PacketPeer`, so it inherits all the useful methods for serializing, sending and receiving data. On top of that, it adds methods to set a peer, transfer mode, etc. It also includes signals that will let you know when peers connect or disconnect.
|
||||||
|
|
||||||
This class interface can abstract most types of network layers, topologies and libraries. By default, Godot
|
This class interface can abstract most types of network layers, topologies and libraries. By default, Godot
|
||||||
provides an implementation based on ENet (`NetworkedMultiplayerEnet <class_NetworkedMultiplayerENet>`),
|
provides an implementation based on ENet (`NetworkedMultiplayerEnet`),
|
||||||
one based on WebRTC (`WebRTCMultiplayer <class_WebRTCMultiplayer>`), and one based on WebSocket
|
one based on WebRTC (`WebRTCMultiplayer`), and one based on WebSocket
|
||||||
(`WebSocketMultiplayerPeer <class_WebSocketMultiplayerPeer>`), but this could be used to implement
|
(`WebSocketMultiplayerPeer`), but this could be used to implement
|
||||||
mobile APIs (for ad hoc WiFi, Bluetooth) or custom device/console-specific networking APIs.
|
mobile APIs (for ad hoc WiFi, Bluetooth) or custom device/console-specific networking APIs.
|
||||||
|
|
||||||
For most common cases, using this object directly is discouraged, as Godot provides even higher level networking facilities.
|
For most common cases, using this object directly is discouraged, as Godot provides even higher level networking facilities.
|
||||||
@ -73,7 +73,7 @@ Yet it is made available in case a game has specific needs for a lower level API
|
|||||||
Initializing the network
|
Initializing the network
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
The object that controls networking in Godot is the same one that controls everything tree-related: `SceneTree <class_SceneTree>`.
|
The object that controls networking in Godot is the same one that controls everything tree-related: `SceneTree`.
|
||||||
|
|
||||||
To initialize high-level networking, the SceneTree must be provided a NetworkedMultiplayerPeer object.
|
To initialize high-level networking, the SceneTree must be provided a NetworkedMultiplayerPeer object.
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ Managing connections
|
|||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
Some games accept connections at any time, others during the lobby phase. Godot can be requested to no longer accept
|
Some games accept connections at any time, others during the lobby phase. Godot can be requested to no longer accept
|
||||||
connections at any point (see ``set_refuse_new_network_connections(bool)`` and related methods on `SceneTree <class_SceneTree>`). To manage who connects, Godot provides the following signals in SceneTree:
|
connections at any point (see ``set_refuse_new_network_connections(bool)`` and related methods on `SceneTree`). To manage who connects, Godot provides the following signals in SceneTree:
|
||||||
|
|
||||||
Server and Clients:
|
Server and Clients:
|
||||||
|
|
||||||
@ -136,7 +136,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.
|
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.
|
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.
|
Anything below 1 should be handled as invalid.
|
||||||
You can retrieve the ID for the local system via `SceneTree.get_network_unique_id() <class_SceneTree_method_get_network_unique_id>`.
|
You can retrieve the ID for the local system via `SceneTree.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.
|
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:
|
Clients:
|
||||||
@ -156,7 +156,7 @@ RPC
|
|||||||
---
|
---
|
||||||
|
|
||||||
To communicate between peers, the easiest way is to use RPCs (remote procedure calls). This is implemented as a set of functions
|
To communicate between peers, the easiest way is to use RPCs (remote procedure calls). This is implemented as a set of functions
|
||||||
in `Node <class_Node>`:
|
in `Node`:
|
||||||
|
|
||||||
- ``rpc("function_name", <optional_args>)``
|
- ``rpc("function_name", <optional_args>)``
|
||||||
- ``rpc_id(<peer_id>,"function_name", <optional_args>)``
|
- ``rpc_id(<peer_id>,"function_name", <optional_args>)``
|
||||||
@ -178,7 +178,7 @@ Functions can be called in two fashions:
|
|||||||
In most cases, reliable is desired. Unreliable is mostly useful when synchronizing object positions (sync must happen constantly,
|
In most cases, reliable is desired. Unreliable is mostly useful when synchronizing object positions (sync must happen constantly,
|
||||||
and if a packet is lost, it's not that bad because a new one will eventually arrive and it would likely be outdated because the object moved further in the meantime, even if it was resent reliably).
|
and if a packet is lost, it's not that bad because a new one will eventually arrive and it would likely be outdated because the object moved further in the meantime, even if it was resent reliably).
|
||||||
|
|
||||||
There is also `SceneTree.get_rpc_sender_id() <class_SceneTree_method_get_rpc_sender_id>`, which can be used to check which peer (or peer ID) sent an RPC.
|
There is also `SceneTree.get_rpc_sender_id()`, which can be used to check which peer (or peer ID) sent an RPC.
|
||||||
|
|
||||||
Back to lobby
|
Back to lobby
|
||||||
-------------
|
-------------
|
||||||
@ -260,7 +260,7 @@ If ``sync`` is included, the call can also be made locally. For example, to allo
|
|||||||
puppetsync func update_position(new_position):
|
puppetsync func update_position(new_position):
|
||||||
position = new_position
|
position = new_position
|
||||||
|
|
||||||
.. tip:: You can also use `SceneTree.get_rpc_sender_id() <class_SceneTree_method_get_rpc_sender_id>` to have more advanced rules on how an rpc can be called.
|
.. tip:: You can also use `SceneTree.get_rpc_sender_id()` to have more advanced rules on how an rpc can be called.
|
||||||
|
|
||||||
These keywords are further explained in `Synchronizing the game <doc_high_level_multiplayer_synchronizing>`.
|
These keywords are further explained in `Synchronizing the game <doc_high_level_multiplayer_synchronizing>`.
|
||||||
|
|
||||||
@ -367,9 +367,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.
|
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
|
The network master can be set
|
||||||
with the function `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).
|
with the function `Node.set_network_master(id, recursive)` (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 `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.
|
Checking that a specific node instance on a peer is the network master for this node for all connected peers is done by calling `Node.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 each peer was set to have network master authority for their own player (Node) instead of the server:
|
If you have paid attention to the previous example, it's possible you noticed that each peer was set to have network master authority for their own player (Node) instead of the server:
|
||||||
|
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
HTTP client class
|
HTTP client class
|
||||||
=================
|
=================
|
||||||
|
|
||||||
`HTTPClient <class_HTTPClient>` provides low-level access to HTTP communication.
|
`HTTPClient` provides low-level access to HTTP communication.
|
||||||
For a higher-level interface, you may want to take a look at `HTTPRequest <class_HTTPRequest>` first,
|
For a higher-level interface, you may want to take a look at `HTTPRequest` first,
|
||||||
which has a tutorial available `here <doc_http_request_class>`.
|
which has a tutorial available `here <doc_http_request_class>`.
|
||||||
|
|
||||||
.. warning::
|
.. warning::
|
||||||
@ -14,7 +14,7 @@ which has a tutorial available `here <doc_http_request_class>`.
|
|||||||
using one-click deploy. Otherwise, network communication of any kind will be
|
using one-click deploy. Otherwise, network communication of any kind will be
|
||||||
blocked by Android.
|
blocked by Android.
|
||||||
|
|
||||||
Here's an example of using the `HTTPClient <class_HTTPClient>`
|
Here's an example of using the `HTTPClient`
|
||||||
class. It's just a script, so it can be run by executing:
|
class. It's just a script, so it can be run by executing:
|
||||||
|
|
||||||
console GDScript
|
console GDScript
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
Making HTTP requests
|
Making HTTP requests
|
||||||
====================
|
====================
|
||||||
|
|
||||||
The `HTTPRequest <class_HTTPRequest>` node is the easiest way to make HTTP requests in Godot.
|
The `HTTPRequest` node is the easiest way to make HTTP requests in Godot.
|
||||||
It is backed by the more low-level `HTTPClient <class_HTTPClient>`, for which a tutorial is available `here <doc_http_client_class>`.
|
It is backed by the more low-level `HTTPClient`.
|
||||||
|
|
||||||
For the sake of this example, we will create a simple UI with a button, that when pressed will start the HTTP request to the specified URL.
|
For the sake of this example, we will create a simple UI with a button, that when pressed will start the HTTP request to the specified URL.
|
||||||
|
|
||||||
@ -48,9 +48,9 @@ gdscript GDScript
|
|||||||
|
|
||||||
With this, you should see ``(hello:world)`` printed on the console; hello being a key, and world being a value, both of them strings.
|
With this, you should see ``(hello:world)`` printed on the console; hello being a key, and world being a value, both of them strings.
|
||||||
|
|
||||||
For more information on parsing JSON, see the class references for `JSON <class_JSON>` and `JSONParseResult <class_JSONParseResult>`.
|
For more information on parsing JSON, see the class references for `JSON`.
|
||||||
|
|
||||||
Note that you may want to check whether the ``result`` equals ``RESULT_SUCCESS`` and whether a JSON parsing error occurred, see the JSON class reference and `HTTPRequest <class_HTTPRequest>` for more.
|
Note that you may want to check whether the ``result`` equals ``RESULT_SUCCESS`` and whether a JSON parsing error occurred, see the JSON class reference and `HTTPRequest` for more.
|
||||||
|
|
||||||
Of course, you can also set custom HTTP headers. These are given as a string array, with each string containing a header in the format ``"header: value"``.
|
Of course, you can also set custom HTTP headers. These are given as a string array, with each string containing a header in the format ``"header: value"``.
|
||||||
For example, to set a custom user agent (the HTTP ``user-agent`` header) you could use the following:
|
For example, to set a custom user agent (the HTTP ``user-agent`` header) you could use the following:
|
||||||
|
@ -8,9 +8,9 @@ Introduction
|
|||||||
|
|
||||||
It is often desired to use SSL connections for communications to avoid
|
It is often desired to use SSL connections for communications to avoid
|
||||||
"man in the middle" attacks. Godot has a connection wrapper,
|
"man in the middle" attacks. Godot has a connection wrapper,
|
||||||
`StreamPeerSSL <class_StreamPeerSSL>`,
|
`StreamPeerSSL`,
|
||||||
which can take a regular connection and add security around it. The
|
which can take a regular connection and add security around it. The
|
||||||
`HTTPClient <class_HTTPClient>`
|
`HTTPClient`
|
||||||
class also supports HTTPS by using this same wrapper.
|
class also supports HTTPS by using this same wrapper.
|
||||||
|
|
||||||
Godot includes SSL certificates from Mozilla, but you can provide your own
|
Godot includes SSL certificates from Mozilla, but you can provide your own
|
||||||
|
@ -33,7 +33,7 @@ Peers connect to a signaling server (for example a WebSocket server) and send th
|
|||||||
Using WebRTC in Godot
|
Using WebRTC in Godot
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
WebRTC is implemented in Godot via two main classes `WebRTCPeerConnection <class_WebRTCPeerConnection>` and `WebRTCDataChannel <class_WebRTCDataChannel>`, plus the multiplayer API implementation `WebRTCMultiplayer <class_WebRTCMultiplayer>`. See section on `high-level multiplayer <doc_high_level_multiplayer>` for more details.
|
WebRTC is implemented in Godot via two main classes `WebRTCPeerConnection` for more details.
|
||||||
|
|
||||||
.. note:: These classes are available automatically in HTML5, but **require an external GDNative plugin on native (non-HTML5) platforms**. Check out the `webrtc-native plugin repository <https://github.com/godotengine/webrtc-native>`__ for instructions and to get the latest `release <https://github.com/godotengine/webrtc-native/releases>`__.
|
.. note:: These classes are available automatically in HTML5, but **require an external GDNative plugin on native (non-HTML5) platforms**. Check out the `webrtc-native plugin repository <https://github.com/godotengine/webrtc-native>`__ for instructions and to get the latest `release <https://github.com/godotengine/webrtc-native/releases>`__.
|
||||||
|
|
||||||
@ -212,4 +212,4 @@ This will print something similar to this:
|
|||||||
Remote signaling with WebSocket
|
Remote signaling with WebSocket
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
A more advanced demo using WebSocket for signaling peers and `WebRTCMultiplayer <class_WebRTCMultiplayer>` is available in the `godot demo projects <https://github.com/godotengine/godot-demo-projects>`_ under `networking/webrtc_signaling`.
|
A more advanced demo using WebSocket for signaling peers and `WebRTCMultiplayer`_ under `networking/webrtc_signaling`.
|
||||||
|
@ -18,7 +18,7 @@ Godot supports WebSocket in both native and HTML5 exports.
|
|||||||
Using WebSocket in Godot
|
Using WebSocket in Godot
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
WebSocket is implemented in Godot via three main classes `WebSocketClient <class_WebSocketClient>`, `WebSocketServer <class_WebSocketServer>`, and `WebSocketPeer <class_WebSocketPeer>`. The WebSocket implementation is compatible with the High Level Multiplayer. See section on `high-level multiplayer <doc_high_level_multiplayer>` for more details.
|
WebSocket is implemented in Godot via three main classes `WebSocketClient` for more details.
|
||||||
|
|
||||||
.. warning::
|
.. warning::
|
||||||
|
|
||||||
|
@ -308,23 +308,23 @@ rendering/batching/options
|
|||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
- `use_batching
|
- `use_batching
|
||||||
<class_ProjectSettings_property_rendering/batching/options/use_batching>` -
|
` -
|
||||||
Turns batching on or off.
|
Turns batching on or off.
|
||||||
|
|
||||||
- `use_batching_in_editor
|
- `use_batching_in_editor
|
||||||
<class_ProjectSettings_property_rendering/batching/options/use_batching_in_editor>`
|
`
|
||||||
Turns batching on or off in the Godot editor.
|
Turns batching on or off in the Godot editor.
|
||||||
This setting doesn't affect the running project in any way.
|
This setting doesn't affect the running project in any way.
|
||||||
|
|
||||||
- `single_rect_fallback
|
- `single_rect_fallback
|
||||||
<class_ProjectSettings_property_rendering/batching/options/single_rect_fallback>` -
|
` -
|
||||||
This is a faster way of drawing unbatchable rectangles. However, it may lead
|
This is a faster way of drawing unbatchable rectangles. However, it may lead
|
||||||
to flicker on some hardware so it's not recommended.
|
to flicker on some hardware so it's not recommended.
|
||||||
|
|
||||||
rendering/batching/parameters
|
rendering/batching/parameters
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
- `max_join_item_commands <class_ProjectSettings_property_rendering/batching/parameters/max_join_item_commands>` -
|
- `max_join_item_commands` -
|
||||||
One of the most important ways of achieving batching is to join suitable
|
One of the most important ways of achieving batching is to join suitable
|
||||||
adjacent items (nodes) together, however they can only be joined if the
|
adjacent items (nodes) together, however they can only be joined if the
|
||||||
commands they contain are compatible. The system must therefore do a lookahead
|
commands they contain are compatible. The system must therefore do a lookahead
|
||||||
@ -333,7 +333,7 @@ rendering/batching/parameters
|
|||||||
not worth joining, so the best value may be project dependent.
|
not worth joining, so the best value may be project dependent.
|
||||||
|
|
||||||
- `colored_vertex_format_threshold
|
- `colored_vertex_format_threshold
|
||||||
<class_ProjectSettings_property_rendering/batching/parameters/colored_vertex_format_threshold>` -
|
` -
|
||||||
Baking colors into vertices results in a larger vertex format. This is not
|
Baking colors into vertices results in a larger vertex format. This is not
|
||||||
necessarily worth doing unless there are a lot of color changes going on
|
necessarily worth doing unless there are a lot of color changes going on
|
||||||
within a joined item. This parameter represents the proportion of commands
|
within a joined item. This parameter represents the proportion of commands
|
||||||
@ -341,12 +341,12 @@ rendering/batching/parameters
|
|||||||
baked colors.
|
baked colors.
|
||||||
|
|
||||||
- `batch_buffer_size
|
- `batch_buffer_size
|
||||||
<class_ProjectSettings_property_rendering/batching/parameters/batch_buffer_size>` -
|
` -
|
||||||
This determines the maximum size of a batch, it doesn't have a huge effect
|
This determines the maximum size of a batch, it doesn't have a huge effect
|
||||||
on performance but can be worth decreasing for mobile if RAM is at a premium.
|
on performance but can be worth decreasing for mobile if RAM is at a premium.
|
||||||
|
|
||||||
- `item_reordering_lookahead
|
- `item_reordering_lookahead
|
||||||
<class_ProjectSettings_property_rendering/batching/parameters/item_reordering_lookahead>` -
|
` -
|
||||||
Item reordering can help especially with interleaved sprites using different
|
Item reordering can help especially with interleaved sprites using different
|
||||||
textures. The lookahead for the overlap test has a small cost, so the best
|
textures. The lookahead for the overlap test has a small cost, so the best
|
||||||
value may change per project.
|
value may change per project.
|
||||||
@ -355,11 +355,11 @@ rendering/batching/lights
|
|||||||
^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
- `scissor_area_threshold
|
- `scissor_area_threshold
|
||||||
<class_ProjectSettings_property_rendering/batching/lights/scissor_area_threshold>` -
|
` -
|
||||||
See light scissoring.
|
See light scissoring.
|
||||||
|
|
||||||
- `max_join_items
|
- `max_join_items
|
||||||
<class_ProjectSettings_property_rendering/batching/lights/max_join_items>` -
|
` -
|
||||||
Joining items before lighting can significantly increase
|
Joining items before lighting can significantly increase
|
||||||
performance. This requires an overlap test, which has a small cost, so the
|
performance. This requires an overlap test, which has a small cost, so the
|
||||||
costs and benefits may be project dependent, and hence the best value to use
|
costs and benefits may be project dependent, and hence the best value to use
|
||||||
@ -369,14 +369,14 @@ rendering/batching/debug
|
|||||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
- `flash_batching
|
- `flash_batching
|
||||||
<class_ProjectSettings_property_rendering/batching/debug/flash_batching>` -
|
` -
|
||||||
This is purely a debugging feature to identify regressions between the
|
This is purely a debugging feature to identify regressions between the
|
||||||
batching and legacy renderer. When it is switched on, the batching and legacy
|
batching and legacy renderer. When it is switched on, the batching and legacy
|
||||||
renderer are used alternately on each frame. This will decrease performance,
|
renderer are used alternately on each frame. This will decrease performance,
|
||||||
and should not be used for your final export, only for testing.
|
and should not be used for your final export, only for testing.
|
||||||
|
|
||||||
- `diagnose_frame
|
- `diagnose_frame
|
||||||
<class_ProjectSettings_property_rendering/batching/debug/diagnose_frame>` -
|
` -
|
||||||
This will periodically print a diagnostic batching log to
|
This will periodically print a diagnostic batching log to
|
||||||
the Godot IDE / console.
|
the Godot IDE / console.
|
||||||
|
|
||||||
@ -384,7 +384,7 @@ rendering/batching/precision
|
|||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
- `uv_contract
|
- `uv_contract
|
||||||
<class_ProjectSettings_property_rendering/batching/precision/uv_contract>` -
|
` -
|
||||||
On some hardware (notably some Android devices) there have been reports of
|
On some hardware (notably some Android devices) there have been reports of
|
||||||
tilemap tiles drawing slightly outside their UV range, leading to edge
|
tilemap tiles drawing slightly outside their UV range, leading to edge
|
||||||
artifacts such as lines around tiles. If you see this problem, try enabling uv
|
artifacts such as lines around tiles. If you see this problem, try enabling uv
|
||||||
@ -392,7 +392,7 @@ rendering/batching/precision
|
|||||||
for precision errors on devices.
|
for precision errors on devices.
|
||||||
|
|
||||||
- `uv_contract_amount
|
- `uv_contract_amount
|
||||||
<class_ProjectSettings_property_rendering/batching/precision/uv_contract_amount>` -
|
` -
|
||||||
Hopefully, the default amount should cure artifacts on most devices,
|
Hopefully, the default amount should cure artifacts on most devices,
|
||||||
but this value remains adjustable just in case.
|
but this value remains adjustable just in case.
|
||||||
|
|
||||||
@ -486,7 +486,7 @@ I get a decrease in performance with batching.
|
|||||||
|
|
||||||
- Try the steps described above to increase the number of batching opportunities.
|
- Try the steps described above to increase the number of batching opportunities.
|
||||||
- Try enabling `single_rect_fallback
|
- Try enabling `single_rect_fallback
|
||||||
<class_ProjectSettings_property_rendering/batching/options/single_rect_fallback>`.
|
`.
|
||||||
- The single rect fallback method is the default used without batching, and it
|
- The single rect fallback method is the default used without batching, and it
|
||||||
is approximately twice as fast. However, it can result in flickering on some
|
is approximately twice as fast. However, it can result in flickering on some
|
||||||
hardware, so its use is discouraged.
|
hardware, so its use is discouraged.
|
||||||
@ -502,7 +502,7 @@ I am seeing line artifacts appear on certain hardware.
|
|||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
- See the `uv_contract
|
- See the `uv_contract
|
||||||
<class_ProjectSettings_property_rendering/batching/precision/uv_contract>`
|
`
|
||||||
project setting which can be used to solve this problem.
|
project setting which can be used to solve this problem.
|
||||||
|
|
||||||
I use a large number of textures, so few items are being batched.
|
I use a large number of textures, so few items are being batched.
|
||||||
|
@ -231,12 +231,12 @@ performance when you have very large numbers of nodes (usually in the thousands)
|
|||||||
Each node is handled individually in the Godot renderer. Therefore, a smaller
|
Each node is handled individually in the Godot renderer. Therefore, a smaller
|
||||||
number of nodes with more in each can lead to better performance.
|
number of nodes with more in each can lead to better performance.
|
||||||
|
|
||||||
One quirk of the `SceneTree <class_SceneTree>` is that you can sometimes
|
One quirk of the `SceneTree` is that you can sometimes
|
||||||
get much better performance by removing nodes from the SceneTree, rather than by
|
get much better performance by removing nodes from the SceneTree, rather than by
|
||||||
pausing or hiding them. You don't have to delete a detached node. You can for
|
pausing or hiding them. You don't have to delete a detached node. You can for
|
||||||
example, keep a reference to a node, detach it from the scene tree using
|
example, keep a reference to a node, detach it from the scene tree using
|
||||||
`Node.remove_child(node) <class_Node_method_remove_child>`, then reattach
|
`Node.remove_child(node)`, then reattach
|
||||||
it later using `Node.add_child(node) <class_Node_method_add_child>`.
|
it later using `Node.add_child(node)`.
|
||||||
This can be very useful for adding and removing areas from a game, for example.
|
This can be very useful for adding and removing areas from a game, for example.
|
||||||
|
|
||||||
You can avoid the SceneTree altogether by using Server APIs. For more
|
You can avoid the SceneTree altogether by using Server APIs. For more
|
||||||
|
@ -71,7 +71,7 @@ through add-ons or may be available in core Godot in the future.
|
|||||||
Transparent objects
|
Transparent objects
|
||||||
~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
Godot sorts objects by `Material <class_Material>` and `Shader
|
Godot sorts objects by `Material` and `Shader
|
||||||
<class_Shader>` to improve performance. This, however, can not be done with
|
<class_Shader>` to improve performance. This, however, can not be done with
|
||||||
transparent objects. Transparent objects are rendered from back to front to make
|
transparent objects. Transparent objects are rendered from back to front to make
|
||||||
blending with what is behind work. As a result,
|
blending with what is behind work. As a result,
|
||||||
@ -116,7 +116,7 @@ Use instancing (MultiMesh)
|
|||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
If several identical objects have to be drawn in the same place or nearby, try
|
If several identical objects have to be drawn in the same place or nearby, try
|
||||||
using `MultiMesh <class_MultiMesh>` instead. MultiMesh allows the drawing
|
using `MultiMesh` instead. MultiMesh allows the drawing
|
||||||
of many thousands of objects at very little performance cost, making it ideal
|
of many thousands of objects at very little performance cost, making it ideal
|
||||||
for flocks, grass, particles, and anything else where you have thousands of
|
for flocks, grass, particles, and anything else where you have thousands of
|
||||||
identical objects.
|
identical objects.
|
||||||
|
@ -35,12 +35,12 @@ which are ideal for this).
|
|||||||
|
|
||||||
Another alternative is to use GDNative and C++, which should be extremely efficient (it's possible
|
Another alternative is to use GDNative and C++, which should be extremely efficient (it's possible
|
||||||
to set the entire state for all objects using linear memory via the
|
to set the entire state for all objects using linear memory via the
|
||||||
`VisualServer.multimesh_set_as_bulk_array() <class_VisualServer_method_multimesh_set_as_bulk_array>`
|
`VisualServer.multimesh_set_as_bulk_array()`
|
||||||
function). This way, the array can be created with multiple threads, then set in one call, providing
|
function). This way, the array can be created with multiple threads, then set in one call, providing
|
||||||
high cache efficiency.
|
high cache efficiency.
|
||||||
|
|
||||||
Finally, it's not required to have all MultiMesh instances visible. The amount of visible ones can be
|
Finally, it's not required to have all MultiMesh instances visible. The amount of visible ones can be
|
||||||
controlled with the `MultiMesh.visible_instance_count <class_MultiMesh_property_visible_instance_count>`
|
controlled with the `MultiMesh.visible_instance_count`
|
||||||
property. The typical workflow is to allocate the maximum amount of instances that will be used,
|
property. The typical workflow is to allocate the maximum amount of instances that will be used,
|
||||||
then change the amount visible depending on how many are currently needed.
|
then change the amount visible depending on how many are currently needed.
|
||||||
|
|
||||||
|
@ -33,10 +33,10 @@ At the core, Godot uses the concept of Servers. They are very low-level APIs to
|
|||||||
rendering, physics, sound, etc. The scene system is built on top of them and uses them directly.
|
rendering, physics, sound, etc. The scene system is built on top of them and uses them directly.
|
||||||
The most common servers are:
|
The most common servers are:
|
||||||
|
|
||||||
* `VisualServer <class_VisualServer>`: handles everything related to graphics.
|
* `VisualServer`: handles everything related to graphics.
|
||||||
* `PhysicsServer <class_PhysicsServer>`: handles everything related to 3D physics.
|
* `PhysicsServer`: handles everything related to 3D physics.
|
||||||
* `Physics2DServer <class_Physics2DServer>`: handles everything related to 2D physics.
|
* `Physics2DServer`: handles everything related to 2D physics.
|
||||||
* `AudioServer <class_AudioServer>`: handles everything related to audio.
|
* `AudioServer`: handles everything related to audio.
|
||||||
|
|
||||||
Explore their APIs and you will realize that all the functions provided are low-level
|
Explore their APIs and you will realize that all the functions provided are low-level
|
||||||
implementations of everything Godot allows you to do.
|
implementations of everything Godot allows you to do.
|
||||||
@ -44,38 +44,38 @@ implementations of everything Godot allows you to do.
|
|||||||
RIDs
|
RIDs
|
||||||
----
|
----
|
||||||
|
|
||||||
The key to using servers is understanding Resource ID (`RID <class_RID>`) objects. These are opaque
|
The key to using servers is understanding Resource ID (`RID`) objects. These are opaque
|
||||||
handles to the server implementation. They are allocated and freed manually. Almost every
|
handles to the server implementation. They are allocated and freed manually. Almost every
|
||||||
function in the servers requires RIDs to access the actual resource.
|
function in the servers requires RIDs to access the actual resource.
|
||||||
|
|
||||||
Most Godot nodes and resources contain these RIDs from the servers internally, and they can
|
Most Godot nodes and resources contain these RIDs from the servers internally, and they can
|
||||||
be obtained with different functions. In fact, anything that inherits `Resource <class_Resource>`
|
be obtained with different functions. In fact, anything that inherits `Resource`
|
||||||
can be directly casted to an RID. Not all resources contain an RID, though: in such cases, the RID will be empty. The resource can then be passed to server APIs as an RID.
|
can be directly casted to an RID. Not all resources contain an RID, though: in such cases, the RID will be empty. The resource can then be passed to server APIs as an RID.
|
||||||
|
|
||||||
.. Warning:: Resources are reference-counted (see `Reference <class_Reference>`), and
|
.. Warning:: Resources are reference-counted (see `Reference`), and
|
||||||
references to a resource's RID are *not* counted when determining whether
|
references to a resource's RID are *not* counted when determining whether
|
||||||
the resource is still in use. Make sure to keep a reference to the resource
|
the resource is still in use. Make sure to keep a reference to the resource
|
||||||
outside the server, or else both it and its RID will be erased.
|
outside the server, or else both it and its RID will be erased.
|
||||||
|
|
||||||
For nodes, there are many functions available:
|
For nodes, there are many functions available:
|
||||||
|
|
||||||
* For CanvasItem, the `CanvasItem.get_canvas_item() <class_CanvasItem_method_get_canvas_item>`
|
* For CanvasItem, the `CanvasItem.get_canvas_item()`
|
||||||
method will return the canvas item RID in the server.
|
method will return the canvas item RID in the server.
|
||||||
* For CanvasLayer, the `CanvasLayer.get_canvas() <class_CanvasLayer_method_get_canvas>`
|
* For CanvasLayer, the `CanvasLayer.get_canvas()`
|
||||||
method will return the canvas RID in the server.
|
method will return the canvas RID in the server.
|
||||||
* For Viewport, the `Viewport.get_viewport_rid() <class_Viewport_method_get_viewport_rid>`
|
* For Viewport, the `Viewport.get_viewport_rid()`
|
||||||
method will return the viewport RID in the server.
|
method will return the viewport RID in the server.
|
||||||
* For 3D, the `World <class_World>` resource (obtainable in the `Viewport <class_Viewport>`
|
* For 3D, the `World`
|
||||||
and `Spatial <class_Spatial>` nodes)
|
and `Spatial` nodes)
|
||||||
contains functions to get the *VisualServer Scenario*, and the *PhysicsServer Space*. This
|
contains functions to get the *VisualServer Scenario*, and the *PhysicsServer Space*. This
|
||||||
allows creating 3D objects directly with the server API and using them.
|
allows creating 3D objects directly with the server API and using them.
|
||||||
* For 2D, the `World2D <class_World2D>` resource (obtainable in the `Viewport <class_Viewport>`
|
* For 2D, the `World2D`
|
||||||
and `CanvasItem <class_CanvasItem>` nodes)
|
and `CanvasItem` nodes)
|
||||||
contains functions to get the *VisualServer Canvas*, and the *Physics2DServer Space*. This
|
contains functions to get the *VisualServer Canvas*, and the *Physics2DServer Space*. This
|
||||||
allows creating 2D objects directly with the server API and using them.
|
allows creating 2D objects directly with the server API and using them.
|
||||||
* The `VisualInstance<class_VisualInstance>` class, allows getting the scenario *instance* and
|
* The `VisualInstance<class_VisualInstance>` class, allows getting the scenario *instance* and
|
||||||
*instance base* via the `VisualInstance.get_instance() <class_VisualInstance_method_get_instance>`
|
*instance base* via the `VisualInstance.get_instance()`
|
||||||
and `VisualInstance.get_base() <class_VisualInstance_method_get_base>` respectively.
|
and `VisualInstance.get_base()` respectively.
|
||||||
|
|
||||||
Try exploring the nodes and resources you are familiar with and find the functions to obtain the server *RIDs*.
|
Try exploring the nodes and resources you are familiar with and find the functions to obtain the server *RIDs*.
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ Creating a sprite
|
|||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
This is a simple example of how to create a sprite from code and move it using the low-level
|
This is a simple example of how to create a sprite from code and move it using the low-level
|
||||||
`CanvasItem <class_CanvasItem>` API.
|
`CanvasItem` API.
|
||||||
|
|
||||||
gdscript GDScript
|
gdscript GDScript
|
||||||
|
|
||||||
@ -160,8 +160,8 @@ gdscript GDScript
|
|||||||
Creating a 2D RigidBody and moving a sprite with it
|
Creating a 2D RigidBody and moving a sprite with it
|
||||||
---------------------------------------------------
|
---------------------------------------------------
|
||||||
|
|
||||||
This creates a `RigidBody2D <class_RigidBody2D>` using the `Physics2DServer <class_Physics2DServer>` API,
|
This creates a `RigidBody2D` API,
|
||||||
and moves a `CanvasItem <class_CanvasItem>` when the body moves.
|
and moves a `CanvasItem` when the body moves.
|
||||||
|
|
||||||
gdscript GDScript
|
gdscript GDScript
|
||||||
|
|
||||||
@ -197,7 +197,7 @@ gdscript GDScript
|
|||||||
```
|
```
|
||||||
|
|
||||||
The 3D version should be very similar, as 2D and 3D physics servers are identical (using
|
The 3D version should be very similar, as 2D and 3D physics servers are identical (using
|
||||||
`RigidBody <class_RigidBody>` and `PhysicsServer <class_PhysicsServer>` respectively).
|
`RigidBody` respectively).
|
||||||
|
|
||||||
Getting data from the servers
|
Getting data from the servers
|
||||||
-----------------------------
|
-----------------------------
|
||||||
|
@ -7,8 +7,8 @@ This tutorial explores a technique used in the game `ABZU <https://www.gdcvault.
|
|||||||
for rendering and animating thousands of fish using vertex animation and
|
for rendering and animating thousands of fish using vertex animation and
|
||||||
static mesh instancing.
|
static mesh instancing.
|
||||||
|
|
||||||
In Godot, this can be accomplished with a custom `Shader <class_Shader>` and
|
In Godot, this can be accomplished with a custom `Shader` and
|
||||||
a `MultiMeshInstance <class_MultiMeshInstance>`. Using the following technique you
|
a `MultiMeshInstance`. Using the following technique you
|
||||||
can render thousands of animated objects, even on low end hardware.
|
can render thousands of animated objects, even on low end hardware.
|
||||||
|
|
||||||
We will start by animating one fish. Then, we will see how to extend that animation to
|
We will start by animating one fish. Then, we will see how to extend that animation to
|
||||||
@ -17,8 +17,8 @@ thousands of fish.
|
|||||||
Animating one Fish
|
Animating one Fish
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
We will start with a single fish. Load your fish model into a `MeshInstance <class_MeshInstance>`
|
We will start with a single fish. Load your fish model into a `MeshInstance`
|
||||||
and add a new `ShaderMaterial <class_ShaderMaterial>`.
|
and add a new `ShaderMaterial`.
|
||||||
|
|
||||||
Here is the fish we will be using for the example images, you can use any fish model you like.
|
Here is the fish we will be using for the example images, you can use any fish model you like.
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ Here is the fish we will be using for the example images, you can use any fish m
|
|||||||
shared with a creative commons license. CC0 1.0 Universal (CC0 1.0) Public Domain
|
shared with a creative commons license. CC0 1.0 Universal (CC0 1.0) Public Domain
|
||||||
Dedication https://creativecommons.org/publicdomain/zero/1.0/
|
Dedication https://creativecommons.org/publicdomain/zero/1.0/
|
||||||
|
|
||||||
Typically, you would use bones and a `Skeleton <class_Skeleton>` to animate objects. However,
|
Typically, you would use bones and a `Skeleton` to animate objects. However,
|
||||||
bones are animated on the CPU and so you end having to calculate thousands of operations every
|
bones are animated on the CPU and so you end having to calculate thousands of operations every
|
||||||
frame and it becomes impossible to have thousands of objects. Using vertex animation in a vertex
|
frame and it becomes impossible to have thousands of objects. Using vertex animation in a vertex
|
||||||
shader, you avoid using bones and can instead calculate the full animation in a few lines of code
|
shader, you avoid using bones and can instead calculate the full animation in a few lines of code
|
||||||
@ -187,12 +187,12 @@ A MultiMeshInstance node is created and used the same way you would make a MeshI
|
|||||||
For this tutorial, we will name the MultiMeshInstance node ``School``, because it will contain
|
For this tutorial, we will name the MultiMeshInstance node ``School``, because it will contain
|
||||||
a school of fish.
|
a school of fish.
|
||||||
|
|
||||||
Once you have a MultiMeshInstance add a `MultiMesh <class_MultiMesh>`, and to that
|
Once you have a MultiMeshInstance add a `MultiMesh`, and to that
|
||||||
MultiMesh add your `Mesh <class_Mesh>` with the shader from above.
|
MultiMesh add your `Mesh` with the shader from above.
|
||||||
|
|
||||||
MultiMeshes draw your Mesh with three additional per-instance properties: Transform (rotation,
|
MultiMeshes draw your Mesh with three additional per-instance properties: Transform (rotation,
|
||||||
translation, scale), Color, and Custom. Custom is used to pass in 4 multi-use variables using
|
translation, scale), Color, and Custom. Custom is used to pass in 4 multi-use variables using
|
||||||
a `Color <class_Color>`.
|
a `Color`.
|
||||||
|
|
||||||
``instance_count`` specifies how many instances of the mesh you want to draw. For now, leave
|
``instance_count`` specifies how many instances of the mesh you want to draw. For now, leave
|
||||||
``instance_count`` at ``0`` because you cannot change any of the other parameters while
|
``instance_count`` at ``0`` because you cannot change any of the other parameters while
|
||||||
@ -271,5 +271,5 @@ moving. You can move them by updating the per-instance transform for each fish e
|
|||||||
doing so will be faster than moving thousands of MeshInstances per frame, it'll still likely be
|
doing so will be faster than moving thousands of MeshInstances per frame, it'll still likely be
|
||||||
slow.
|
slow.
|
||||||
|
|
||||||
In the next tutorial we will cover how to use `Particles <class_Particles>` to take advantage
|
In the next tutorial we will cover how to use `Particles` to take advantage
|
||||||
of the GPU and move each fish around individually while still receiving the benefits of instancing.
|
of the GPU and move each fish around individually while still receiving the benefits of instancing.
|
||||||
|
@ -3,20 +3,20 @@
|
|||||||
Controlling thousands of fish with Particles
|
Controlling thousands of fish with Particles
|
||||||
============================================
|
============================================
|
||||||
|
|
||||||
The problem with `MeshInstances <class_MeshInstance>` is that it is expensive to
|
The problem with `MeshInstances` is that it is expensive to
|
||||||
update their transform array. It is great for placing many static objects around the
|
update their transform array. It is great for placing many static objects around the
|
||||||
scene. But it is still difficult to move the objects around the scene.
|
scene. But it is still difficult to move the objects around the scene.
|
||||||
|
|
||||||
To make each instance move in an interesting way, we will use a
|
To make each instance move in an interesting way, we will use a
|
||||||
`Particles <class_Particles>` node. Particles take advantage of GPU acceleration
|
`Particles` node. Particles take advantage of GPU acceleration
|
||||||
by computing and setting the per-instance information in a `Shader <class_Shader>`.
|
by computing and setting the per-instance information in a `Shader`.
|
||||||
|
|
||||||
.. note:: Particles are not available in GLES2, instead use `CPUParticles <class_CPUParticles>`,
|
.. note:: Particles are not available in GLES2, instead use `CPUParticles`,
|
||||||
which do the same thing as Particles, but do not benefit from GPU acceleration.
|
which do the same thing as Particles, but do not benefit from GPU acceleration.
|
||||||
|
|
||||||
First create a Particles node. Then, under "Draw Passes" set the Particle's "Draw Pass 1" to your
|
First create a Particles node. Then, under "Draw Passes" set the Particle's "Draw Pass 1" to your
|
||||||
`Mesh <class_Mesh>`. Then under "Process Material" create a new
|
`Mesh`. Then under "Process Material" create a new
|
||||||
`ShaderMaterial <class_ShaderMaterial>`.
|
`ShaderMaterial`.
|
||||||
|
|
||||||
Set the ``shader_type`` to ``particles``.
|
Set the ``shader_type`` to ``particles``.
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ Then add the following two functions:
|
|||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
These functions come from the default `ParticlesMaterial <class_ParticlesMaterial>`.
|
These functions come from the default `ParticlesMaterial`.
|
||||||
They are used to generate a random number from each particle's ``RANDOM_SEED``.
|
They are used to generate a random number from each particle's ``RANDOM_SEED``.
|
||||||
|
|
||||||
A unique thing about particle shaders is that some built-in variables are saved across frames.
|
A unique thing about particle shaders is that some built-in variables are saved across frames.
|
||||||
|
@ -13,7 +13,7 @@ Godot provides many kinds of collision shapes, with different performance and
|
|||||||
accuracy tradeoffs.
|
accuracy tradeoffs.
|
||||||
|
|
||||||
You can define the shape of a `class_PhysicsBody` by adding one or more
|
You can define the shape of a `class_PhysicsBody` by adding one or more
|
||||||
`CollisionShapes <class_CollisionShape>` as child nodes. Note that you must
|
`CollisionShapes` as child nodes. Note that you must
|
||||||
add a `class_Shape` *resource* to collision shape nodes in the Inspector
|
add a `class_Shape` *resource* to collision shape nodes in the Inspector
|
||||||
dock.
|
dock.
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ better performance as well.
|
|||||||
Convex collision shapes
|
Convex collision shapes
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
`Convex collision shapes <class_ConvexPolygonShape>` are a compromise
|
`Convex collision shapes` are a compromise
|
||||||
between primitive collision shapes and concave collision shapes. They can
|
between primitive collision shapes and concave collision shapes. They can
|
||||||
represent shapes of any complexity, but with an important caveat. As their name
|
represent shapes of any complexity, but with an important caveat. As their name
|
||||||
implies, an individual shape can only represent a *convex* shape. For instance,
|
implies, an individual shape can only represent a *convex* shape. For instance,
|
||||||
@ -75,7 +75,7 @@ viewport. The editor exposes two generation modes:
|
|||||||
Concave or trimesh collision shapes
|
Concave or trimesh collision shapes
|
||||||
-----------------------------------
|
-----------------------------------
|
||||||
|
|
||||||
`Concave collision shapes <class_ConcavePolygonShape>`, also called trimesh
|
`Concave collision shapes`, also called trimesh
|
||||||
collision shapes, can take any form, from a few triangles to thousands of
|
collision shapes, can take any form, from a few triangles to thousands of
|
||||||
triangles. Concave shapes are the slowest option but are also the most accurate
|
triangles. Concave shapes are the slowest option but are also the most accurate
|
||||||
in Godot. **You can only use concave shapes within StaticBodies.** They will not
|
in Godot. **You can only use concave shapes within StaticBodies.** They will not
|
||||||
|
@ -101,8 +101,8 @@ Moving the kinematic character
|
|||||||
Go back to the character scene, and open the script, the magic begins
|
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
|
now! Kinematic body will do nothing by default, but it has a
|
||||||
useful function called
|
useful function called
|
||||||
`KinematicBody2D.move_and_collide() <class_KinematicBody2D_method_move_and_collide>`.
|
`KinematicBody2D.move_and_collide()`.
|
||||||
This function takes a `Vector2 <class_Vector2>` as
|
This function takes a `Vector2` as
|
||||||
an argument, and tries to apply that motion to the kinematic body. If a
|
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.
|
collision happens, it stops right at the moment of the collision.
|
||||||
|
|
||||||
|
@ -26,28 +26,28 @@ In this guide, you will learn:
|
|||||||
Collision objects
|
Collision objects
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
Godot offers four kinds of physics bodies, extending `CollisionObject2D <class_CollisionObject2D>`:
|
Godot offers four kinds of physics bodies, extending `CollisionObject2D`:
|
||||||
|
|
||||||
- `Area2D <class_Area2D>`
|
- `Area2D`
|
||||||
``Area2D`` nodes provide **detection** and **influence**. They can detect when
|
``Area2D`` nodes provide **detection** and **influence**. They can detect when
|
||||||
objects overlap and can emit signals when bodies enter or exit. An ``Area2D``
|
objects overlap and can emit signals when bodies enter or exit. An ``Area2D``
|
||||||
can also be used to override physics properties, such as gravity or damping,
|
can also be used to override physics properties, such as gravity or damping,
|
||||||
in a defined area.
|
in a defined area.
|
||||||
|
|
||||||
The other three bodies extend `PhysicsBody2D <class_PhysicsBody2D>`:
|
The other three bodies extend `PhysicsBody2D`:
|
||||||
|
|
||||||
- `StaticBody2D <class_StaticBody2D>`
|
- `StaticBody2D`
|
||||||
A static body is one that is not moved by the physics engine. It participates
|
A static body is one that is not moved by the physics engine. It participates
|
||||||
in collision detection, but does not move in response to the collision. They
|
in collision detection, but does not move in response to the collision. They
|
||||||
are most often used for objects that are part of the environment or that do
|
are most often used for objects that are part of the environment or that do
|
||||||
not need to have any dynamic behavior.
|
not need to have any dynamic behavior.
|
||||||
|
|
||||||
- `RigidBody2D <class_RigidBody2D>`
|
- `RigidBody2D`
|
||||||
This is the node that implements simulated 2D physics. You do not control a
|
This is the node that implements simulated 2D physics. You do not control a
|
||||||
``RigidBody2D`` directly, but instead you apply forces to it (gravity, impulses,
|
``RigidBody2D`` directly, but instead you apply forces to it (gravity, impulses,
|
||||||
etc.) and the physics engine calculates the resulting movement. `Read more about using rigid bodies. <doc_rigid_body>`
|
etc.) and the physics engine calculates the resulting movement. `Read more about using rigid bodies. <doc_rigid_body>`
|
||||||
|
|
||||||
- `KinematicBody2D <class_KinematicBody2D>`
|
- `KinematicBody2D`
|
||||||
A body that provides collision detection, but no physics. All movement and
|
A body that provides collision detection, but no physics. All movement and
|
||||||
collision response must be implemented in code.
|
collision response must be implemented in code.
|
||||||
|
|
||||||
@ -61,15 +61,15 @@ and set if it's absorbent and/or rough.
|
|||||||
Collision shapes
|
Collision shapes
|
||||||
~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
A physics body can hold any number of `Shape2D <class_Shape2D>` objects
|
A physics body can hold any number of `Shape2D` objects
|
||||||
as children. These shapes are used to define the object's collision bounds
|
as children. These shapes are used to define the object's collision bounds
|
||||||
and to detect contact with other objects.
|
and to detect contact with other objects.
|
||||||
|
|
||||||
.. note:: In order to detect collisions, at least one ``Shape2D`` must be
|
.. note:: In order to detect collisions, at least one ``Shape2D`` must be
|
||||||
assigned to the object.
|
assigned to the object.
|
||||||
|
|
||||||
The most common way to assign a shape is by adding a `CollisionShape2D <class_CollisionShape2D>`
|
The most common way to assign a shape is by adding a `CollisionShape2D`
|
||||||
or `CollisionPolygon2D <class_CollisionPolygon2D>` as a child of the object.
|
or `CollisionPolygon2D` as a child of the object.
|
||||||
These nodes allow you to draw the shape directly in the editor workspace.
|
These nodes allow you to draw the shape directly in the editor workspace.
|
||||||
|
|
||||||
.. important:: Be careful to never scale your collision shapes in the editor.
|
.. important:: Be careful to never scale your collision shapes in the editor.
|
||||||
@ -89,7 +89,7 @@ of a body's state variables such as ``position`` or ``linear velocity``
|
|||||||
may not be accurate for the current frame.
|
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
|
In order to avoid this inaccuracy, any code that needs to access a body's properties should
|
||||||
be run in the `Node._physics_process() <class_Node_method__physics_process>`
|
be run in the `Node._physics_process()`
|
||||||
callback, which is called before each physics step at a constant frame rate
|
callback, which is called before each physics step at a constant frame rate
|
||||||
(60 times per second by default). This method will be passed a ``delta``
|
(60 times per second by default). This method will be passed a ``delta``
|
||||||
parameter, which is a floating-point number equal to the time passed in
|
parameter, which is a floating-point number equal to the time passed in
|
||||||
@ -185,7 +185,7 @@ objects overlap and emit signals when bodies enter or exit. Areas can also
|
|||||||
be used to override physics properties, such as gravity or damping, in a
|
be used to override physics properties, such as gravity or damping, in a
|
||||||
defined area.
|
defined area.
|
||||||
|
|
||||||
There are three main uses for `Area2D <class_Area2D>`:
|
There are three main uses for `Area2D`:
|
||||||
|
|
||||||
- Overriding physics parameters (such as gravity) in a given region.
|
- Overriding physics parameters (such as gravity) in a given region.
|
||||||
|
|
||||||
@ -216,7 +216,7 @@ RigidBody2D
|
|||||||
-----------
|
-----------
|
||||||
|
|
||||||
This is the node that implements simulated 2D physics. You do not control a
|
This is the node that implements simulated 2D physics. You do not control a
|
||||||
`RigidBody2D <class_RigidBody2D>` directly. Instead, you apply forces
|
`RigidBody2D` directly. Instead, you apply forces
|
||||||
to it and the physics engine calculates the resulting movement, including
|
to it and the physics engine calculates the resulting movement, including
|
||||||
collisions with other bodies, and collision responses, such as bouncing,
|
collisions with other bodies, and collision responses, such as bouncing,
|
||||||
rotating, etc.
|
rotating, etc.
|
||||||
@ -225,7 +225,7 @@ You can modify a rigid body's behavior via properties such as "Mass",
|
|||||||
"Friction", or "Bounce", which can be set in the Inspector.
|
"Friction", or "Bounce", which can be set in the Inspector.
|
||||||
|
|
||||||
The body's behavior is also affected by the world's properties, as set in
|
The body's behavior is also affected by the world's properties, as set in
|
||||||
`Project Settings -> Physics`, or by entering an `Area2D <class_Area2D>`
|
`Project Settings -> Physics`, or by entering an `Area2D`
|
||||||
that is overriding the global physics properties.
|
that is overriding the global physics properties.
|
||||||
|
|
||||||
When a rigid body is at rest and hasn't moved for a while, it goes to sleep.
|
When a rigid body is at rest and hasn't moved for a while, it goes to sleep.
|
||||||
@ -239,9 +239,9 @@ Rigid body modes
|
|||||||
A rigid body can be set to one of four modes:
|
A rigid body can be set to one of four modes:
|
||||||
|
|
||||||
- **Rigid** - The body behaves as a physical object. It collides with other bodies and responds to forces applied to it. This is the default mode.
|
- **Rigid** - The body behaves as a physical object. It collides with other bodies and responds to forces applied to it. This is the default mode.
|
||||||
- **Static** - The body behaves like a `StaticBody2D <class_StaticBody2D>` and does not move.
|
- **Static** - The body behaves like a `StaticBody2D` and does not move.
|
||||||
- **Character** - Similar to "Rigid" mode, but the body cannot rotate.
|
- **Character** - Similar to "Rigid" mode, but the body cannot rotate.
|
||||||
- **Kinematic** - The body behaves like a `KinematicBody2D <class_KinematicBody2D>` and must be moved by code.
|
- **Kinematic** - The body behaves like a `KinematicBody2D` and must be moved by code.
|
||||||
|
|
||||||
Using RigidBody2D
|
Using RigidBody2D
|
||||||
~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~
|
||||||
@ -255,9 +255,9 @@ automatically be calculated by the physics engine.
|
|||||||
However, if you do wish to have some control over the body, you should take
|
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
|
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 a rigid body can result in unexpected behavior. If you need to alter any
|
||||||
of the physics-related properties, you should use the `_integrate_forces() <class_RigidBody2D_method__integrate_forces>`
|
of the physics-related properties, you should use the `_integrate_forces()`
|
||||||
callback instead of ``_physics_process()``. In this callback, you have access
|
callback instead of ``_physics_process()``. In this callback, you have access
|
||||||
to the body's `Physics2DDirectBodyState <class_Physics2DDirectBodyState>`,
|
to the body's `Physics2DDirectBodyState`,
|
||||||
which allows for safely changing properties and synchronizing them with
|
which allows for safely changing properties and synchronizing them with
|
||||||
the physics engine.
|
the physics engine.
|
||||||
|
|
||||||
@ -291,7 +291,7 @@ the body and letting the physics engine calculate the resulting movement.
|
|||||||
.. note:: When a rigid body goes to sleep, the ``_integrate_forces()``
|
.. note:: When a rigid body goes to sleep, the ``_integrate_forces()``
|
||||||
function will not be called. To override this behavior, you will
|
function will not be called. To override this behavior, you will
|
||||||
need to keep the body awake by creating a collision, applying a
|
need to keep the body awake by creating a collision, applying a
|
||||||
force to it, or by disabling the `can_sleep <class_RigidBody2D_property_can_sleep>`
|
force to it, or by disabling the `can_sleep`
|
||||||
property. Be aware that this can have a negative effect on performance.
|
property. Be aware that this can have a negative effect on performance.
|
||||||
|
|
||||||
Contact reporting
|
Contact reporting
|
||||||
@ -299,19 +299,19 @@ Contact reporting
|
|||||||
|
|
||||||
By default, rigid bodies do not keep track of contacts, because this can
|
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
|
require a huge amount of memory if many bodies are in the scene. To enable
|
||||||
contact reporting, set the `contacts_reported <class_RigidBody2D_property_contacts_reported>`
|
contact reporting, set the `contacts_reported`
|
||||||
property to a non-zero value. The contacts can then be obtained via
|
property to a non-zero value. The contacts can then be obtained via
|
||||||
`Physics2DDirectBodyState.get_contact_count() <class_Physics2DDirectBodyState_method_get_contact_count>`
|
`Physics2DDirectBodyState.get_contact_count()`
|
||||||
and related functions.
|
and related functions.
|
||||||
|
|
||||||
Contact monitoring via signals can be enabled via the `contact_monitor <class_RigidBody2D_property_contact_monitor>`
|
Contact monitoring via signals can be enabled via the `contact_monitor`
|
||||||
property. See `RigidBody2D <class_RigidBody2D>` for the list of available
|
property. See `RigidBody2D` for the list of available
|
||||||
signals.
|
signals.
|
||||||
|
|
||||||
KinematicBody2D
|
KinematicBody2D
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
`KinematicBody2D <class_KinematicBody2D>` bodies detect collisions with
|
`KinematicBody2D` bodies detect collisions with
|
||||||
other bodies, but are not affected by physics properties like gravity or friction.
|
other bodies, but are not affected by physics properties like gravity or friction.
|
||||||
Instead, they must be controlled by the user via code. The physics engine will
|
Instead, they must be controlled by the user via code. The physics engine will
|
||||||
not move a kinematic body.
|
not move a kinematic body.
|
||||||
@ -329,11 +329,11 @@ 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
|
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.
|
response depends on which method you used to move the KinematicBody2D.
|
||||||
|
|
||||||
`move_and_collide <class_KinematicBody2D_method_move_and_collide>`
|
`move_and_collide`
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
When using ``move_and_collide()``, the function returns a
|
When using ``move_and_collide()``, the function returns a
|
||||||
`KinematicCollision2D <class_KinematicCollision2D>` object, which contains
|
`KinematicCollision2D` object, which contains
|
||||||
information about the collision and the colliding body. You can use this
|
information about the collision and the colliding body. You can use this
|
||||||
information to determine the response.
|
information to determine the response.
|
||||||
|
|
||||||
@ -368,7 +368,7 @@ gdscript GDScript
|
|||||||
velocity = velocity.bounce(collision_info.normal)
|
velocity = velocity.bounce(collision_info.normal)
|
||||||
```
|
```
|
||||||
|
|
||||||
`move_and_slide <class_KinematicBody2D_method_move_and_slide>`
|
`move_and_slide`
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
Sliding is a common collision response; imagine a player moving along walls
|
Sliding is a common collision response; imagine a player moving along walls
|
||||||
|
@ -18,7 +18,7 @@ Setting up the ragdoll
|
|||||||
Creating physical bones
|
Creating physical bones
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
Like many other features in the engine, there is a node to set up a ragdoll: the `PhysicalBone <class_PhysicalBone>` node. To simplify the setup, you can generate ``PhysicalBone`` nodes with the "Create physical skeleton" feature in the skeleton node.
|
Like many other features in the engine, there is a node to set up a ragdoll: the `PhysicalBone` node. To simplify the setup, you can generate ``PhysicalBone`` nodes with the "Create physical skeleton" feature in the skeleton node.
|
||||||
|
|
||||||
Open the platformer demo in Godot, and then the Robi scene. Select the ``Skeleton`` node. A skeleton button appears on the top bar menu:
|
Open the platformer demo in Godot, and then the Robi scene. Select the ``Skeleton`` node. A skeleton button appears on the top bar menu:
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ do this in 2D and 3D.
|
|||||||
Godot stores all the low level game information in servers, while the
|
Godot stores all the low level game information in servers, while the
|
||||||
scene is just a frontend. As such, ray casting is generally a
|
scene is just a frontend. As such, ray casting is generally a
|
||||||
lower-level task. For simple raycasts, node such as
|
lower-level task. For simple raycasts, node such as
|
||||||
`RayCast <class_RayCast>` and `RayCast2D <class_RayCast2D>`
|
`RayCast`
|
||||||
will work, as they will return every frame what the result of a raycast
|
will work, as they will return every frame what the result of a raycast
|
||||||
is.
|
is.
|
||||||
|
|
||||||
@ -27,12 +27,12 @@ Space
|
|||||||
In the physics world, Godot stores all the low level collision and
|
In the physics world, Godot stores all the low level collision and
|
||||||
physics information in a *space*. The current 2d space (for 2D Physics)
|
physics information in a *space*. The current 2d space (for 2D Physics)
|
||||||
can be obtained by accessing
|
can be obtained by accessing
|
||||||
`CanvasItem.get_world_2d().space <class_CanvasItem_method_get_world_2d>`.
|
`CanvasItem.get_world_2d().space`.
|
||||||
For 3D, it's `Spatial.get_world().space <class_Spatial_method_get_world>`.
|
For 3D, it's `Spatial.get_world().space`.
|
||||||
|
|
||||||
The resulting space `RID <class_RID>` can be used in
|
The resulting space `RID` can be used in
|
||||||
`PhysicsServer <class_PhysicsServer>` and
|
`PhysicsServer` and
|
||||||
`Physics2DServer <class_Physics2DServer>` respectively for 3D and 2D.
|
`Physics2DServer` respectively for 3D and 2D.
|
||||||
|
|
||||||
Accessing space
|
Accessing space
|
||||||
---------------
|
---------------
|
||||||
@ -40,13 +40,13 @@ Accessing space
|
|||||||
Godot physics runs by default in the same thread as game logic, but may
|
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
|
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
|
this, the only time accessing space is safe is during the
|
||||||
`Node._physics_process() <class_Node_method__physics_process>`
|
`Node._physics_process()`
|
||||||
callback. Accessing it from outside this function may result in an error
|
callback. Accessing it from outside this function may result in an error
|
||||||
due to space being *locked*.
|
due to space being *locked*.
|
||||||
|
|
||||||
To perform queries into physics space, the
|
To perform queries into physics space, the
|
||||||
`Physics2DDirectSpaceState <class_Physics2DDirectSpaceState>`
|
`Physics2DDirectSpaceState`
|
||||||
and `PhysicsDirectSpaceState <class_PhysicsDirectSpaceState>`
|
and `PhysicsDirectSpaceState`
|
||||||
must be used.
|
must be used.
|
||||||
|
|
||||||
Use the following code in 2D:
|
Use the following code in 2D:
|
||||||
@ -81,7 +81,7 @@ Raycast query
|
|||||||
-------------
|
-------------
|
||||||
|
|
||||||
For performing a 2D raycast query, the method
|
For performing a 2D raycast query, the method
|
||||||
`Physics2DDirectSpaceState.intersect_ray() <class_Physics2DDirectSpaceState_method_intersect_ray>`
|
`Physics2DDirectSpaceState.intersect_ray()`
|
||||||
may be used. For example:
|
may be used. For example:
|
||||||
|
|
||||||
gdscript GDScript
|
gdscript GDScript
|
||||||
@ -176,11 +176,11 @@ See `doc_physics_introduction_collision_layer_code_example` for details on how t
|
|||||||
|
|
||||||
Casting a ray from screen to 3D physics space is useful for object
|
Casting a ray from screen to 3D physics space is useful for object
|
||||||
picking. There is not much need to do this because
|
picking. There is not much need to do this because
|
||||||
`CollisionObject <class_CollisionObject>`
|
`CollisionObject`
|
||||||
has an "input_event" signal that will let you know when it was clicked,
|
has an "input_event" signal that will let you know when it was clicked,
|
||||||
but in case there is any desire to do it manually, here's how.
|
but in case there is any desire to do it manually, here's how.
|
||||||
|
|
||||||
To cast a ray from the screen, you need a `Camera <class_Camera>`
|
To cast a ray from the screen, you need a `Camera`
|
||||||
node. A ``Camera`` can be in two projection modes: perspective and
|
node. A ``Camera`` can be in two projection modes: perspective and
|
||||||
orthogonal. Because of this, both the ray origin and direction must be
|
orthogonal. Because of this, both the ray origin and direction must be
|
||||||
obtained. This is because ``origin`` changes in orthogonal mode, while
|
obtained. This is because ``origin`` changes in orthogonal mode, while
|
||||||
|
@ -7,7 +7,7 @@ What is a rigid body?
|
|||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
A rigid body is one that is directly controlled by the physics engine in order to simulate the behavior of physical objects.
|
A rigid body is one that is directly controlled by the physics engine in order to simulate the behavior of physical objects.
|
||||||
In order to define the shape of the body, it must have one or more `Shape <class_Shape>` objects assigned. Note that setting the position of these shapes will affect the body's center of mass.
|
In order to define the shape of the body, it must have one or more `Shape` objects assigned. Note that setting the position of these shapes will affect the body's center of mass.
|
||||||
|
|
||||||
How to control a rigid body
|
How to control a rigid body
|
||||||
---------------------------
|
---------------------------
|
||||||
@ -15,12 +15,12 @@ How to control a rigid body
|
|||||||
A rigid body's behavior can be altered by setting its properties, such as mass and weight.
|
A rigid body's behavior can be altered by setting its properties, such as mass and weight.
|
||||||
A physics material needs to be added to the rigid body to adjust its friction and bounce,
|
A physics material needs to be added to the rigid body to adjust its friction and bounce,
|
||||||
and set if it's absorbent and/or rough. These properties can be set in the Inspector or via code.
|
and set if it's absorbent and/or rough. These properties can be set in the Inspector or via code.
|
||||||
See `RigidBody <class_RigidBody>` and `PhysicsMaterial <class_PhysicsMaterial>` for
|
See `RigidBody` for
|
||||||
the full list of properties and their effects.
|
the full list of properties and their effects.
|
||||||
|
|
||||||
There are several ways to control a rigid body's movement, depending on your desired application.
|
There are several ways to control a rigid body's movement, depending on your desired application.
|
||||||
|
|
||||||
If you only need to place a rigid body once, for example to set its initial location, you can use the methods provided by the `Spatial <class_Spatial>` node, such as ``set_global_transform()`` or ``look_at()``. However, these methods cannot be called every frame or the physics engine will not be able to correctly simulate the body's state.
|
If you only need to place a rigid body once, for example to set its initial location, you can use the methods provided by the `Spatial` node, such as ``set_global_transform()`` or ``look_at()``. However, these methods cannot be called every frame or the physics engine will not be able to correctly simulate the body's state.
|
||||||
As an example, consider a rigid body that you want to rotate so that it points towards another object. A common mistake when implementing this kind of behavior is to use ``look_at()`` every frame, which breaks the physics simulation. Below, we'll demonstrate how to implement this correctly.
|
As an example, consider a rigid body that you want to rotate so that it points towards another object. A common mistake when implementing this kind of behavior is to use ``look_at()`` every frame, which breaks the physics simulation. Below, we'll demonstrate how to implement this correctly.
|
||||||
|
|
||||||
The fact that you can't use ``set_global_transform()`` or ``look_at()`` methods doesn't mean that you can't have full control of a rigid body. Instead, you can control it by using the ``_integrate_forces()`` callback. In this method, you can add *forces*, apply *impulses*, or set the *velocity* in order to achieve any movement you desire.
|
The fact that you can't use ``set_global_transform()`` or ``look_at()`` methods doesn't mean that you can't have full control of a rigid body. Instead, you can control it by using the ``_integrate_forces()`` callback. In this method, you can add *forces*, apply *impulses*, or set the *velocity* in order to achieve any movement you desire.
|
||||||
|
@ -9,7 +9,7 @@ This can for example be used to simulate cloth or to create more realistic chara
|
|||||||
Basic set-up
|
Basic set-up
|
||||||
~~~~~~~~~~~~
|
~~~~~~~~~~~~
|
||||||
|
|
||||||
A `SoftBody <class_SoftBody>` node is used for soft body simulations.
|
A `SoftBody` node is used for soft body simulations.
|
||||||
|
|
||||||
We will create a bouncy cube to demonstrate the setup of a soft body.
|
We will create a bouncy cube to demonstrate the setup of a soft body.
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ Open the ``PlaneMesh`` properties and set the size(x: 0.5 y: 1) then set ``Subdi
|
|||||||
|
|
||||||
.. tip:: Subdivision generates a more tessellated mesh for better simulations.
|
.. tip:: Subdivision generates a more tessellated mesh for better simulations.
|
||||||
|
|
||||||
Add a `BoneAttachment <class_BoneAttachment>` node under the skeleton node and select the Neck bone to attach the cloak to the character skeleton.
|
Add a `BoneAttachment` node under the skeleton node and select the Neck bone to attach the cloak to the character skeleton.
|
||||||
|
|
||||||
.. note:: ``BoneAttachment`` node is to attach objects to a bone of a armature. The attached object will follow the bone's movement, weapon of a character can be attached this way.
|
.. note:: ``BoneAttachment`` node is to attach objects to a bone of a armature. The attached object will follow the bone's movement, weapon of a character can be attached this way.
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ Godot offers a number of collision objects to provide both collision detection
|
|||||||
and response. Trying to decide which one to use for your project can be confusing.
|
and response. Trying to decide which one to use for your project can be confusing.
|
||||||
You can avoid problems and simplify development if you understand how each of them
|
You can avoid problems and simplify development if you understand how each of them
|
||||||
works and what their pros and cons are. In this tutorial, we'll look at the
|
works and what their pros and cons are. In this tutorial, we'll look at the
|
||||||
`Area2D <class_Area2D>` node and show some examples of how it can be used.
|
`Area2D` node and show some examples of how it can be used.
|
||||||
|
|
||||||
.. note:: This document assumes you're familiar with Godot's various physics
|
.. note:: This document assumes you're familiar with Godot's various physics
|
||||||
bodies. Please read `doc_physics_introduction` first.
|
bodies. Please read `doc_physics_introduction` first.
|
||||||
@ -19,7 +19,7 @@ What is an area?
|
|||||||
----------------
|
----------------
|
||||||
|
|
||||||
An Area2D defines a region of 2D space. In this space you can detect other
|
An Area2D defines a region of 2D space. In this space you can detect other
|
||||||
`CollisionObject2D <class_CollisionObject2D>` nodes overlapping, entering,
|
`CollisionObject2D` nodes overlapping, entering,
|
||||||
and exiting. Areas also allow for overriding local physics properties. We'll
|
and exiting. Areas also allow for overriding local physics properties. We'll
|
||||||
explore each of these functions below.
|
explore each of these functions below.
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ and mask(s).
|
|||||||
The "Audio Bus" section allows you to override audio in the area, for example to
|
The "Audio Bus" section allows you to override audio in the area, for example to
|
||||||
apply an audio effect when the player moves through.
|
apply an audio effect when the player moves through.
|
||||||
|
|
||||||
Note that Area2D extends `CollisionObject2D <class_CollisionObject2D>`, so it
|
Note that Area2D extends `CollisionObject2D`, so it
|
||||||
also provides properties inherited from that class, such as ``input_pickable``.
|
also provides properties inherited from that class, such as ``input_pickable``.
|
||||||
|
|
||||||
Overlap detection
|
Overlap detection
|
||||||
|
@ -10,7 +10,7 @@ Godot offers several collision objects to provide both collision detection
|
|||||||
and response. Trying to decide which one to use for your project can be confusing.
|
and response. Trying to decide which one to use for your project can be confusing.
|
||||||
You can avoid problems and simplify development if you understand how each of them
|
You can avoid problems and simplify development if you understand how each of them
|
||||||
works and what their pros and cons are. In this tutorial, we'll look at the
|
works and what their pros and cons are. In this tutorial, we'll look at the
|
||||||
`KinematicBody2D <class_KinematicBody2D>` node and show some examples
|
`KinematicBody2D` node and show some examples
|
||||||
of how to use it.
|
of how to use it.
|
||||||
|
|
||||||
.. note:: This document assumes you're familiar with Godot's various physics
|
.. note:: This document assumes you're familiar with Godot's various physics
|
||||||
@ -46,11 +46,11 @@ see examples of how they work.
|
|||||||
``move_and_collide``
|
``move_and_collide``
|
||||||
~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
This method takes one parameter: a `Vector2 <class_Vector2>` indicating the body's
|
This method takes one parameter: a `Vector2` indicating the body's
|
||||||
relative movement. Typically, this is your velocity vector multiplied by the
|
relative movement. Typically, this is your velocity vector multiplied by the
|
||||||
frame timestep (``delta``). If the engine detects a collision anywhere along
|
frame timestep (``delta``). If the engine detects a collision anywhere along
|
||||||
this vector, the body will immediately stop moving. If this happens, the
|
this vector, the body will immediately stop moving. If this happens, the
|
||||||
method will return a `KinematicCollision2D <class_KinematicCollision2D>` object.
|
method will return a `KinematicCollision2D` object.
|
||||||
|
|
||||||
``KinematicCollision2D`` is an object containing data about the collision
|
``KinematicCollision2D`` is an object containing data about the collision
|
||||||
and the colliding object. Using this data, you can calculate your collision
|
and the colliding object. Using this data, you can calculate your collision
|
||||||
@ -92,7 +92,7 @@ other parameters allowing you to customize the slide behavior:
|
|||||||
|
|
||||||
- ``infinite_inertia`` - *default value:* ``true``
|
- ``infinite_inertia`` - *default value:* ``true``
|
||||||
|
|
||||||
When this parameter is ``true``, the body can push `RigidBody2D <class_RigidBody2D>`
|
When this parameter is ``true``, the body can push `RigidBody2D`
|
||||||
nodes, ignoring their mass, but won't detect collisions with them. If it's ``false``
|
nodes, ignoring their mass, but won't detect collisions with them. If it's ``false``
|
||||||
the body will collide with rigid bodies and stop.
|
the body will collide with rigid bodies and stop.
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ gdscript GDScript
|
|||||||
|
|
||||||
.. note:: `get_slide_count()` only counts times the body has collided and changed direction.
|
.. note:: `get_slide_count()` only counts times the body has collided and changed direction.
|
||||||
|
|
||||||
See `KinematicCollision2D <class_KinematicCollision2D>` for details on what
|
See `KinematicCollision2D` for details on what
|
||||||
collision data is returned.
|
collision data is returned.
|
||||||
|
|
||||||
Which movement method to use?
|
Which movement method to use?
|
||||||
@ -229,7 +229,7 @@ gdscript GDScript
|
|||||||
|
|
||||||
Run this scene and you'll see that ``move_and_collide()`` works as expected, moving
|
Run this scene and you'll see that ``move_and_collide()`` works as expected, moving
|
||||||
the body along the velocity vector. Now let's see what happens when you add
|
the body along the velocity vector. Now let's see what happens when you add
|
||||||
some obstacles. Add a `StaticBody2D <class_StaticBody2D>` with a
|
some obstacles. Add a `StaticBody2D` with a
|
||||||
rectangular collision shape. For visibility, you can use a sprite, a
|
rectangular collision shape. For visibility, you can use a sprite, a
|
||||||
Polygon2D, or turn on "Visible Collision Shapes" from the "Debug" menu.
|
Polygon2D, or turn on "Visible Collision Shapes" from the "Debug" menu.
|
||||||
|
|
||||||
@ -344,7 +344,7 @@ If you've downloaded the sample project, you can find this in "Platformer.tscn".
|
|||||||
|
|
||||||
For this example, we'll assume you have a level made of ``StaticBody2D`` objects.
|
For this example, we'll assume you have a level made of ``StaticBody2D`` objects.
|
||||||
They can be any shape and size. In the sample project, we're using
|
They can be any shape and size. In the sample project, we're using
|
||||||
`Polygon2D <class_Polygon2D>` to create the platform shapes.
|
`Polygon2D` to create the platform shapes.
|
||||||
|
|
||||||
Here's the code for the player body:
|
Here's the code for the player body:
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ Check if the user purchased an item
|
|||||||
***********************************
|
***********************************
|
||||||
|
|
||||||
To get all purchases, call ``queryPurchases``. Unlike most of the other functions, ``queryPurchases`` is
|
To get all purchases, call ``queryPurchases``. Unlike most of the other functions, ``queryPurchases`` is
|
||||||
a synchronous operation and returns a `Dictionary <class_Dictionary>` with a status code
|
a synchronous operation and returns a `Dictionary` with a status code
|
||||||
and either an array of purchases or an error message. Only active subscriptions and non-consumed one-time purchases are returned.
|
and either an array of purchases or an error message. Only active subscriptions and non-consumed one-time purchases are returned.
|
||||||
|
|
||||||
Full example:
|
Full example:
|
||||||
|
@ -148,7 +148,7 @@ allows to test for a specific major version of WebGL.
|
|||||||
|
|
||||||
As the real executable file does not exist in the Web environment, the engine only stores a virtual
|
As the real executable file does not exist in the Web environment, the engine only stores a virtual
|
||||||
filename formed from the base name of loaded engine files. This value affects the output of the
|
filename formed from the base name of loaded engine files. This value affects the output of the
|
||||||
`OS.get_executable_path() <class_OS_method_get_executable_path>` method and defines the name of
|
`OS.get_executable_path()` method and defines the name of
|
||||||
the automatically started main pack. The :js:attr:`executable` override option can be
|
the automatically started main pack. The :js:attr:`executable` override option can be
|
||||||
used to override this value.
|
used to override this value.
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ The following project settings have mobile-specific overrides:
|
|||||||
| *GLES3 only:* ``rendering/quality/reflections/texture_array_reflections`` | ``true`` | ``false`` |
|
| *GLES3 only:* ``rendering/quality/reflections/texture_array_reflections`` | ``true`` | ``false`` |
|
||||||
+---------------------------------------------------------------------------+-----------------+--------------------+
|
+---------------------------------------------------------------------------+-----------------+--------------------+
|
||||||
|
|
||||||
See the `ProjectSettings class documentation <class_ProjectSettings>`
|
See the `ProjectSettings class documentation`
|
||||||
for more information on those setting overrides.
|
for more information on those setting overrides.
|
||||||
|
|
||||||
If you're only targeting mobile platforms in your project, consider changing the
|
If you're only targeting mobile platforms in your project, consider changing the
|
||||||
|
@ -66,10 +66,10 @@ when needed:
|
|||||||
|
|
||||||
When this plugin is activated, it will create a new instance of the import
|
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
|
plugin (which we'll soon make) and add it to the editor using the
|
||||||
`add_import_plugin() <class_EditorPlugin_method_add_import_plugin>` method. We store
|
`add_import_plugin()` method. We store
|
||||||
a reference to it in a class member ``import_plugin`` so we can refer to it
|
a reference to it in a class member ``import_plugin`` so we can refer to it
|
||||||
later when removing it. The
|
later when removing it. The
|
||||||
`remove_import_plugin() <class_EditorPlugin_method_remove_import_plugin>` method is
|
`remove_import_plugin()` method is
|
||||||
called when the plugin is deactivated to clean up the memory and let the editor
|
called when the plugin is deactivated to clean up the memory and let the editor
|
||||||
know the import plugin isn't available anymore.
|
know the import plugin isn't available anymore.
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ The EditorImportPlugin class
|
|||||||
----------------------------
|
----------------------------
|
||||||
|
|
||||||
The main character of the show is the
|
The main character of the show is the
|
||||||
`EditorImportPlugin class <class_EditorImportPlugin>`. It is responsible for
|
`EditorImportPlugin class`. It is responsible for
|
||||||
implementing the methods that are called by Godot when it needs to know how to deal
|
implementing the methods that are called by Godot when it needs to know how to deal
|
||||||
with files.
|
with files.
|
||||||
|
|
||||||
@ -196,7 +196,7 @@ plugin:
|
|||||||
func get_preset_count():
|
func get_preset_count():
|
||||||
return Presets.size()
|
return Presets.size()
|
||||||
|
|
||||||
The `get_preset_count() <class_EditorImportPlugin_method_get_preset_count>` method
|
The `get_preset_count()` method
|
||||||
returns the amount of presets that this plugins defines. We only have one preset
|
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
|
now, but we can make this method future-proof by returning the size of our
|
||||||
``Presets`` enumeration.
|
``Presets`` enumeration.
|
||||||
@ -212,7 +212,7 @@ now, but we can make this method future-proof by returning the size of our
|
|||||||
|
|
||||||
|
|
||||||
Here we have the
|
Here we have the
|
||||||
`get_preset_name() <class_EditorImportPlugin_method_get_preset_name>` method, which
|
`get_preset_name()` method, which
|
||||||
gives names to the presets as they will be presented to the user, so be sure to
|
gives names to the presets as they will be presented to the user, so be sure to
|
||||||
use short and clear names.
|
use short and clear names.
|
||||||
|
|
||||||
@ -237,7 +237,7 @@ you do this you have to be careful when you add more presets.
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
This is the method which defines the available options.
|
This is the method which defines the available options.
|
||||||
`get_import_options() <class_EditorImportPlugin_method_get_import_options>` returns
|
`get_import_options()` returns
|
||||||
an array of dictionaries, and each dictionary contains a few keys that are
|
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
|
checked to customize the option as its shown to the user. The following table
|
||||||
shows the possible keys:
|
shows the possible keys:
|
||||||
@ -275,7 +275,7 @@ of options first and then change it based on the preset.
|
|||||||
return true
|
return true
|
||||||
|
|
||||||
For the
|
For the
|
||||||
`get_option_visibility() <class_EditorImportPlugin_method_get_option_visibility>`
|
`get_option_visibility()`
|
||||||
method, we simply return ``true`` because all of our options (i.e. the single
|
method, we simply return ``true`` because all of our options (i.e. the single
|
||||||
one we defined) are visible all the time.
|
one we defined) are visible all the time.
|
||||||
|
|
||||||
@ -286,7 +286,7 @@ The ``import`` method
|
|||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
The heavy part of the process, responsible for converting the files into
|
The heavy part of the process, responsible for converting the files into
|
||||||
resources, is covered by the `import() <class_EditorImportPlugin_method_import>`
|
resources, is covered by the `import()`
|
||||||
method. Our sample code is a bit long, so let's split in a few parts:
|
method. Our sample code is a bit long, so let's split in a few parts:
|
||||||
|
|
||||||
::
|
::
|
||||||
@ -302,7 +302,7 @@ method. Our sample code is a bit long, so let's split in a few parts:
|
|||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
The first part of our import method opens and reads the source file. We use the
|
The first part of our import method opens and reads the source file. We use the
|
||||||
`File <class_File>` class to do that, passing the ``source_file``
|
`File` class to do that, passing the ``source_file``
|
||||||
parameter which is provided by the editor.
|
parameter which is provided by the editor.
|
||||||
|
|
||||||
If there's an error when opening the file, we return it to let the editor know
|
If there's an error when opening the file, we return it to let the editor know
|
||||||
@ -324,7 +324,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,
|
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.
|
it considers the file invalid and reports an error.
|
||||||
|
|
||||||
Then it creates a new `Color <class_Color>` variable and sets its values
|
Then it creates a new `Color` variable and sets its values
|
||||||
according to the input file. If the ``use_red_anyway`` option is enabled, then
|
according to the input file. If the ``use_red_anyway`` option is enabled, then
|
||||||
it sets the color as a pure red instead.
|
it sets the color as a pure red instead.
|
||||||
|
|
||||||
@ -333,7 +333,7 @@ it sets the color as a pure red instead.
|
|||||||
var material = SpatialMaterial.new()
|
var material = SpatialMaterial.new()
|
||||||
material.albedo_color = color
|
material.albedo_color = color
|
||||||
|
|
||||||
This part makes a new `SpatialMaterial <class_SpatialMaterial>` that is the
|
This part makes a new `SpatialMaterial` that is the
|
||||||
imported resource. We create a new instance of it and then set its albedo color
|
imported resource. We create a new instance of it and then set its albedo color
|
||||||
as the value we got before.
|
as the value we got before.
|
||||||
|
|
||||||
@ -349,7 +349,7 @@ 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.
|
can be sure that they won't get out of sync.
|
||||||
|
|
||||||
We also return the result from the
|
We also return the result from the
|
||||||
`ResourceSaver.save() <class_ResourceSaver_method_save>` method, so if there's an
|
`ResourceSaver.save()` method, so if there's an
|
||||||
error in this step, the editor will know about it.
|
error in this step, the editor will know about it.
|
||||||
|
|
||||||
Platform variants and generated files
|
Platform variants and generated files
|
||||||
|
@ -91,8 +91,8 @@ editor, and it must inherit from `class_EditorPlugin`.
|
|||||||
|
|
||||||
It's important to deal with initialization and clean-up of resources.
|
It's important to deal with initialization and clean-up of resources.
|
||||||
A good practice is to use the virtual function
|
A good practice is to use the virtual function
|
||||||
`_enter_tree() <class_Node_method__enter_tree>` to initialize your plugin and
|
`_enter_tree()` to initialize your plugin and
|
||||||
`_exit_tree() <class_Node_method__exit_tree>` to clean it up. Thankfully,
|
`_exit_tree()` to clean it up. Thankfully,
|
||||||
the dialog generates these callbacks for you. Your script should look something
|
the dialog generates these callbacks for you. Your script should look something
|
||||||
like this:
|
like this:
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ custom behavior.
|
|||||||
are writing GDScript or NativeScript, we recommend using Script Classes instead.
|
are writing GDScript or NativeScript, we recommend using Script Classes instead.
|
||||||
|
|
||||||
To create a new node type, you can use the function
|
To create a new node type, you can use the function
|
||||||
`add_custom_type() <class_EditorPlugin_method_add_custom_type>` from the
|
`add_custom_type()` from the
|
||||||
`class_EditorPlugin` class. This function can add new types to the editor
|
`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
|
(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
|
that will act as the logic for the type. While that script doesn't have to use
|
||||||
@ -234,7 +234,7 @@ Since we're trying to add a new custom dock, we need to create the contents of
|
|||||||
the dock. This is nothing more than a standard Godot scene: just create
|
the dock. This is nothing more than a standard Godot scene: just create
|
||||||
a new scene in the editor then edit it.
|
a new scene in the editor then edit it.
|
||||||
|
|
||||||
For an editor dock, the root node **must** be a `Control <class_Control>`
|
For an editor dock, the root node **must** be a `Control`
|
||||||
or one of its child classes. For this tutorial, you can create a single button.
|
or one of its child classes. For this tutorial, you can create a single button.
|
||||||
The name of the root node will also be the name that appears on the dock tab,
|
The name of the root node will also be the name that appears on the dock tab,
|
||||||
so be sure to give it a short and descriptive name.
|
so be sure to give it a short and descriptive name.
|
||||||
@ -244,8 +244,8 @@ 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
|
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
|
then add it as a dock in the editor. For this, you can rely on the function
|
||||||
`add_control_to_dock() <class_EditorPlugin_method_add_control_to_dock>` from the
|
`add_control_to_dock()` from the
|
||||||
`EditorPlugin <class_EditorPlugin>` class.
|
`EditorPlugin` class.
|
||||||
|
|
||||||
You need to select a dock position and define the control to add
|
You need to select a dock position and define the control to add
|
||||||
(which is the scene you just created). Don't forget to
|
(which is the scene you just created). Don't forget to
|
||||||
|
@ -20,7 +20,7 @@ The EditorSpatialGizmoPlugin
|
|||||||
----------------------------
|
----------------------------
|
||||||
|
|
||||||
Regardless of the approach we choose, we will need to create a new
|
Regardless of the approach we choose, we will need to create a new
|
||||||
`EditorSpatialGizmoPlugin <class_EditorSpatialGizmoPlugin>`. This will allow
|
`EditorSpatialGizmoPlugin`. This will allow
|
||||||
us to set a name for the new gizmo type and define other behaviors such as whether
|
us to set a name for the new gizmo type and define other behaviors such as whether
|
||||||
the gizmo can be hidden or not.
|
the gizmo can be hidden or not.
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ This would be a basic setup:
|
|||||||
remove_spatial_gizmo_plugin(gizmo_plugin)
|
remove_spatial_gizmo_plugin(gizmo_plugin)
|
||||||
|
|
||||||
|
|
||||||
For simple gizmos, just inheriting `EditorSpatialGizmoPlugin <class_EditorSpatialGizmoPlugin>`
|
For simple gizmos, just inheriting `EditorSpatialGizmoPlugin`
|
||||||
is enough. If you want to store some per-gizmo data or you are porting a Godot 3.0 gizmo
|
is enough. If you want to store some per-gizmo data or you are porting a Godot 3.0 gizmo
|
||||||
to 3.1+, you should go with the second approach.
|
to 3.1+, you should go with the second approach.
|
||||||
|
|
||||||
@ -159,7 +159,7 @@ So the final plugin would look somewhat like this:
|
|||||||
# (get_handle_name(), get_handle_value(), commit_handle()...).
|
# (get_handle_name(), get_handle_value(), commit_handle()...).
|
||||||
|
|
||||||
Note that we just added some handles in the redraw method, but we still need to implement
|
Note that we just added some handles in the redraw method, but we still need to implement
|
||||||
the rest of handle-related callbacks in `EditorSpatialGizmoPlugin <class_EditorSpatialGizmoPlugin>`
|
the rest of handle-related callbacks in `EditorSpatialGizmoPlugin`
|
||||||
to get properly working handles.
|
to get properly working handles.
|
||||||
|
|
||||||
Alternative approach
|
Alternative approach
|
||||||
|
@ -136,10 +136,10 @@ Instancing scenes
|
|||||||
|
|
||||||
You can instantiate packed scenes normally and add them to the scene currently
|
You can instantiate packed scenes normally and add them to the scene currently
|
||||||
opened in the editor. By default, nodes or scenes added with
|
opened in the editor. By default, nodes or scenes added with
|
||||||
`Node.add_child(node) <class_Node_method_add_child>` are **not** visible
|
`Node.add_child(node)` are **not** visible
|
||||||
in the Scene tree dock and are **not** persisted to disk. If you wish the node
|
in the Scene tree dock and are **not** persisted to disk. If you wish the node
|
||||||
or scene to be visible in the scene tree dock and persisted to disk when saving
|
or scene to be visible in the scene tree dock and persisted to disk when saving
|
||||||
the scene, you need to set the child node's `owner <class_Node_property_owner>`
|
the scene, you need to set the child node's `owner`
|
||||||
property to the currently edited scene root.
|
property to the currently edited scene root.
|
||||||
|
|
||||||
If you are using ``tool``:
|
If you are using ``tool``:
|
||||||
|
@ -90,7 +90,7 @@ Resizing
|
|||||||
There are several types of devices, with several types of screens, which
|
There are several types of devices, with several types of screens, which
|
||||||
in turn have different pixel density and resolutions. Handling all of
|
in turn have different pixel density and resolutions. Handling all of
|
||||||
them can be a lot of work, so Godot tries to make the developer's life a
|
them can be a lot of work, so Godot tries to make the developer's life a
|
||||||
little easier. The `Viewport <class_Viewport>`
|
little easier. The `Viewport`
|
||||||
node has several functions to handle resizing, and the root node of the
|
node has several functions to handle resizing, and the root node of the
|
||||||
scene tree is always a viewport (scenes loaded are instanced as a child
|
scene tree is always a viewport (scenes loaded are instanced as a child
|
||||||
of it, and it can always be accessed by calling
|
of it, and it can always be accessed by calling
|
||||||
@ -119,7 +119,7 @@ the resolution of the window or screen.
|
|||||||
The animations below use a "base size" of just 16×9 pixels to
|
The animations below use a "base size" of just 16×9 pixels to
|
||||||
demonstrate the effect of different stretch modes. A single sprite, also
|
demonstrate the effect of different stretch modes. A single sprite, also
|
||||||
16×9 pixels in size, covers the entire viewport, and a diagonal
|
16×9 pixels in size, covers the entire viewport, and a diagonal
|
||||||
`Line2D <class_Line2D>` is added on top of it:
|
`Line2D` is added on top of it:
|
||||||
|
|
||||||
.. image:: img/stretch_demo_scene.png
|
.. image:: img/stretch_demo_scene.png
|
||||||
|
|
||||||
@ -143,7 +143,7 @@ demonstrate the effect of different stretch modes. A single sprite, also
|
|||||||
.. image:: img/stretch_2d_expand.gif
|
.. image:: img/stretch_2d_expand.gif
|
||||||
|
|
||||||
- **Stretch Mode = Viewport**: Viewport scaling means that the size of
|
- **Stretch Mode = Viewport**: Viewport scaling means that the size of
|
||||||
the root `Viewport <class_Viewport>` is set precisely to the
|
the root `Viewport` is set precisely to the
|
||||||
base size specified in the Project Settings' **Display** section.
|
base size specified in the Project Settings' **Display** section.
|
||||||
The scene is rendered to this viewport first. Finally, this viewport
|
The scene is rendered to this viewport first. Finally, this viewport
|
||||||
is scaled to fit the screen (taking the **Stretch Aspect** setting into
|
is scaled to fit the screen (taking the **Stretch Aspect** setting into
|
||||||
@ -250,7 +250,7 @@ From scripts
|
|||||||
|
|
||||||
To configure stretching at runtime from a script, use the
|
To configure stretching at runtime from a script, use the
|
||||||
``get_tree().set_screen_stretch()`` method (see
|
``get_tree().set_screen_stretch()`` method (see
|
||||||
`SceneTree.set_screen_stretch() <class_SceneTree_method_set_screen_stretch>`).
|
`SceneTree.set_screen_stretch()`).
|
||||||
|
|
||||||
Common use case scenarios
|
Common use case scenarios
|
||||||
-------------------------
|
-------------------------
|
||||||
|
@ -6,23 +6,23 @@ Using Viewports
|
|||||||
Introduction
|
Introduction
|
||||||
------------
|
------------
|
||||||
|
|
||||||
Think of a `Viewport <class_Viewport>` as a screen onto which the game is projected. In order
|
Think of a `Viewport` as a screen onto which the game is projected. In order
|
||||||
to see the game, we need to have a surface on which to draw it; that surface is
|
to see the game, we need to have a surface on which to draw it; that surface is
|
||||||
the Root `Viewport <class_Viewport>`.
|
the Root `Viewport`.
|
||||||
|
|
||||||
.. image:: img/viewportnode.png
|
.. image:: img/viewportnode.png
|
||||||
|
|
||||||
|
|
||||||
`Viewports <class_Viewport>` can also be added to the scene so that there
|
`Viewports` can also be added to the scene so that there
|
||||||
are multiple surfaces to draw on. When we are drawing to a `Viewport <class_Viewport>`
|
are multiple surfaces to draw on. When we are drawing to a `Viewport`
|
||||||
that is not the Root, we call it a render target. We can access the contents
|
that is not the Root, we call it a render target. We can access the contents
|
||||||
of a render target by accessing its corresponding `texture <class_ViewportTexture>`.
|
of a render target by accessing its corresponding `texture`.
|
||||||
By using a `Viewport <class_Viewport>` as a render target,
|
By using a `Viewport` as a render target,
|
||||||
we can either render multiple scenes simultaneously or we can render to
|
we can either render multiple scenes simultaneously or we can render to
|
||||||
a `texture <class_ViewportTexture>` which is applied to an object in the scene, for example a dynamic
|
a `texture` which is applied to an object in the scene, for example a dynamic
|
||||||
skybox.
|
skybox.
|
||||||
|
|
||||||
`Viewports <class_Viewport>` have a variety of use cases, including:
|
`Viewports` have a variety of use cases, including:
|
||||||
|
|
||||||
- Rendering 3D objects within a 2D game
|
- Rendering 3D objects within a 2D game
|
||||||
- Rendering 2D elements in a 3D game
|
- Rendering 2D elements in a 3D game
|
||||||
@ -37,10 +37,10 @@ what to do with the resulting texture.
|
|||||||
Input
|
Input
|
||||||
-----
|
-----
|
||||||
|
|
||||||
`Viewports <class_Viewport>` are also responsible for delivering properly adjusted and
|
`Viewports` are also responsible for delivering properly adjusted and
|
||||||
scaled input events to all their children nodes. Typically, input is received by the
|
scaled input events to all their children nodes. Typically, input is received by the
|
||||||
nearest `Viewport <class_Viewport>` in the tree, but you can set `Viewports <class_Viewport>` not to receive input by checking
|
nearest `Viewport` not to receive input by checking
|
||||||
'Disable Input' to 'on'; this will allow the next nearest `Viewport <class_Viewport>` in the tree to capture
|
'Disable Input' to 'on'; this will allow the next nearest `Viewport` in the tree to capture
|
||||||
the input.
|
the input.
|
||||||
|
|
||||||
.. image:: img/input.png
|
.. image:: img/input.png
|
||||||
@ -52,27 +52,27 @@ Listener
|
|||||||
|
|
||||||
Godot supports 3D sound (in both 2D and 3D nodes); more on this can be
|
Godot supports 3D sound (in both 2D and 3D nodes); more on this can be
|
||||||
found in the `Audio Streams Tutorial<doc_audio_streams>`. For this type of sound to be
|
found in the `Audio Streams Tutorial<doc_audio_streams>`. For this type of sound to be
|
||||||
audible, the `Viewport <class_Viewport>` needs to be enabled as a listener (for 2D or 3D).
|
audible, the `Viewport` needs to be enabled as a listener (for 2D or 3D).
|
||||||
If you are using a custom `Viewport <class_Viewport>` to display your `World <class_World>`, don't forget
|
If you are using a custom `Viewport`, don't forget
|
||||||
to enable this!
|
to enable this!
|
||||||
|
|
||||||
Cameras (2D & 3D)
|
Cameras (2D & 3D)
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
When using a `Camera <class_Camera>` /
|
When using a `Camera` /
|
||||||
`Camera2D <class_Camera2D>`, cameras will always display on the
|
`Camera2D`, cameras will always display on the
|
||||||
closest parent `Viewport <class_Viewport>` (going towards the root). For example, in the
|
closest parent `Viewport` (going towards the root). For example, in the
|
||||||
following hierarchy:
|
following hierarchy:
|
||||||
|
|
||||||
.. image:: img/cameras.png
|
.. image:: img/cameras.png
|
||||||
|
|
||||||
CameraA will display on the Root `Viewport <class_Viewport>` and it will draw MeshA. CameraB
|
CameraA will display on the Root `Viewport` and it will draw MeshA. CameraB
|
||||||
will be captured by the `Viewport <class_Viewport>` Node along with MeshB. Even though MeshB is in the scene
|
will be captured by the `Viewport` Node along with MeshB. Even though MeshB is in the scene
|
||||||
hierarchy, it will still not be drawn to the Root `Viewport <class_Viewport>`. Similarly MeshA will not
|
hierarchy, it will still not be drawn to the Root `Viewport`. Similarly MeshA will not
|
||||||
be visible from the `Viewport <class_Viewport>` node because `Viewport <class_Viewport>` nodes only
|
be visible from the `Viewport` nodes only
|
||||||
capture nodes below them in the hierarchy.
|
capture nodes below them in the hierarchy.
|
||||||
|
|
||||||
There can only be one active camera per `Viewport <class_Viewport>`, so if there is more
|
There can only be one active camera per `Viewport`, so if there is more
|
||||||
than one, make sure that the desired one has the "current" property set,
|
than one, make sure that the desired one has the "current" property set,
|
||||||
or make it the current camera by calling:
|
or make it the current camera by calling:
|
||||||
|
|
||||||
@ -81,18 +81,18 @@ or make it the current camera by calling:
|
|||||||
camera.make_current()
|
camera.make_current()
|
||||||
|
|
||||||
By default, cameras will render all objects in their world. In 3D, cameras can use their
|
By default, cameras will render all objects in their world. In 3D, cameras can use their
|
||||||
`cull_mask <class_Camera_property_cull_mask>` property combined with the
|
`cull_mask` property combined with the
|
||||||
`VisualInstance's <class_VisualInstance>` `layer <class_VisualInstance_property_layers>`
|
`VisualInstance's`
|
||||||
property to restrict which objects are rendered.
|
property to restrict which objects are rendered.
|
||||||
|
|
||||||
Scale & stretching
|
Scale & stretching
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
`Viewports <class_Viewport>` have a "size" property, which represents the size of the `Viewport <class_Viewport>`
|
`Viewports`
|
||||||
in pixels. For `Viewports <class_Viewport>` which are children of `ViewportContainers <class_viewportcontainer>`,
|
in pixels. For `Viewports`,
|
||||||
these values are overridden, but for all others, this sets their resolution.
|
these values are overridden, but for all others, this sets their resolution.
|
||||||
|
|
||||||
It is also possible to scale the 2D content and make the `Viewport <class_Viewport>` resolution
|
It is also possible to scale the 2D content and make the `Viewport` resolution
|
||||||
different from the one specified in size, by calling:
|
different from the one specified in size, by calling:
|
||||||
|
|
||||||
::
|
::
|
||||||
@ -100,40 +100,40 @@ different from the one specified in size, by calling:
|
|||||||
viewport.set_size_override(true, Vector2(width, height)) # Custom size for 2D.
|
viewport.set_size_override(true, Vector2(width, height)) # Custom size for 2D.
|
||||||
viewport.set_size_override_stretch(true) # Enable stretch for custom size.
|
viewport.set_size_override_stretch(true) # Enable stretch for custom size.
|
||||||
|
|
||||||
The root `Viewport <class_Viewport>` uses this for the stretch options in the project
|
The root `Viewport` uses this for the stretch options in the project
|
||||||
settings. For more information on scaling and stretching visit the `Multiple Resolutions Tutorial <doc_multiple_resolutions>`
|
settings. For more information on scaling and stretching visit the `Multiple Resolutions Tutorial <doc_multiple_resolutions>`
|
||||||
|
|
||||||
Worlds
|
Worlds
|
||||||
------
|
------
|
||||||
|
|
||||||
For 3D, a `Viewport <class_Viewport>` will contain a `World <class_World>`. This
|
For 3D, a `Viewport`. This
|
||||||
is basically the universe that links physics and rendering together.
|
is basically the universe that links physics and rendering together.
|
||||||
Spatial-based nodes will register using the `World <class_World>` of the closest
|
Spatial-based nodes will register using the `World` of the closest
|
||||||
`Viewport <class_Viewport>`. By default, newly created `Viewports <class_Viewport>` do not contain a `World <class_World>` but
|
`Viewport` but
|
||||||
use the same as their parent `Viewport <class_Viewport>` (the root `Viewport <class_Viewport>` always contains a
|
use the same as their parent `Viewport` always contains a
|
||||||
`World <class_World>`, which is the one objects are rendered to by default). A `World <class_World>` can
|
`World` can
|
||||||
be set in a `Viewport <class_Viewport>` using the "world" property, and that will separate
|
be set in a `Viewport` using the "world" property, and that will separate
|
||||||
all children nodes of that `Viewport <class_Viewport>` from interacting with the parent
|
all children nodes of that `Viewport` from interacting with the parent
|
||||||
`Viewport's <class_Viewport>` `World <class_World>`. This is especially useful in scenarios where, for
|
`Viewport's`. This is especially useful in scenarios where, for
|
||||||
example, you might want to show a separate character in 3D imposed over
|
example, you might want to show a separate character in 3D imposed over
|
||||||
the game (like in StarCraft).
|
the game (like in StarCraft).
|
||||||
|
|
||||||
As a helper for situations where you want to create `Viewports <class_Viewport>` that
|
As a helper for situations where you want to create `Viewports` that
|
||||||
display single objects and don't want to create a `World <class_World>`, `Viewport <class_Viewport>` has
|
display single objects and don't want to create a `World` has
|
||||||
the option to use its own `World <class_World>`. This is useful when you want to
|
the option to use its own `World`. This is useful when you want to
|
||||||
instance 3D characters or objects in a 2D `World <class_World2D>`.
|
instance 3D characters or objects in a 2D `World`.
|
||||||
|
|
||||||
For 2D, each `Viewport <class_Viewport>` always contains its own `World2D <class_World2D>`.
|
For 2D, each `Viewport`.
|
||||||
This suffices in most cases, but in case sharing them may be desired, it
|
This suffices in most cases, but in case sharing them may be desired, it
|
||||||
is possible to do so by setting the `Viewport's <class_Viewport>` `World2D <class_World2D>` manually.
|
is possible to do so by setting the `Viewport's` manually.
|
||||||
|
|
||||||
For an example of how this works, see the demo projects `3D in 2D <https://github.com/godotengine/godot-demo-projects/tree/master/viewport/3d_in_2d>`_ and `2D in 3D <https://github.com/godotengine/godot-demo-projects/tree/master/viewport/2d_in_3d>`_ respectively.
|
For an example of how this works, see the demo projects `3D in 2D <https://github.com/godotengine/godot-demo-projects/tree/master/viewport/3d_in_2d>`_ and `2D in 3D <https://github.com/godotengine/godot-demo-projects/tree/master/viewport/2d_in_3d>`_ respectively.
|
||||||
|
|
||||||
Capture
|
Capture
|
||||||
-------
|
-------
|
||||||
|
|
||||||
It is possible to query a capture of the `Viewport <class_Viewport>` contents. For the root
|
It is possible to query a capture of the `Viewport` contents. For the root
|
||||||
`Viewport <class_Viewport>`, this is effectively a screen capture. This is done with the
|
`Viewport`, this is effectively a screen capture. This is done with the
|
||||||
following code:
|
following code:
|
||||||
|
|
||||||
::
|
::
|
||||||
@ -149,7 +149,7 @@ following code:
|
|||||||
# Set Sprite Texture.
|
# Set Sprite Texture.
|
||||||
$sprite.texture = tex
|
$sprite.texture = tex
|
||||||
|
|
||||||
But if you use this in ``_ready()`` or from the first frame of the `Viewport's <class_Viewport>` initialization,
|
But if you use this in ``_ready()`` or from the first frame of the `Viewport's` initialization,
|
||||||
you will get an empty texture because there is nothing to get as texture. You can deal with
|
you will get an empty texture because there is nothing to get as texture. You can deal with
|
||||||
it using (for example):
|
it using (for example):
|
||||||
|
|
||||||
@ -162,33 +162,33 @@ it using (for example):
|
|||||||
Viewport Container
|
Viewport Container
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
If the `Viewport <class_Viewport>` is a child of a `ViewportContainer <class_viewportcontainer>`, it will become active and display anything it has inside. The layout looks like this:
|
If the `Viewport`, it will become active and display anything it has inside. The layout looks like this:
|
||||||
|
|
||||||
.. image:: img/container.png
|
.. image:: img/container.png
|
||||||
|
|
||||||
The `Viewport <class_Viewport>` will cover the area of its parent `ViewportContainer <class_viewportcontainer>` completely
|
The `Viewport` completely
|
||||||
if `Stretch<class_viewportcontainer_property_stretch>` is set to ``true`` in `ViewportContainer <class_viewportcontainer>`.
|
if `Stretch<class_viewportcontainer_property_stretch>` is set to ``true`` in `ViewportContainer`.
|
||||||
Note: The size of the `ViewportContainer <class_viewportcontainer>` cannot be smaller than the size of the `Viewport <class_Viewport>`.
|
Note: The size of the `ViewportContainer`.
|
||||||
|
|
||||||
Rendering
|
Rendering
|
||||||
---------
|
---------
|
||||||
|
|
||||||
Due to the fact that the `Viewport <class_Viewport>` is an entryway into another rendering surface, it exposes a few
|
Due to the fact that the `Viewport` is an entryway into another rendering surface, it exposes a few
|
||||||
rendering properties that can be different from the project settings. The first is MSAA; you can
|
rendering properties that can be different from the project settings. The first is MSAA; you can
|
||||||
choose to use a different level of MSAA for each `Viewport <class_Viewport>`; the default behavior is DISABLED.
|
choose to use a different level of MSAA for each `Viewport`; the default behavior is DISABLED.
|
||||||
You can also set the `Viewport <class_Viewport>` to use HDR, HDR is very useful for when you want to store values in the texture that are outside the range 0.0 - 1.0.
|
You can also set the `Viewport` to use HDR, HDR is very useful for when you want to store values in the texture that are outside the range 0.0 - 1.0.
|
||||||
|
|
||||||
If you know how the `Viewport <class_Viewport>` is going to be used, you can set its Usage to either 3D or 2D. Godot will then
|
If you know how the `Viewport` is going to be used, you can set its Usage to either 3D or 2D. Godot will then
|
||||||
restrict how the `Viewport <class_Viewport>` is drawn to in accordance with your choice; default is 3D.
|
restrict how the `Viewport` is drawn to in accordance with your choice; default is 3D.
|
||||||
The 2D usage mode is slightly faster and uses less memory compared to the 3D one. It's a good idea to set the `Viewport <class_Viewport>`'s Usage property to 2D if your viewport doesn't render anything in 3D.
|
The 2D usage mode is slightly faster and uses less memory compared to the 3D one. It's a good idea to set the `Viewport`'s Usage property to 2D if your viewport doesn't render anything in 3D.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
If you need to render 3D shadows in the viewport, make sure to set the viewport's *Shadow Atlas Size* property to a value higher than 0.
|
If you need to render 3D shadows in the viewport, make sure to set the viewport's *Shadow Atlas Size* property to a value higher than 0.
|
||||||
Otherwise, shadows won't be rendered. For reference, the Project Settings define it to 4096 by default.
|
Otherwise, shadows won't be rendered. For reference, the Project Settings define it to 4096 by default.
|
||||||
|
|
||||||
Godot also provides a way of customizing how everything is drawn inside `Viewports <class_Viewport>` using “Debug Draw”.
|
Godot also provides a way of customizing how everything is drawn inside `Viewports` using “Debug Draw”.
|
||||||
Debug Draw allows you to specify one of four options for how the `Viewport <class_Viewport>` will display things drawn
|
Debug Draw allows you to specify one of four options for how the `Viewport` will display things drawn
|
||||||
inside it. Debug Draw is disabled by default.
|
inside it. Debug Draw is disabled by default.
|
||||||
|
|
||||||
.. image:: img/default_scene.png
|
.. image:: img/default_scene.png
|
||||||
@ -218,8 +218,8 @@ Lastly, Wireframe draws the scene using only the edges of triangles in the meshe
|
|||||||
Render target
|
Render target
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
When rendering to a `Viewport <class_Viewport>`, whatever is inside will not be
|
When rendering to a `Viewport`, whatever is inside will not be
|
||||||
visible in the scene editor. To display the contents, you have to draw the `Viewport's <class_Viewport>` `ViewportTexture <class_ViewportTexture>` somewhere.
|
visible in the scene editor. To display the contents, you have to draw the `Viewport's` somewhere.
|
||||||
This can be requested via code using (for example):
|
This can be requested via code using (for example):
|
||||||
|
|
||||||
::
|
::
|
||||||
@ -232,17 +232,17 @@ Or it can be assigned in the editor by selecting "New ViewportTexture"
|
|||||||
|
|
||||||
.. image:: img/texturemenu.png
|
.. image:: img/texturemenu.png
|
||||||
|
|
||||||
and then selecting the `Viewport <class_Viewport>` you want to use.
|
and then selecting the `Viewport` you want to use.
|
||||||
|
|
||||||
.. image:: img/texturepath.png
|
.. image:: img/texturepath.png
|
||||||
|
|
||||||
Every frame, the `Viewport <class_Viewport>`'s texture is cleared away with the default clear color (or a transparent
|
Every frame, the `Viewport`'s texture is cleared away with the default clear color (or a transparent
|
||||||
color if `Transparent Bg<class_Viewport_property_transparent_bg>` is set to ``true``). This can be changed by setting `Clear Mode<class_Viewport_property_render_target_clear_mode>` to Never or Next Frame.
|
color if `Transparent Bg<class_Viewport_property_transparent_bg>` is set to ``true``). This can be changed by setting `Clear Mode<class_Viewport_property_render_target_clear_mode>` to Never or Next Frame.
|
||||||
As the name implies, Never means the texture will never be cleared, while next frame will
|
As the name implies, Never means the texture will never be cleared, while next frame will
|
||||||
clear the texture on the next frame and then set itself to Never.
|
clear the texture on the next frame and then set itself to Never.
|
||||||
|
|
||||||
By default, re-rendering of the `Viewport <class_Viewport>` happens when the
|
By default, re-rendering of the `Viewport` happens when the
|
||||||
`Viewport <class_Viewport>`'s `ViewportTexture <class_ViewportTexture>` has been drawn in a frame. If visible, it will be
|
`Viewport` has been drawn in a frame. If visible, it will be
|
||||||
rendered; otherwise, it will not. This behavior can be changed to manual
|
rendered; otherwise, it will not. This behavior can be changed to manual
|
||||||
rendering (once), or always render, no matter if visible or not. This flexibility
|
rendering (once), or always render, no matter if visible or not. This flexibility
|
||||||
allows users to render an image once and then use the texture without
|
allows users to render an image once and then use the texture without
|
||||||
|
@ -4,7 +4,7 @@ Change scenes manually
|
|||||||
======================
|
======================
|
||||||
|
|
||||||
Sometimes it helps to have more control over how one swaps scenes around.
|
Sometimes it helps to have more control over how one swaps scenes around.
|
||||||
As mentioned above, a `Viewport <class_Viewport>`'s child nodes
|
As mentioned above, a `Viewport`'s child nodes
|
||||||
will render to the image it generates. This holds true even for nodes outside
|
will render to the image it generates. This holds true even for nodes outside
|
||||||
of the "current" scene. Autoloads fall into this category, but so do
|
of the "current" scene. Autoloads fall into this category, but so do
|
||||||
scenes which one instances and adds to the tree at runtime:
|
scenes which one instances and adds to the tree at runtime:
|
||||||
@ -22,13 +22,13 @@ gdscript GDScript
|
|||||||
|
|
||||||
To complete the cycle and swap out the new scene with the old one,
|
To complete the cycle and swap out the new scene with the old one,
|
||||||
developers have a choice to make. Many strategies exist for removing a scene
|
developers have a choice to make. Many strategies exist for removing a scene
|
||||||
from view of the `Viewport <class_Viewport>`. The tradeoffs involve
|
from view of the `Viewport`. The tradeoffs involve
|
||||||
balancing operation speed and memory consumption as well as balancing data
|
balancing operation speed and memory consumption as well as balancing data
|
||||||
access and integrity.
|
access and integrity.
|
||||||
|
|
||||||
1. **We can delete the existing scene.**
|
1. **We can delete the existing scene.**
|
||||||
`SceneTree.change_scene() <class_SceneTree_method_change_scene>` and
|
`SceneTree.change_scene()` and
|
||||||
`SceneTree.change_scene_to() <class_SceneTree_method_change_scene_to>`
|
`SceneTree.change_scene_to()`
|
||||||
will delete the current scene immediately. Developers can also delete the
|
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
|
main scene though. Assuming the root node's name is "Main", one could do
|
||||||
``get_node("/root/Main").free()`` to delete the whole scene.
|
``get_node("/root/Main").free()`` to delete the whole scene.
|
||||||
@ -46,7 +46,7 @@ access and integrity.
|
|||||||
|
|
||||||
- Note: It can be useful to preserve the data in a soon-to-be-deleted
|
- Note: It can be useful to preserve the data in a soon-to-be-deleted
|
||||||
scene by re-attaching one or more of its nodes to a different scene,
|
scene by re-attaching one or more of its nodes to a different scene,
|
||||||
or even directly to the `SceneTree <class_SceneTree>`.
|
or even directly to the `SceneTree`.
|
||||||
|
|
||||||
- Processing stops.
|
- Processing stops.
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ access and integrity.
|
|||||||
data.
|
data.
|
||||||
|
|
||||||
- Pro: Nodes are still members of groups (since groups belong to the
|
- Pro: Nodes are still members of groups (since groups belong to the
|
||||||
`SceneTree <class_SceneTree>`).
|
`SceneTree`).
|
||||||
|
|
||||||
- Con: The CPU's attention is now divided between both scenes. Too much
|
- Con: The CPU's attention is now divided between both scenes. Too much
|
||||||
load could result in low frame rates. One should be sure to test
|
load could result in low frame rates. One should be sure to test
|
||||||
@ -85,7 +85,7 @@ access and integrity.
|
|||||||
|
|
||||||
3. **We can remove the existing scene from the tree.** Assign a variable
|
3. **We can remove the existing scene from the tree.** Assign a variable
|
||||||
to the existing scene's root node. Then use
|
to the existing scene's root node. Then use
|
||||||
`Node.remove_child(Node) <class_Node_method_remove_child>` to detach the entire
|
`Node.remove_child(Node)` to detach the entire
|
||||||
scene from the tree.
|
scene from the tree.
|
||||||
|
|
||||||
- Memory still exists (similar pros/cons as with hiding it from view).
|
- Memory still exists (similar pros/cons as with hiding it from view).
|
||||||
@ -99,7 +99,7 @@ access and integrity.
|
|||||||
|
|
||||||
- Con: Unlike with hiding it from view only, the data contained within
|
- Con: Unlike with hiding it from view only, the data contained within
|
||||||
the scene will become stale if it relies on delta time, input, groups,
|
the scene will become stale if it relies on delta time, input, groups,
|
||||||
or other data that is derived from `SceneTree <class_SceneTree>`
|
or other data that is derived from `SceneTree`
|
||||||
access.
|
access.
|
||||||
|
|
||||||
There are also cases where one may wish to have many scenes present at the same
|
There are also cases where one may wish to have many scenes present at the same
|
||||||
@ -113,7 +113,7 @@ gdscript GDScript
|
|||||||
```
|
```
|
||||||
|
|
||||||
Perhaps instead they wish to display multiple scenes at the same time using
|
Perhaps instead they wish to display multiple scenes at the same time using
|
||||||
`ViewportContainers <class_ViewportContainer>`. This is optimal in
|
`ViewportContainers`. This is optimal in
|
||||||
cases where the intent is to render different content in different parts of the
|
cases where the intent is to render different content in different parts of the
|
||||||
screen. Minimaps and split-screen multiplayer are good examples.
|
screen. Minimaps and split-screen multiplayer are good examples.
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ Project-defined templates
|
|||||||
The default path to search for templates is the
|
The default path to search for templates is the
|
||||||
``res://script_templates/`` directory. The path can be changed by configuring
|
``res://script_templates/`` directory. The path can be changed by configuring
|
||||||
the ``editor/script_templates_search_path`` setting in the
|
the ``editor/script_templates_search_path`` setting in the
|
||||||
`ProjectSettings <class_ProjectSettings>`, both via code and the editor.
|
`ProjectSettings`, both via code and the editor.
|
||||||
|
|
||||||
If no ``script_templates`` directory is found within a project, it is simply
|
If no ``script_templates`` directory is found within a project, it is simply
|
||||||
ignored.
|
ignored.
|
||||||
@ -107,7 +107,7 @@ Base placeholders
|
|||||||
| ``%TS%`` | Indentation placeholder. The exact type and number of |
|
| ``%TS%`` | Indentation placeholder. The exact type and number of |
|
||||||
| | whitespace characters used for indentation is determined by |
|
| | whitespace characters used for indentation is determined by |
|
||||||
| | the ``text_editor/indent/type`` and ``text_editor/indent/size``|
|
| | the ``text_editor/indent/type`` and ``text_editor/indent/size``|
|
||||||
| | settings in the `EditorSettings <class_EditorSettings>` |
|
| | settings in the `EditorSettings` |
|
||||||
| | respectively. |
|
| | respectively. |
|
||||||
+-------------+----------------------------------------------------------------+
|
+-------------+----------------------------------------------------------------+
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ Type placeholders
|
|||||||
These are only relevant for GDScript with static typing. Whether these
|
These are only relevant for GDScript with static typing. Whether these
|
||||||
placeholders are actually replaced is determined by the
|
placeholders are actually replaced is determined by the
|
||||||
``text_editor/completion/add_type_hints`` setting in the
|
``text_editor/completion/add_type_hints`` setting in the
|
||||||
`EditorSettings <class_EditorSettings>`.
|
`EditorSettings`.
|
||||||
|
|
||||||
+-------------------+--------------+
|
+-------------------+--------------+
|
||||||
| Placeholder | Value |
|
| Placeholder | Value |
|
||||||
|
@ -44,7 +44,7 @@ Instantiating C# nodes from GDScript
|
|||||||
|
|
||||||
Using C# from GDScript doesn't need much work. Once loaded
|
Using C# from GDScript doesn't need much work. Once loaded
|
||||||
(see `doc_gdscript_classes_as_resources`), the script can be instantiated
|
(see `doc_gdscript_classes_as_resources`), the script can be instantiated
|
||||||
with `new() <class_CSharpScript_method_new>`.
|
with `new()`.
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ Instantiating GDScript nodes from C#
|
|||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
From the C# side, everything work the same way. Once loaded, the GDScript can
|
From the C# side, everything work the same way. Once loaded, the GDScript can
|
||||||
be instantiated with `GDScript.New() <class_GDScript_method_new>`.
|
be instantiated with `GDScript.New()`.
|
||||||
|
|
||||||
.. code-block:: csharp
|
.. code-block:: csharp
|
||||||
|
|
||||||
@ -104,8 +104,8 @@ Accessing GDScript fields from C#
|
|||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
As C# is statically typed, accessing GDScript from C# is a bit more
|
As C# is statically typed, accessing GDScript from C# is a bit more
|
||||||
convoluted, you will have to use `Object.Get() <class_Object_method_get>`
|
convoluted, you will have to use `Object.Get()`
|
||||||
and `Object.Set() <class_Object_method_set>`. The first argument is the name of the field you want to access.
|
and `Object.Set()`. The first argument is the name of the field you want to access.
|
||||||
|
|
||||||
.. code-block:: csharp
|
.. code-block:: csharp
|
||||||
|
|
||||||
@ -145,7 +145,7 @@ Calling GDScript methods from C#
|
|||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
To call GDScript methods from C# you'll need to use
|
To call GDScript methods from C# you'll need to use
|
||||||
`Object.Call() <class_Object_method_call>`. The first argument is the
|
`Object.Call()`. The first argument is the
|
||||||
name of the method you want to call. The following arguments will be passed
|
name of the method you want to call. The following arguments will be passed
|
||||||
to said method.
|
to said method.
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ An expression can be:
|
|||||||
- A built-in method call like ``deg2rad(90)``.
|
- A built-in method call like ``deg2rad(90)``.
|
||||||
- A method call on an user-provided script like ``update_health()``,
|
- A method call on an user-provided script like ``update_health()``,
|
||||||
if ``base_instance`` is set to a value other than ``null`` when calling
|
if ``base_instance`` is set to a value other than ``null`` when calling
|
||||||
`Expression.execute() <class_Expression_method_execute>`.
|
`Expression.execute()`.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ Setting a base instance for the expression
|
|||||||
By default, an expression has a base instance of ``null``. This means the
|
By default, an expression has a base instance of ``null``. This means the
|
||||||
expression has no base instance associated to it.
|
expression has no base instance associated to it.
|
||||||
|
|
||||||
When calling `Expression.execute() <class_Expression_method_execute>`,
|
When calling `Expression.execute()`,
|
||||||
you can set the value of the ``base_instance`` parameter to a specific object
|
you can set the value of the ``base_instance`` parameter to a specific object
|
||||||
instance such as ``self``, another script instance or even a singleton::
|
instance such as ``self``, another script instance or even a singleton::
|
||||||
|
|
||||||
|
@ -348,18 +348,18 @@ null
|
|||||||
``null`` is an empty data type that contains no information and can not
|
``null`` is an empty data type that contains no information and can not
|
||||||
be assigned any other value.
|
be assigned any other value.
|
||||||
|
|
||||||
`bool <class_bool>`
|
`bool`
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
Short for "boolean", it can only contain ``true`` or ``false``.
|
Short for "boolean", it can only contain ``true`` or ``false``.
|
||||||
|
|
||||||
`int <class_int>`
|
`int`
|
||||||
^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
Short for "integer", it stores whole numbers (positive and negative).
|
Short for "integer", it stores whole numbers (positive and negative).
|
||||||
It is stored as a 64-bit value, equivalent to "int64_t" in C++.
|
It is stored as a 64-bit value, equivalent to "int64_t" in C++.
|
||||||
|
|
||||||
`float <class_float>`
|
`float`
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
Stores real numbers, including decimals, using floating-point values.
|
Stores real numbers, including decimals, using floating-point values.
|
||||||
@ -367,7 +367,7 @@ It is stored as a 64-bit value, equivalent to "double" in C++.
|
|||||||
Note: Currently, data structures such as Vector2, Vector3, and
|
Note: Currently, data structures such as Vector2, Vector3, and
|
||||||
PoolRealArray store 32-bit single-precision "float" values.
|
PoolRealArray store 32-bit single-precision "float" values.
|
||||||
|
|
||||||
`String <class_String>`
|
`String`
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
A sequence of characters in `Unicode format <https://en.wikipedia.org/wiki/Unicode>`_.
|
A sequence of characters in `Unicode format <https://en.wikipedia.org/wiki/Unicode>`_.
|
||||||
@ -405,56 +405,56 @@ GDScript also supports `doc_gdscript_printf`.
|
|||||||
Vector built-in types
|
Vector built-in types
|
||||||
~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
`Vector2 <class_Vector2>`
|
`Vector2`
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
2D vector type containing ``x`` and ``y`` fields. Can also be
|
2D vector type containing ``x`` and ``y`` fields. Can also be
|
||||||
accessed as an array.
|
accessed as an array.
|
||||||
|
|
||||||
`Rect2 <class_Rect2>`
|
`Rect2`
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
2D Rectangle type containing two vectors fields: ``position`` and ``size``.
|
2D Rectangle type containing two vectors fields: ``position`` and ``size``.
|
||||||
Also contains an ``end`` field which is ``position + size``.
|
Also contains an ``end`` field which is ``position + size``.
|
||||||
|
|
||||||
`Vector3 <class_Vector3>`
|
`Vector3`
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
3D vector type containing ``x``, ``y`` and ``z`` fields. This can also
|
3D vector type containing ``x``, ``y`` and ``z`` fields. This can also
|
||||||
be accessed as an array.
|
be accessed as an array.
|
||||||
|
|
||||||
`Transform2D <class_Transform2D>`
|
`Transform2D`
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
3×2 matrix used for 2D transforms.
|
3×2 matrix used for 2D transforms.
|
||||||
|
|
||||||
`Plane <class_Plane>`
|
`Plane`
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
3D Plane type in normalized form that contains a ``normal`` vector field
|
3D Plane type in normalized form that contains a ``normal`` vector field
|
||||||
and a ``d`` scalar distance.
|
and a ``d`` scalar distance.
|
||||||
|
|
||||||
`Quat <class_Quat>`
|
`Quat`
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
Quaternion is a datatype used for representing a 3D rotation. It's
|
Quaternion is a datatype used for representing a 3D rotation. It's
|
||||||
useful for interpolating rotations.
|
useful for interpolating rotations.
|
||||||
|
|
||||||
`AABB <class_AABB>`
|
`AABB`
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
Axis-aligned bounding box (or 3D box) contains 2 vectors fields: ``position``
|
Axis-aligned bounding box (or 3D box) contains 2 vectors fields: ``position``
|
||||||
and ``size``. Also contains an ``end`` field which is
|
and ``size``. Also contains an ``end`` field which is
|
||||||
``position + size``.
|
``position + size``.
|
||||||
|
|
||||||
`Basis <class_Basis>`
|
`Basis`
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
3x3 matrix used for 3D rotation and scale. It contains 3 vector fields
|
3x3 matrix used for 3D rotation and scale. It contains 3 vector fields
|
||||||
(``x``, ``y`` and ``z``) and can also be accessed as an array of 3D
|
(``x``, ``y`` and ``z``) and can also be accessed as an array of 3D
|
||||||
vectors.
|
vectors.
|
||||||
|
|
||||||
`Transform <class_Transform>`
|
`Transform`
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
3D Transform contains a Basis field ``basis`` and a Vector3 field
|
3D Transform contains a Basis field ``basis`` and a Vector3 field
|
||||||
@ -463,24 +463,24 @@ vectors.
|
|||||||
Engine built-in types
|
Engine built-in types
|
||||||
~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
`Color <class_Color>`
|
`Color`
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
Color data type contains ``r``, ``g``, ``b``, and ``a`` fields. It can
|
Color data type contains ``r``, ``g``, ``b``, and ``a`` fields. It can
|
||||||
also be accessed as ``h``, ``s``, and ``v`` for hue/saturation/value.
|
also be accessed as ``h``, ``s``, and ``v`` for hue/saturation/value.
|
||||||
|
|
||||||
`NodePath <class_NodePath>`
|
`NodePath`
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
Compiled path to a node used mainly in the scene system. It can be
|
Compiled path to a node used mainly in the scene system. It can be
|
||||||
easily assigned to, and from, a String.
|
easily assigned to, and from, a String.
|
||||||
|
|
||||||
`RID <class_RID>`
|
`RID`
|
||||||
^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
Resource ID (RID). Servers use generic RIDs to reference opaque data.
|
Resource ID (RID). Servers use generic RIDs to reference opaque data.
|
||||||
|
|
||||||
`Object <class_Object>`
|
`Object`
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
Base class for anything that is not a built-in type.
|
Base class for anything that is not a built-in type.
|
||||||
@ -488,7 +488,7 @@ Base class for anything that is not a built-in type.
|
|||||||
Container built-in types
|
Container built-in types
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
`Array <class_Array>`
|
`Array`
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
Generic sequence of arbitrary object types, including other arrays or dictionaries (see below).
|
Generic sequence of arbitrary object types, including other arrays or dictionaries (see below).
|
||||||
@ -512,15 +512,15 @@ arrays are available. These only accept a single data type. They avoid memory
|
|||||||
fragmentation and use less memory, but are atomic and tend to run slower than generic
|
fragmentation and use less memory, but are atomic and tend to run slower than generic
|
||||||
arrays. They are therefore only recommended to use for large data sets:
|
arrays. They are therefore only recommended to use for large data sets:
|
||||||
|
|
||||||
- `PoolByteArray <class_PoolByteArray>`: An array of bytes (integers from 0 to 255).
|
- `PoolByteArray`: An array of bytes (integers from 0 to 255).
|
||||||
- `PoolIntArray <class_PoolIntArray>`: An array of integers.
|
- `PoolIntArray`: An array of integers.
|
||||||
- `PoolRealArray <class_PoolRealArray>`: An array of floats.
|
- `PoolRealArray`: An array of floats.
|
||||||
- `PoolStringArray <class_PoolStringArray>`: An array of strings.
|
- `PoolStringArray`: An array of strings.
|
||||||
- `PoolVector2Array <class_PoolVector2Array>`: An array of `Vector2 <class_Vector2>` objects.
|
- `PoolVector2Array` objects.
|
||||||
- `PoolVector3Array <class_PoolVector3Array>`: An array of `Vector3 <class_Vector3>` objects.
|
- `PoolVector3Array` objects.
|
||||||
- `PoolColorArray <class_PoolColorArray>`: An array of `Color <class_Color>` objects.
|
- `PoolColorArray` objects.
|
||||||
|
|
||||||
`Dictionary <class_Dictionary>`
|
`Dictionary`
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
Associative container which contains values referenced by unique keys.
|
Associative container which contains values referenced by unique keys.
|
||||||
@ -569,8 +569,8 @@ assign to it::
|
|||||||
The bracket syntax can be used to access properties of any
|
The bracket syntax can be used to access properties of any
|
||||||
`class_Object`, not just Dictionaries. Keep in mind it will cause a
|
`class_Object`, not just Dictionaries. Keep in mind it will cause a
|
||||||
script error when attempting to index a non-existing property. To avoid
|
script error when attempting to index a non-existing property. To avoid
|
||||||
this, use the `Object.get() <class_Object_method_get>` and
|
this, use the `Object.get()` and
|
||||||
`Object.set() <class_Object_method_set>` methods instead.
|
`Object.set()` methods instead.
|
||||||
|
|
||||||
Data
|
Data
|
||||||
----
|
----
|
||||||
@ -1270,7 +1270,7 @@ function.
|
|||||||
Classes as resources
|
Classes as resources
|
||||||
^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
Classes stored as files are treated as `resources <class_GDScript>`. They
|
Classes stored as files are treated as `resources`. They
|
||||||
must be loaded from disk to access them in other classes. This is done using
|
must be loaded from disk to access them in other classes. This is done using
|
||||||
either the ``load`` or ``preload`` functions (see below). Instancing of a loaded
|
either the ``load`` or ``preload`` functions (see below). Instancing of a loaded
|
||||||
class resource is done by calling the ``new`` function on the class object::
|
class resource is done by calling the ``new`` function on the class object::
|
||||||
@ -1452,9 +1452,9 @@ to react to health changes with an animation, but we want to keep the user
|
|||||||
interface separate from the player in our scene tree.
|
interface separate from the player in our scene tree.
|
||||||
|
|
||||||
In our ``Character.gd`` script, we define a ``health_changed`` signal and emit
|
In our ``Character.gd`` script, we define a ``health_changed`` signal and emit
|
||||||
it with `Object.emit_signal() <class_Object_method_emit_signal>`, and from
|
it with `Object.emit_signal()`, and from
|
||||||
a ``Game`` node higher up our scene tree, we connect it to the ``Lifebar`` using
|
a ``Game`` node higher up our scene tree, we connect it to the ``Lifebar`` using
|
||||||
the `Object.connect() <class_Object_method_connect>` method::
|
the `Object.connect()` method::
|
||||||
|
|
||||||
# Character.gd
|
# Character.gd
|
||||||
|
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user