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
|
||||
^^^^^^^^^^
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
- Containers to place GUI elements automatically following certain rules.
|
||||
|
||||
- `Stack <class_BoxContainer>` layouts.
|
||||
- `Grid <class_GridContainer>` layouts.
|
||||
- `Margin <class_MarginContainer>` and `centered <class_CenterContainer>`
|
||||
- `Stack` layouts.
|
||||
- `Grid` layouts.
|
||||
- `Margin`
|
||||
layouts.
|
||||
- `Draggable splitter <class_SplitContainer>` layouts.
|
||||
- `Draggable splitter` layouts.
|
||||
|
||||
- Scale to multiple resolutions using the ``2d`` or ``viewport`` stretch modes.
|
||||
- Support any aspect ratio using anchors and the ``expand`` stretch aspect.
|
||||
@ -591,7 +591,7 @@ Animation
|
||||
^^^^^^^^^
|
||||
|
||||
- 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 calling methods 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`. |
|
||||
+----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
|
||||
| [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. |
|
||||
+----------------------------+--------------------------------------+-----------------------------------+---------------------------------------------------+
|
||||
|
@ -6,12 +6,12 @@ Object class
|
||||
.. seealso::
|
||||
|
||||
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
|
||||
------------------
|
||||
|
||||
`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
|
||||
editable properties, and declaring them is a matter of using a single
|
||||
macro like this.
|
||||
@ -240,14 +240,14 @@ Adding signals to a class is done in ``_bind_methods``, using the
|
||||
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.
|
||||
More information can be found on the `doc_godot_notifications` page.
|
||||
|
||||
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.
|
||||
Declaring them must be done using Ref<> template. For example:
|
||||
|
||||
@ -270,7 +270,7 @@ References:
|
||||
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
|
||||
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
|
||||
|
@ -80,7 +80,7 @@ heading.
|
||||
|
||||
.. 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
|
||||
collision area. For this character, a ``CapsuleShape2D`` node gives the best
|
||||
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:
|
||||
|
||||
- `RigidBody2D <class_RigidBody2D>` (named ``Mob``)
|
||||
- `RigidBody2D` (named ``Mob``)
|
||||
|
||||
- `AnimatedSprite <class_AnimatedSprite>`
|
||||
- `CollisionShape2D <class_CollisionShape2D>`
|
||||
- `VisibilityNotifier2D <class_VisibilityNotifier2D>`
|
||||
- `AnimatedSprite`
|
||||
- `CollisionShape2D`
|
||||
- `VisibilityNotifier2D`
|
||||
|
||||
Don't forget to set the children so they can't be selected, like you did with
|
||||
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
|
||||
`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.
|
||||
|
||||
.. 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
|
||||
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.
|
||||
|
||||
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
|
||||
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
|
||||
(values are in seconds):
|
||||
|
||||
- `Timer <class_Timer>` (named ``MobTimer``) - to control how often mobs
|
||||
- `Timer` (named ``MobTimer``) - to control how often mobs
|
||||
spawn
|
||||
- `Timer <class_Timer>` (named ``ScoreTimer``) - to increment the score
|
||||
- `Timer` (named ``ScoreTimer``) - to increment the score
|
||||
every second
|
||||
- `Timer <class_Timer>` (named ``StartTimer``) - to give a delay before
|
||||
- `Timer` (named ``StartTimer``) - to give a delay before
|
||||
starting
|
||||
- `Position2D <class_Position2D>` (named ``StartPosition``) - to indicate
|
||||
- `Position2D` (named ``StartPosition``) - to indicate
|
||||
the player's start position
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
automatically rotate and follow the path as it moves, so we can use it to select
|
||||
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
|
||||
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
|
||||
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
|
||||
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 "Start" button to begin the game.
|
||||
|
||||
The basic node for UI elements is `Control <class_Control>`. To create our
|
||||
UI, we'll use two types of `Control <class_Control>` nodes: `Label
|
||||
<class_Label>` and `Button <class_Button>`.
|
||||
The basic node for UI elements is `Control`. To create our
|
||||
UI, we'll use two types of `Control` nodes: `Label
|
||||
<class_Label>` and `Button`.
|
||||
|
||||
Create the following as children of the ``HUD`` node:
|
||||
|
||||
- `Label <class_Label>` named ``ScoreLabel``.
|
||||
- `Label <class_Label>` named ``Message``.
|
||||
- `Button <class_Button>` named ``StartButton``.
|
||||
- `Timer <class_Timer>` named ``MessageTimer``.
|
||||
- `Label` named ``ScoreLabel``.
|
||||
- `Label` named ``Message``.
|
||||
- `Button` named ``StartButton``.
|
||||
- `Timer` named ``MessageTimer``.
|
||||
|
||||
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
|
||||
|
@ -12,7 +12,7 @@ Background
|
||||
~~~~~~~~~~
|
||||
|
||||
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.
|
||||
``ColorRect`` only has one property: ``Color``. Choose a color you like and
|
||||
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
|
||||
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,
|
||||
click on the ``Stream`` property, select "Load", and choose the corresponding
|
||||
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
|
||||
<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
|
||||
`CollisionShape2D <class_CollisionShape2D>`.
|
||||
and bounce on walls, a `Sprite` node, and a
|
||||
`CollisionShape2D`.
|
||||
|
||||
.. image:: img/instancing_ball_scene.png
|
||||
|
||||
|
@ -102,7 +102,7 @@ node, including classes it extends, like ``Node2D``, ``CanvasItem``, and
|
||||
``Node``.
|
||||
|
||||
.. 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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
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
|
||||
shape, allowing you to know when the player collected it.
|
||||
|
||||
|
@ -46,33 +46,33 @@ Nodes
|
||||
-----
|
||||
|
||||
The demo uses four different nodes:
|
||||
* `CanvasModulate <class_CanvasModulate>`
|
||||
* `Sprite <class_Sprite>`
|
||||
* `Light2D <class_Light2D>`
|
||||
* `LightOccluder2D <class_LightOccluder2D>`
|
||||
* `CanvasModulate`
|
||||
* `Sprite`
|
||||
* `Light2D`
|
||||
* `LightOccluder2D`
|
||||
|
||||
`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.
|
||||
|
||||
`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
|
||||
used in other ways, for example masking out parts of the scene.
|
||||
|
||||
`LightOccluder2Ds <class_LightOccluder2D>` 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
|
||||
their direction is based on the center of the `Light <class_Light2D>`.
|
||||
`LightOccluder2Ds` are used to tell the shader which parts of
|
||||
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`.
|
||||
|
||||
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.
|
||||
|
||||
.. 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.
|
||||
|
||||
@ -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
|
||||
the color of the light.
|
||||
|
||||
For the demo the lights have two components, the `Light <class_Light2D>` itself (which
|
||||
is the effect of the light), and a `Sprite <class_Sprite>` blob which is an image showing the
|
||||
location of the light source. A child `Sprite <class_Sprite>` is not necessary to make a
|
||||
`Light <class_Light2D>` work.
|
||||
For the demo the lights have two components, the `Light` itself (which
|
||||
is the effect of the light), and a `Sprite` blob which is an image showing the
|
||||
location of the light source. A child `Sprite` is not necessary to make a
|
||||
`Light` work.
|
||||
|
||||
.. image:: img/light_shadow_light_blob.png
|
||||
|
||||
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``.
|
||||
|
||||
In the demo we are using a `Sprite <class_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
|
||||
the `LightOccluder2D <class_LightOccluder2D>` looks like a dark spot and in this demo the `Sprite <class_Sprite>` is
|
||||
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`. By itself
|
||||
the `LightOccluder2D` is
|
||||
just a black square.
|
||||
|
||||
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
|
||||
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.
|
||||
|
||||
.. 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
|
||||
means that each light adds its own color to whatever is underneath.
|
||||
|
||||
.. 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
|
||||
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
|
||||
should stay centered on the `Light <class_Light2D>` 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
|
||||
`LightOccluder2D's <class_LightOccluder2D>` will treat the position of the light as the center of the `Light <class_Light2D>`
|
||||
node, which is why we want the blob to be centered on its parent `Light <class_Light2D>`.
|
||||
Next add a child `Sprite` nodes, and set
|
||||
the `Sprite's`_. Each of these
|
||||
should stay centered on the `Light` node. The blob is the image of the light
|
||||
itself while the `Light` shows the effect that the light has on the scene. The
|
||||
`LightOccluder2D's`
|
||||
node, which is why we want the blob to be centered on its parent `Light`.
|
||||
|
||||
.. 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.
|
||||
|
||||
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
|
||||
`CanvasModulate <class_CanvasModulate>` multiples the entire viewport by a specific color.
|
||||
This is why the demo uses a `CanvasModulate` in the scene. The
|
||||
`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.
|
||||
|
||||
.. image:: img/light_shadow_ambient.png
|
||||
|
||||
Now we add the shadow casters.
|
||||
|
||||
The demo uses a `Node <class_Node2D>` 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.
|
||||
The demo uses a `Node` named "casters" to organize the shadow casters. Add a
|
||||
`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.
|
||||
|
||||
Each shadow caster is made of a `Sprite <class_Sprite>`, with a `LightOccluder2D <class_LightOccluder2D>`
|
||||
child. For the demo the `Sprite <class_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
|
||||
game the `Sprite <class_Sprite>` could be more than a black box; it could be an image of whatever object is casting
|
||||
Each shadow caster is made of a `Sprite`
|
||||
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` is where all the magic happens. In a
|
||||
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.
|
||||
|
||||
.. image:: img/light_shadow_sprites.png
|
||||
|
||||
`LightOccluder2Ds <class_LightOccluder2D>` tell the game what shape the occluder has. They hold
|
||||
an `OccluderPolygon2D <class_OccluderPolygon2D>`, which is a container
|
||||
`LightOccluder2Ds` tell the game what shape the occluder has. They hold
|
||||
an `OccluderPolygon2D`, which is a container
|
||||
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.
|
||||
|
||||
@ -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
|
||||
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``
|
||||
set to ``off`` in the corresponding `OccluderPolygon2D <class_OccluderPolygon2D>`, so that the
|
||||
To illustrate the difference, here is an image of a `LightOccluder2D` with ``Closed``
|
||||
set to ``off`` in the corresponding `OccluderPolygon2D`, so that the
|
||||
lines of the polygon can be seen:
|
||||
|
||||
.. 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
|
||||
left which would cast a shadow as well.
|
||||
|
||||
When you have added the `LightOccluder2Ds <class_LightOccluder2D>` the shadows still won't
|
||||
appear. You need to go back into the `Light2Ds <class_Light2D>` and under the Shadow
|
||||
When you have added the `LightOccluder2Ds` the shadows still won't
|
||||
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.
|
||||
|
||||
.. image:: img/light_shadow_filter0_pcf0.png
|
||||
@ -219,7 +219,7 @@ forming between the samples.
|
||||
|
||||
.. 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.
|
||||
|
||||
.. 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
|
||||
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.
|
||||
|
||||
.. _doc_2d_movement_setup:
|
||||
@ -159,7 +159,7 @@ gdscript GDScript
|
||||
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
|
||||
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
|
||||
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
|
||||
with `AnimationPlayer <class_AnimationPlayer>` and the *Animation*
|
||||
property of `Sprite <class_Sprite>`.
|
||||
with `AnimationPlayer` and the *Animation*
|
||||
property of `Sprite`.
|
||||
|
||||
.. note:: Art for the following examples by https://opengameart.org/users/ansimuz and by
|
||||
https://opengameart.org/users/tgfcoder
|
||||
@ -36,8 +36,8 @@ with the following nodes:
|
||||
|
||||
.. image:: img/2d_animation_tree1.png
|
||||
|
||||
.. note:: The root node could also be `Area2D <class_Area2D>` or
|
||||
`RigidBody2D <class_RigidBody2D>`. The animation will still be
|
||||
.. note:: The root node could also be `Area2D` or
|
||||
`RigidBody2D`. The animation will still be
|
||||
made in the same way. Once the animation is completed, you can
|
||||
assign a shape to the CollisionShape2D. See
|
||||
`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
|
||||
`Sprite <class_Sprite>` node to display the texture, and then animating the
|
||||
change from texture to texture with `AnimationPlayer <class_AnimationPlayer>`.
|
||||
`Sprite` node to display the texture, and then animating the
|
||||
change from texture to texture with `AnimationPlayer`.
|
||||
|
||||
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
|
||||
|
||||
.. note:: The root node could also be `Area2D <class_Area2D>` or
|
||||
`RigidBody2D <class_RigidBody2D>`. The animation will still be
|
||||
.. note:: The root node could also be `Area2D` or
|
||||
`RigidBody2D`. The animation will still be
|
||||
made in the same way. Once the animation is completed, you can
|
||||
assign a shape to the CollisionShape2D. See
|
||||
`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``
|
||||
properties when a character turns while starting a 'turning' animation),
|
||||
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,
|
||||
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)``
|
||||
|
@ -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 as their common root) will reside in a *Canvas Layer*. Every
|
||||
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,
|
||||
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
|
||||
`Transform2D <class_Transform2D>`). This is the master transform and
|
||||
`Transform2D`). This is the master transform and
|
||||
affects all individual *Canvas Layer* transforms. Generally, this
|
||||
transform is not of much use, but is used in the CanvasItem 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
|
||||
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
|
||||
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.
|
||||
|
||||
Transform order
|
||||
@ -62,11 +62,11 @@ Obtaining each transform can be achieved with the following functions:
|
||||
+----------------------------------+---------------------------------------------------------------------------------------------+
|
||||
| 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
|
||||
|
@ -6,20 +6,20 @@ Canvas layers
|
||||
Viewport and Canvas items
|
||||
-------------------------
|
||||
|
||||
`CanvasItem <class_CanvasItem>` is the base for all 2D nodes, be it regular
|
||||
2D nodes, such as `Node2D <class_Node2D>`, or `Control <class_Control>`.
|
||||
Both inherit from `CanvasItem <class_CanvasItem>`.
|
||||
`CanvasItem` is the base for all 2D nodes, be it regular
|
||||
2D nodes, such as `Node2D`.
|
||||
Both inherit from `CanvasItem`.
|
||||
You can arrange canvas items in trees. Each item will inherit its parent's
|
||||
transform: when the parent moves, its children move too.
|
||||
|
||||
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
|
||||
`Viewport.canvas_transform <class_Viewport_property_canvas_transform>`,
|
||||
allows to apply a custom `Transform2D <class_Transform2D>`
|
||||
`Viewport.canvas_transform`,
|
||||
allows to apply a custom `Transform2D`
|
||||
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
|
||||
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
|
||||
------------
|
||||
|
||||
The answer is `CanvasLayer <class_CanvasLayer>`,
|
||||
The answer is `CanvasLayer`,
|
||||
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
|
||||
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
|
||||
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
|
||||
(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,
|
||||
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
|
||||
`Control <class_Control>` or `Node2D <class_Node2D>`
|
||||
`Control`
|
||||
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:
|
||||
@ -30,9 +30,9 @@ Custom drawing in a 2D node is *really* useful. Here are some use cases:
|
||||
Drawing
|
||||
-------
|
||||
|
||||
Add a script to any `CanvasItem <class_CanvasItem>`
|
||||
derived node, like `Control <class_Control>` or
|
||||
`Node2D <class_Node2D>`. Then override the ``_draw()`` function.
|
||||
Add a script to any `CanvasItem`
|
||||
derived node, like `Control` or
|
||||
`Node2D`. Then override the ``_draw()`` function.
|
||||
|
||||
gdscript GDScript
|
||||
|
||||
@ -44,7 +44,7 @@ gdscript GDScript
|
||||
pass
|
||||
```
|
||||
|
||||
Draw commands are described in the `CanvasItem <class_CanvasItem>`
|
||||
Draw commands are described in the `CanvasItem`
|
||||
class reference. There are plenty of them.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
optimized for drawing large numbers of tiles. Finally, you can add collision,
|
||||
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
|
||||
------------
|
||||
|
||||
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
|
||||
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
|
||||
`TileSet <class_TileSet>`. A TileSet is a
|
||||
`Resource <class_Resource>` that contains the data about your
|
||||
`TileSet`. A TileSet is a
|
||||
`Resource` that contains the data about your
|
||||
tiles - their textures, collision shapes, and other properties. When the game
|
||||
runs, the TileMap combines the individual tiles into a single object.
|
||||
|
||||
@ -340,7 +340,7 @@ to take effect.
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
the CSG nodes:
|
||||
|
||||
- `CSGBox <class_CSGBox>`
|
||||
- `CSGCylinder <class_CSGCylinder>` (also supports cone)
|
||||
- `CSGSphere <class_CSGSphere>`
|
||||
- `CSGTorus <class_CSGTorus>`
|
||||
- `CSGPolygon <class_CSGPolygon>`
|
||||
- `CSGMesh <class_CSGMesh>`
|
||||
- `CSGCombiner <class_CSGcombiner>`
|
||||
- `CSGBox`
|
||||
- `CSGCylinder` (also supports cone)
|
||||
- `CSGSphere`
|
||||
- `CSGTorus`
|
||||
- `CSGPolygon`
|
||||
- `CSGMesh`
|
||||
- `CSGCombiner`
|
||||
|
||||
.. image:: img/csg_nodes.png
|
||||
|
||||
@ -59,7 +59,7 @@ Every CSG node supports 3 kinds of boolean operations:
|
||||
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:
|
||||
|
||||
- **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
|
||||
|
||||
.. 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
|
||||
CSGPolygon will extrude along the given path.
|
||||
|
||||
@ -79,7 +79,7 @@ The `CSGPolygon <class_CSGPolygon>` node extrude along a Polygon drawn in
|
||||
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
|
||||
supported. There are some restrictions for geometry:
|
||||
|
||||
@ -93,7 +93,7 @@ supported. There are some restrictions for geometry:
|
||||
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.
|
||||
|
||||
Processing order
|
||||
|
@ -101,7 +101,7 @@ Scene linear to display-referred nonlinear
|
||||
|
||||
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
|
||||
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**
|
||||
conversions must always be **both** enabled. Failing to enable one of them will
|
||||
@ -111,8 +111,8 @@ indie games.
|
||||
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
|
||||
`WorldEnvironment <class_WorldEnvironment>`
|
||||
`WorldEnvironment`
|
||||
node or set in a Camera node. For more information, see
|
||||
`doc_environment_and_post_processing`.
|
||||
|
@ -19,9 +19,9 @@ to develop 3D games efficiently.
|
||||
Spatial node
|
||||
~~~~~~~~~~~~
|
||||
|
||||
`Node2D <class_Node2D>` is the base node for 2D.
|
||||
`Control <class_Control>` is the base node for everything GUI.
|
||||
Following this reasoning, the 3D engine uses the `Spatial <class_Spatial>`
|
||||
`Node2D` is the base node for 2D.
|
||||
`Control` is the base node for everything GUI.
|
||||
Following this reasoning, the 3D engine uses the `Spatial`
|
||||
node for everything 3D.
|
||||
|
||||
.. 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
|
||||
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
|
||||
`Transform <class_Transform>`, or as 3 `Vector3 <class_Vector3>`
|
||||
`Transform`
|
||||
members representing location, Euler rotation (X, Y and Z angles) and
|
||||
scale.
|
||||
|
||||
@ -56,16 +56,16 @@ entire scenes (just as they look in the DCC), including animation,
|
||||
skeletal rigs, blend shapes, etc.
|
||||
|
||||
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.
|
||||
|
||||
Generated geometry
|
||||
------------------
|
||||
|
||||
It is possible to create custom geometry by using the
|
||||
`ArrayMesh <class_ArrayMesh>` resource directly. Simply create your arrays
|
||||
and use the `ArrayMesh.add_surface_from_arrays() <class_ArrayMesh_method_add_surface_from_arrays>`
|
||||
function. A helper class is also available, `SurfaceTool <class_SurfaceTool>`,
|
||||
`ArrayMesh` resource directly. Simply create your arrays
|
||||
and use the `ArrayMesh.add_surface_from_arrays()`
|
||||
function. A helper class is also available, `SurfaceTool`,
|
||||
which provides a more straightforward API and helpers for indexing,
|
||||
generating normals, tangents, etc.
|
||||
|
||||
@ -78,7 +78,7 @@ Immediate geometry
|
||||
|
||||
If, instead, there is a requirement to generate simple geometry that
|
||||
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,
|
||||
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
|
||||
3D environment. By using a fixed camera (either orthogonal or
|
||||
perspective) that does not rotate, nodes such as
|
||||
`Sprite3D <class_Sprite3D>` and
|
||||
`AnimatedSprite3D <class_AnimatedSprite3D>`
|
||||
`Sprite3D` and
|
||||
`AnimatedSprite3D`
|
||||
can be used to create 2D games that take advantage of mixing with 3D
|
||||
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.
|
||||
Godot provides a `WorldEnvironment <class_WorldEnvironment>`
|
||||
Godot provides a `WorldEnvironment`
|
||||
node that allows changing the background color, mode (as in, put a
|
||||
skybox), and applying several types of built-in post-processing effects.
|
||||
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
|
||||
displayed unless a `Camera <class_Camera>` is
|
||||
displayed unless a `Camera` is
|
||||
also added to the scene. Cameras can work in either orthogonal or
|
||||
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).
|
||||
- Light Nodes: Directional, Omni and Spot.
|
||||
- Ambient Light in the
|
||||
`Environment <class_Environment>`.
|
||||
`Environment`.
|
||||
- Baked Light (read `doc_baked_lightmaps`).
|
||||
|
||||
The emission color is a material property. You can read more about it
|
||||
|
@ -3,9 +3,9 @@
|
||||
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.
|
||||
|
||||
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
|
||||
- ``ARRAY_VERTEX``
|
||||
- `PoolVector3Array <class_PoolVector3Array>` or `PoolVector2Array <class_PoolVector2Array>`
|
||||
- `PoolVector3Array`
|
||||
|
||||
* - 1
|
||||
- ``ARRAY_NORMAL``
|
||||
- `PoolVector3Array <class_PoolVector3Array>`
|
||||
- `PoolVector3Array`
|
||||
|
||||
* - 2
|
||||
- ``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.
|
||||
|
||||
* - 3
|
||||
- ``ARRAY_COLOR``
|
||||
- `PoolColorArray <class_PoolColorArray>`
|
||||
- `PoolColorArray`
|
||||
|
||||
* - 4
|
||||
- ``ARRAY_TEX_UV``
|
||||
- `PoolVector2Array <class_PoolVector2Array>` or `PoolVector3Array <class_PoolVector3Array>`
|
||||
- `PoolVector2Array`
|
||||
|
||||
* - 5
|
||||
- ``ARRAY_TEX_UV2``
|
||||
- `PoolVector2Array <class_PoolVector2Array>` or `PoolVector3Array <class_PoolVector3Array>`
|
||||
- `PoolVector2Array`
|
||||
|
||||
* - 6
|
||||
- ``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
|
||||
- ``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
|
||||
- ``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.
|
||||
|
||||
@ -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
|
||||
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
|
||||
---------
|
||||
|
||||
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
|
||||
from code without creating one.
|
||||
|
||||
@ -239,7 +239,7 @@ gdscript GDScript
|
||||
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.
|
||||
|
||||
gdscript GDScript
|
||||
|
@ -3,7 +3,7 @@
|
||||
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
|
||||
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.
|
||||
``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
|
||||
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.
|
||||
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?
|
||||
---------------
|
||||
|
||||
Many things in Godot have mesh in their name: the `Mesh <class_Mesh>`, the `ArrayMesh <class_ArrayMesh>`,
|
||||
the `MeshInstance <class_MeshInstance>`, the `MultiMesh <class_MultiMesh>`, and
|
||||
the `MultiMeshInstance <class_MultiMeshInstance>`. While they are all related, they have slightly different uses.
|
||||
Many things in Godot have mesh in their name: the `Mesh`,
|
||||
the `MeshInstance`, and
|
||||
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 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
|
||||
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.
|
||||
|
||||
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
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
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
|
||||
``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.
|
||||
|
||||
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
|
||||
======================
|
||||
|
||||
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.
|
||||
|
||||
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,
|
||||
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
|
||||
|
||||
|
@ -3,8 +3,8 @@
|
||||
Using the SurfaceTool
|
||||
=====================
|
||||
|
||||
The `SurfaceTool <class_surfacetool>` provides a useful interface for constructing geometry.
|
||||
The interface is similar to the `ImmediateGeometry <class_immediategeometry>` node. You
|
||||
The `SurfaceTool` provides a useful interface for constructing geometry.
|
||||
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
|
||||
captures the attributes.
|
||||
|
||||
@ -22,8 +22,8 @@ gdscript GDScript
|
||||
st.add_normal() # Normal never added to a vertex.
|
||||
```
|
||||
|
||||
When finished generating your geometry with the `SurfaceTool <class_surfacetool>`
|
||||
call ``commit()`` to finish generating the mesh. If an `ArrayMesh <class_ArrayMesh>` is passed
|
||||
When finished generating your geometry with the `SurfaceTool`
|
||||
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
|
||||
in, ``commit()`` returns an ArrayMesh.
|
||||
|
||||
|
@ -6,7 +6,7 @@ Using GridMaps
|
||||
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>`
|
||||
works in 2D. You start with a predefined collection of 3D meshes (a
|
||||
`class_MeshLibrary`) that can be placed on a grid,
|
||||
|
@ -6,13 +6,13 @@ Using MultiMeshInstance
|
||||
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
|
||||
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
|
||||
manually. This may be a tedious process and the result may look mechanical.
|
||||
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.
|
||||
|
||||
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.
|
||||
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:
|
||||
|
||||
.. image:: img/multimesh_scene_tree.png
|
||||
|
@ -6,13 +6,13 @@ Using AnimationTree
|
||||
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,
|
||||
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.
|
||||
|
||||
`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.
|
||||
|
||||
Creating an AnimationTree
|
||||
@ -193,7 +193,7 @@ transformation visually (the animation will stay in place).
|
||||
|
||||
.. 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
|
||||
|
||||
@ -201,7 +201,7 @@ gdscript GDScript
|
||||
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
|
||||
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
|
||||
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).
|
||||
|
||||
|
||||
|
@ -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,
|
||||
etc.
|
||||
- **Custom Shaped Elements**: Custom shapes can be created with
|
||||
`Polygon2D <class_Polygon2D>`
|
||||
`Polygon2D`
|
||||
allowing UV animation, deformations, etc.
|
||||
- **Particle Systems**: A cutout animation rig can be combined with particle
|
||||
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.
|
||||
|
||||
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:
|
||||
|
||||
.. image:: img/tuto_cutout4.png
|
||||
@ -130,7 +130,7 @@ of the torso. We'll fix this problem with ``RemoteTransform2D`` nodes.
|
||||
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
|
||||
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.
|
||||
|
||||
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
|
||||
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
|
||||
`Engine.time_scale<class_Engine_property_time_scale>`.
|
||||
- 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
|
||||
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
|
||||
|
@ -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
|
||||
need to use the `Resource Loader<class_ResourceLoader>` as it will
|
||||
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.
|
||||
|
||||
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
|
||||
--------------------------
|
||||
|
@ -258,7 +258,7 @@ Reverb
|
||||
|
||||
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
|
||||
from `Areas <class_Area>`
|
||||
from `Areas`
|
||||
(see `Reverb buses <doc_audio_streams_reverb_buses>`), or to apply
|
||||
a "chamber" feel to all sounds.
|
||||
|
||||
|
@ -43,9 +43,9 @@ gdscript GDScript
|
||||
|
||||
The audio recording is handled by the `class_AudioEffectRecord` resource
|
||||
which has three methods:
|
||||
`get_recording() <class_AudioEffectRecord_method_get_recording>`,
|
||||
`is_recording_active() <class_AudioEffectRecord_method_is_recording_active>`,
|
||||
and `set_recording_active() <class_AudioEffectRecord_method_set_recording_active>`.
|
||||
`get_recording()`,
|
||||
`is_recording_active()`,
|
||||
and `set_recording_active()`.
|
||||
|
||||
gdscript GDScript
|
||||
|
||||
|
@ -6,7 +6,7 @@ Autoloads versus regular nodes
|
||||
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:
|
||||
`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
|
||||
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:
|
||||
|
||||
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
|
||||
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
|
||||
`Variant <https://docs.godotengine.org/en/latest/development/cpp/variant_class.html>`_
|
||||
class. Variants can store Variant-compatible data structures such as
|
||||
`Array <class_Array>` and `Dictionary <class_Dictionary>` as well as
|
||||
`Object <class_Object>` s.
|
||||
`Array` as well as
|
||||
`Object` s.
|
||||
|
||||
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
|
||||
@ -54,7 +54,7 @@ to each other.
|
||||
array object in traditional C++ libraries. It is a "templated"
|
||||
type, meaning that its records can only contain a particular type (denoted
|
||||
by angled brackets). So, for example, a
|
||||
`PoolStringArray <class_PoolStringArray>` would be something like
|
||||
`PoolStringArray` would be something like
|
||||
a ``Vector<String>``.
|
||||
|
||||
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.
|
||||
Objects query data sources when posed questions. For example, to answer
|
||||
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
|
||||
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?
|
||||
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.
|
||||
Users can manipulate...
|
||||
|
||||
@ -291,21 +291,21 @@ Users can manipulate...
|
||||
|
||||
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
|
||||
involves no extra logic on the part of the engine. The bad news is
|
||||
that users have very little control.
|
||||
|
||||
Also note that AnimatedTexture is a `Resource <class_Resource>` unlike
|
||||
the other `Node <class_Node>` objects discussed here. One might create
|
||||
a `Sprite <class_Sprite>` node that uses AnimatedTexture as its texture.
|
||||
Also note that AnimatedTexture is a `Resource` unlike
|
||||
the other `Node` objects discussed here. One might create
|
||||
a `Sprite` node that uses AnimatedTexture as its texture.
|
||||
Or (something the others can't do) one could add AnimatedTextures as tiles
|
||||
in a `TileSet <class_TileSet>` and integrate it with a
|
||||
`TileMap <class_TileMap>` for many auto-animating backgrounds that
|
||||
in a `TileSet` and integrate it with a
|
||||
`TileMap` for many auto-animating backgrounds that
|
||||
all render in a single batched draw call.
|
||||
|
||||
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,
|
||||
and control their speed, regional offset, and orientation. This makes them
|
||||
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
|
||||
example, create particle effects, call functions, or manipulate other
|
||||
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.
|
||||
|
||||
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
|
||||
for blending, i.e. enabling smooth transitions between these animations. There
|
||||
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
|
||||
`here <doc_animation_tree>`.
|
||||
|
@ -15,7 +15,7 @@ The rest of this tutorial outlines the various ways of doing all this.
|
||||
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.
|
||||
|
||||
gdscript GDScript
|
||||
@ -25,9 +25,9 @@ gdscript GDScript
|
||||
var obj = node.get_object() # Method access.
|
||||
```
|
||||
|
||||
The same principle applies for `Reference <class_Reference>` objects.
|
||||
While users often access `Node <class_Node>` and
|
||||
`Resource <class_Resource>` this way, alternative measures are available.
|
||||
The same principle applies for `Reference` objects.
|
||||
While users often access `Node` and
|
||||
`Resource` this way, alternative measures are available.
|
||||
|
||||
Instead of property or method access, one can get Resources by load
|
||||
access.
|
||||
@ -72,7 +72,7 @@ Note the following:
|
||||
|
||||
3. Keep in mind that loading a resource fetches the cached resource
|
||||
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()``.
|
||||
|
||||
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**.
|
||||
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
|
||||
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:
|
||||
|
||||
- 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.
|
||||
|
||||
- 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.
|
||||
`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,
|
||||
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
|
||||
`CanvasItem.visible <class_CanvasItem_property_visible>`, one can
|
||||
`CanvasItem.visible`, one can
|
||||
access the methods, ``set_visible`` and ``is_visible`` like any other method.
|
||||
|
||||
gdscript GDScript
|
||||
@ -262,7 +262,7 @@ gdscript GDScript
|
||||
# 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
|
||||
this case, one relies on an external context to setup the method.
|
||||
|
||||
|
@ -4,10 +4,10 @@ Godot notifications
|
||||
===================
|
||||
|
||||
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
|
||||
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)``.
|
||||
|
||||
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
|
||||
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.
|
||||
|
||||
- `Object::NOTIFICATION_PREDELETE <class_Object_constant_NOTIFICATION_PREDELETE>`:
|
||||
- `Object::NOTIFICATION_PREDELETE`:
|
||||
a callback that triggers before the engine deletes an Object, i.e. a
|
||||
'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
|
||||
system that displays the game content.
|
||||
|
||||
And many of the callbacks that *do* exist in Nodes don't have any dedicated
|
||||
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.
|
||||
|
||||
- `Node::NOTIFICATION_UNPARENTED <class_Node_constant_NOTIFICATION_UNPARENTED>`:
|
||||
- `Node::NOTIFICATION_UNPARENTED`:
|
||||
a callback that triggers anytime one removes a child node from another
|
||||
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.
|
||||
Note the difference from its ``about_to_show`` signal which triggers
|
||||
*before* its appearance.
|
||||
@ -62,7 +62,7 @@ One can access all these custom notifications from the universal
|
||||
overridden by scripts.
|
||||
|
||||
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
|
||||
(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,
|
||||
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
|
||||
a custom signal on the parent node without failing. Useful on data-centric
|
||||
nodes that one might create at runtime.
|
||||
|
@ -10,15 +10,15 @@ Loading vs. preloading
|
||||
----------------------
|
||||
|
||||
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
|
||||
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 in-place which can cause slowdowns when it occurs in the middle of
|
||||
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.
|
||||
|
||||
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
|
||||
properties, then one can set them to ``null`` and remove all references
|
||||
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).
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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,
|
||||
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
|
||||
further references to themselves exist. These are useful in the majority of
|
||||
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.
|
||||
|
||||
- **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)
|
||||
their object properties to/from Godot resource files.
|
||||
|
||||
- **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.
|
||||
|
||||
- **Advantages:** Much has
|
||||
`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,
|
||||
their main advantage is in Inspector-compatibility. While nearly as
|
||||
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).
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
gdscript GDScript
|
||||
@ -157,12 +157,12 @@ gdscript GDScript
|
||||
|
||||
To avoid creating and maintaining such documentation, one converts the
|
||||
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
|
||||
warning icon with the string as a tooltip by the node. This is the same icon
|
||||
that appears for nodes such as the
|
||||
`Area2D <class_Area2D>` node when it has no child
|
||||
`CollisionShape2D <class_CollisionShape2D>` nodes defined. The editor
|
||||
`Area2D` node when it has no child
|
||||
`CollisionShape2D` nodes defined. The editor
|
||||
then self-documents the scene through the script code. No content duplication
|
||||
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
|
||||
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
|
||||
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
|
||||
relative to each other. One can use the
|
||||
`RemoteTransform <class_RemoteTransform>` /
|
||||
`RemoteTransform2D <class_RemoteTransform2D>` nodes for this purpose.
|
||||
`RemoteTransform` /
|
||||
`RemoteTransform2D` nodes for this purpose.
|
||||
They will allow a target node to conditionally inherit selected transform
|
||||
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.
|
||||
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
|
||||
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
|
||||
information to their children.
|
||||
2. The **imperative** solution: Use the ``set_as_toplevel`` setter for the
|
||||
`CanvasItem <class_CanvasItem_method_set_as_toplevel>` or
|
||||
`Spatial <class_Spatial_method_set_as_toplevel>` node. This will make
|
||||
`CanvasItem` or
|
||||
`Spatial` node. This will make
|
||||
the node ignore its inherited transform.
|
||||
|
||||
.. 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.
|
||||
|
||||
- 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>`
|
||||
|
||||
|
@ -16,7 +16,7 @@ how they work under the hood.
|
||||
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.
|
||||
|
||||
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
|
||||
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``.
|
||||
|
||||
.. note::
|
||||
|
||||
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
|
||||
a `Node <class_Node>`.
|
||||
a `Node`.
|
||||
|
||||
Scenes
|
||||
------
|
||||
|
@ -60,7 +60,7 @@ Command line reference
|
||||
+------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| ``--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). |
|
||||
+------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
|
@ -82,7 +82,7 @@ process will build that type of file for the chosen platform.
|
||||
build of the engine or have access to one (distributed alongside or
|
||||
perhaps in the original game's files). The tool can then use the Godot
|
||||
executable to export a PCK file from the command line with
|
||||
`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
|
||||
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.
|
||||
|
||||
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::
|
||||
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::
|
||||
|
||||
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.
|
||||
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
|
||||
|
@ -51,7 +51,7 @@ locale.
|
||||
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.
|
||||
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.
|
||||
@ -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().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
|
||||
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
|
||||
this, make sure to read the tutorial on `doc_size_and_anchors`, as
|
||||
dynamically adjusting control sizes may help.
|
||||
`Container <class_Container>` can be useful, as well as the text wrapping
|
||||
options available in `Label <class_Label>`.
|
||||
`Container` can be useful, as well as the text wrapping
|
||||
options available in `Label`.
|
||||
|
||||
TranslationServer
|
||||
-----------------
|
||||
|
||||
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;
|
||||
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 .
|
||||
|
||||
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
|
||||
"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
|
||||
`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
|
||||
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
|
||||
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.
|
||||
|
||||
My controller works on a given platform, but not on another platform.
|
||||
|
@ -59,7 +59,7 @@ gdscript GDScript
|
||||
```
|
||||
|
||||
.. note::
|
||||
Check `Input.set_custom_mouse_cursor() <class_Input_method_set_custom_mouse_cursor>`.
|
||||
Check `Input.set_custom_mouse_cursor()`.
|
||||
|
||||
|
||||
Demo project
|
||||
@ -71,4 +71,4 @@ https://github.com/guilhermefelipecgs/custom_hardware_cursor
|
||||
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
|
||||
-------------------------
|
||||
|
||||
On desktop platforms, the `MainLoop <class_MainLoop>`
|
||||
On desktop platforms, the `MainLoop`
|
||||
has a special ``MainLoop.NOTIFICATION_WM_QUIT_REQUEST`` notification that is
|
||||
sent to all nodes when quitting is requested.
|
||||
|
||||
@ -53,10 +53,10 @@ gdscript GDScript
|
||||
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
|
||||
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 delay the line that forces the quit.
|
||||
|
||||
|
@ -6,7 +6,7 @@ Input examples
|
||||
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
|
||||
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
|
||||
@ -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
|
||||
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
|
||||
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.
|
||||
|
||||
Examples:
|
||||
@ -51,7 +51,7 @@ events in ``_input()``.
|
||||
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
|
||||
related to that event. To see what events actually look like, add a Node and
|
||||
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
|
||||
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:
|
||||
|
||||
- `InputEvent <class_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`.
|
||||
- `InputEventMouse <class_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.
|
||||
- `InputEvent` - the base class for all input events
|
||||
- `InputEventWithModifiers` - adds the ability to check if modifiers are pressed, such as :kbd:`Shift` or :kbd:`Alt`.
|
||||
- `InputEventMouse` - adds mouse event properties, such as ``position``
|
||||
- `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
|
||||
with events so you can check the event type's available properties and
|
||||
@ -109,7 +109,7 @@ gdscript GDScript
|
||||
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
|
||||
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
|
||||
@ -136,7 +136,7 @@ gdscript GDScript
|
||||
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
|
||||
you want to specifically look at key events. For this example, let's check for
|
||||
the :kbd:`T`:
|
||||
@ -170,7 +170,7 @@ Keyboard modifiers
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
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 want one thing to happen when the :kbd:`T` is pressed, but something
|
||||
different when it's :kbd:`Shift + T`:
|
||||
@ -193,9 +193,9 @@ gdscript GDScript
|
||||
Mouse events
|
||||
------------
|
||||
|
||||
Mouse events stem from the `InputEventMouse <class_InputEventMouse>` class, and
|
||||
are separated into two types: `InputEventMouseButton <class_InputEventMouseButton>`
|
||||
and `InputEventMouseMotion <class_InputEventMouseMotion>`. Note that this
|
||||
Mouse events stem from the `InputEventMouse` class, and
|
||||
are separated into two types: `InputEventMouseButton`
|
||||
and `InputEventMouseMotion`. Note that this
|
||||
means that all mouse events will contain a ``position`` property.
|
||||
|
||||
Mouse buttons
|
||||
@ -221,11 +221,11 @@ gdscript GDScript
|
||||
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``
|
||||
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:
|
||||
|
||||
gdscript GDScript
|
||||
@ -257,8 +257,8 @@ Touch events
|
||||
------------
|
||||
|
||||
If you are using a touchscreen device, you can generate touch events.
|
||||
`InputEventScreenTouch <class_InputEventScreenTouch>` is equivalent to
|
||||
a mouse click event, and `InputEventScreenDrag <class_InputEventScreenDrag>`
|
||||
`InputEventScreenTouch` is equivalent to
|
||||
a mouse click event, and `InputEventScreenDrag`
|
||||
works much the same as mouse motion.
|
||||
|
||||
.. 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
|
||||
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
|
||||
events. Input events travel through the engine and can be received in
|
||||
multiple locations, depending on the purpose.
|
||||
@ -23,7 +23,7 @@ gdscript GDScript
|
||||
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,
|
||||
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,
|
||||
@ -45,44 +45,44 @@ How does it work?
|
||||
Every input event is originated from the user/player (though it's
|
||||
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
|
||||
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
|
||||
provides a function to get the current SceneTree object :
|
||||
**get_tree()**.
|
||||
|
||||
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
|
||||
received input, in order:
|
||||
|
||||
.. image:: img/input_event_flow.png
|
||||
|
||||
1. First of all, the standard `Node._input() <class_Node_method__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>`).
|
||||
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
|
||||
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()`).
|
||||
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.
|
||||
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
|
||||
control can receive it. If so, the `Control <class_Control>` will be called via the
|
||||
virtual function `Control._gui_input() <class_Control_method__gui_input>` and the signal
|
||||
control can receive it. If so, the `Control` will be called via the
|
||||
virtual function `Control._gui_input()` and the signal
|
||||
"gui_input" will be emitted (this function is re-implementable by
|
||||
script by inheriting from it). If the control wants to "consume" the
|
||||
event, it will call `Control.accept_event() <class_Control_method_accept_event>` and the event will
|
||||
not spread any more. Use the `Control.mouse_filter <class_Control_property_mouse_filter>`
|
||||
property to control whether a `Control <class_Control>` is notified
|
||||
of mouse events via `Control._gui_input() <class_Control_method__gui_input>`
|
||||
event, it will call `Control.accept_event()` and the event will
|
||||
not spread any more. Use the `Control.mouse_filter`
|
||||
property to control whether a `Control` is notified
|
||||
of mouse events via `Control._gui_input()`
|
||||
callback, and whether these events are propagated further.
|
||||
3. If so far no one consumed the event, the unhandled input callback
|
||||
will be called if overridden (and not disabled with
|
||||
`Node.set_process_unhandled_input() <class_Node_method_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
|
||||
`Node.set_process_unhandled_input()`).
|
||||
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.
|
||||
4. If no one wanted the event so far, and a `Camera <class_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
|
||||
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
|
||||
`CollisionObject._input_event() <class_CollisionObject_method__input_event>` function in the relevant
|
||||
4. If no one wanted the event so far, and a `Camera` is assigned
|
||||
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`) If this ray hits an object, it will call the
|
||||
`CollisionObject._input_event()` function in the relevant
|
||||
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
|
||||
Viewport in the tree, otherwise it will be ignored.
|
||||
|
||||
@ -103,7 +103,7 @@ generalized behavior if needed.
|
||||
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
|
||||
(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 |
|
||||
+-------------------------------------------------------------------+--------------------+-----------------------------------------+
|
||||
| `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. |
|
||||
+-------------------------------------------------------------------+--------------------+-----------------------------------------+
|
||||
| `InputEventMouseButton <class_InputEventMouseButton>` | MOUSE_BUTTON | Contains click information, such as |
|
||||
| `InputEventMouseButton` | MOUSE_BUTTON | Contains click information, such as |
|
||||
| | | 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. |
|
||||
+-------------------------------------------------------------------+--------------------+-----------------------------------------+
|
||||
| `InputEventJoypadMotion <class_InputEventJoypadMotion>` | JOYSTICK_MOTION | Contains Joystick/Joypad analog axis |
|
||||
| `InputEventJoypadMotion` | JOYSTICK_MOTION | Contains Joystick/Joypad analog axis |
|
||||
| | | information. |
|
||||
+-------------------------------------------------------------------+--------------------+-----------------------------------------+
|
||||
| `InputEventJoypadButton <class_InputEventJoypadButton>` | JOYSTICK_BUTTON | Contains Joystick/Joypad button |
|
||||
| `InputEventJoypadButton` | JOYSTICK_BUTTON | Contains Joystick/Joypad button |
|
||||
| | | information. |
|
||||
+-------------------------------------------------------------------+--------------------+-----------------------------------------+
|
||||
| `InputEventScreenTouch <class_InputEventScreenTouch>` | SCREEN_TOUCH | Contains multi-touch press/release |
|
||||
| `InputEventScreenTouch` | SCREEN_TOUCH | Contains multi-touch press/release |
|
||||
| | | information. (only available on mobile |
|
||||
| | | devices) |
|
||||
+-------------------------------------------------------------------+--------------------+-----------------------------------------+
|
||||
| `InputEventScreenDrag <class_InputEventScreenDrag>` | SCREEN_DRAG | Contains multi-touch drag information. |
|
||||
| `InputEventScreenDrag` | SCREEN_DRAG | Contains multi-touch drag information. |
|
||||
| | | (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 |
|
||||
| | | 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
|
||||
tab.
|
||||
|
||||
Any event has the methods `InputEvent.is_action() <class_InputEvent_method_is_action>`,
|
||||
`InputEvent.is_pressed() <class_InputEvent_method_is_pressed>` and `InputEvent <class_InputEvent>`.
|
||||
Any event has the methods `InputEvent.is_action()`,
|
||||
`InputEvent.is_pressed()`.
|
||||
|
||||
Alternatively, it may be desired to supply the game back with an action
|
||||
from the game code (a good example of this is detecting gestures).
|
||||
The Input singleton has a method for this:
|
||||
`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
|
||||
|
||||
@ -178,7 +178,7 @@ InputMap
|
||||
--------
|
||||
|
||||
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
|
||||
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
|
||||
|
@ -55,14 +55,14 @@ Project Settings:
|
||||
`editor data path <doc_data_paths_editor_data_paths>` in the
|
||||
``app_userdata/[project_name]`` folder. This is the default so that prototypes
|
||||
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
|
||||
to** Godot's editor data path, i.e. in the standard location for applications
|
||||
data.
|
||||
|
||||
* By default, the folder name will be inferred from the project name, but it
|
||||
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
|
||||
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
|
||||
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
|
||||
---------------------------------------------------
|
||||
|
||||
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.
|
||||
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
|
||||
using `OS.shell_open() <class_OS_method_shell_open>` since it only accepts
|
||||
using `OS.shell_open()` since it only accepts
|
||||
native OS paths.
|
||||
|
||||
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
|
||||
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.
|
||||
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
|
||||
is placed in a writable location (i.e. **not** Program Files or another
|
||||
directory that is read-only for regular users).
|
||||
|
@ -147,9 +147,9 @@ work and look in Godot.
|
||||
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
|
||||
|
||||
@ -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.
|
||||
|
||||
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
|
||||
---------
|
||||
|
@ -28,10 +28,10 @@ There are other types of interpolations, which will not be covered here. A recom
|
||||
Vector interpolation
|
||||
--------------------
|
||||
|
||||
Vector types (`Vector2 <class_Vector2>` and `Vector3 <class_Vector3>`) 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>`.
|
||||
Vector types (`Vector2`) can also be interpolated, they come with handy functions to do it
|
||||
`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:
|
||||
|
||||
@ -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).
|
||||
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:
|
||||
|
||||
|
@ -81,7 +81,7 @@ Getting a random number
|
||||
Let's look at some of the most commonly used functions and methods to generate
|
||||
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
|
||||
want to use the modulo operator (``%``) to bound the result between 0 and the
|
||||
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
|
||||
`doc_random_number_generation_weighted_random_probability` system, among
|
||||
other things.
|
||||
|
||||
`randfn() <class_RandomNumberGenerator_method_randfn>` returns a random
|
||||
`randfn()` returns a random
|
||||
floating-point number following a `normal distribution
|
||||
<https://en.wikipedia.org/wiki/Normal_distribution>`__. This means the returned
|
||||
value is more likely to be around the mean (0.0 by default),
|
||||
@ -117,7 +117,7 @@ gdscript GDScript
|
||||
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``
|
||||
and ``to``:
|
||||
|
||||
@ -239,7 +239,7 @@ gdscript GDScript
|
||||
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
|
||||
"weighted" probability where different outcomes have different likelihoods:
|
||||
|
||||
|
@ -69,8 +69,8 @@ gdscript GDScript
|
||||
$Node2D.position = Vector2(400, 300)
|
||||
```
|
||||
|
||||
Godot supports both `Vector2 <class_Vector2>` and
|
||||
`Vector3 <class_Vector3>` for 2D and 3D usage, respectively. The same
|
||||
Godot supports both `Vector2` and
|
||||
`Vector3` for 2D and 3D usage, respectively. The same
|
||||
mathematical rules discussed in this article apply to both types.
|
||||
|
||||
Member access
|
||||
@ -199,9 +199,9 @@ wall or other object:
|
||||
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
|
||||
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
|
||||
`KinematicBody2D <class_KinematicBody2D>`:
|
||||
`KinematicBody2D`:
|
||||
|
||||
|
||||
gdscript GDScript
|
||||
|
@ -67,7 +67,7 @@ by N and D. For example:
|
||||
|
||||
.. 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.
|
||||
|
||||
Basically, N and D can represent any plane in space, be it for 2D or 3D
|
||||
@ -114,7 +114,7 @@ gdscript GDScript
|
||||
D = -D
|
||||
```
|
||||
|
||||
Of course, Godot also implements this operator in `Plane <class_Plane>`,
|
||||
Of course, Godot also implements this operator in `Plane`,
|
||||
so doing:
|
||||
|
||||
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
|
||||
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
|
||||
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.
|
||||
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
|
||||
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.
|
||||
|
||||
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 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
|
||||
provides an implementation based on ENet (`NetworkedMultiplayerEnet <class_NetworkedMultiplayerENet>`),
|
||||
one based on WebRTC (`WebRTCMultiplayer <class_WebRTCMultiplayer>`), and one based on WebSocket
|
||||
(`WebSocketMultiplayerPeer <class_WebSocketMultiplayerPeer>`), but this could be used to implement
|
||||
provides an implementation based on ENet (`NetworkedMultiplayerEnet`),
|
||||
one based on WebRTC (`WebRTCMultiplayer`), and one based on WebSocket
|
||||
(`WebSocketMultiplayerPeer`), but this could be used to implement
|
||||
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.
|
||||
@ -73,7 +73,7 @@ Yet it is made available in case a game has specific needs for a lower level API
|
||||
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.
|
||||
|
||||
@ -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
|
||||
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:
|
||||
|
||||
@ -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.
|
||||
Clients will connect with a unique ID greater than 1, while network peer ID 1 is always the server.
|
||||
Anything below 1 should be handled as invalid.
|
||||
You can retrieve the ID for the local system via `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.
|
||||
|
||||
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
|
||||
in `Node <class_Node>`:
|
||||
in `Node`:
|
||||
|
||||
- ``rpc("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,
|
||||
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
|
||||
-------------
|
||||
@ -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):
|
||||
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>`.
|
||||
|
||||
@ -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.
|
||||
|
||||
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:
|
||||
|
||||
|
@ -3,8 +3,8 @@
|
||||
HTTP client class
|
||||
=================
|
||||
|
||||
`HTTPClient <class_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,
|
||||
`HTTPClient` provides low-level access to HTTP communication.
|
||||
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>`.
|
||||
|
||||
.. 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
|
||||
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:
|
||||
|
||||
console GDScript
|
||||
|
@ -3,8 +3,8 @@
|
||||
Making HTTP requests
|
||||
====================
|
||||
|
||||
The `HTTPRequest <class_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>`.
|
||||
The `HTTPRequest` node is the easiest way to make HTTP requests in Godot.
|
||||
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.
|
||||
|
||||
@ -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.
|
||||
|
||||
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"``.
|
||||
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
|
||||
"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
|
||||
`HTTPClient <class_HTTPClient>`
|
||||
`HTTPClient`
|
||||
class also supports HTTPS by using this same wrapper.
|
||||
|
||||
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
|
||||
---------------------
|
||||
|
||||
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>`__.
|
||||
|
||||
@ -212,4 +212,4 @@ This will print something similar to this:
|
||||
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
|
||||
------------------------
|
||||
|
||||
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::
|
||||
|
||||
|
@ -308,23 +308,23 @@ rendering/batching/options
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- `use_batching
|
||||
<class_ProjectSettings_property_rendering/batching/options/use_batching>` -
|
||||
` -
|
||||
Turns batching on or off.
|
||||
|
||||
- `use_batching_in_editor
|
||||
<class_ProjectSettings_property_rendering/batching/options/use_batching_in_editor>`
|
||||
`
|
||||
Turns batching on or off in the Godot editor.
|
||||
This setting doesn't affect the running project in any way.
|
||||
|
||||
- `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
|
||||
to flicker on some hardware so it's not recommended.
|
||||
|
||||
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
|
||||
adjacent items (nodes) together, however they can only be joined if the
|
||||
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.
|
||||
|
||||
- `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
|
||||
necessarily worth doing unless there are a lot of color changes going on
|
||||
within a joined item. This parameter represents the proportion of commands
|
||||
@ -341,12 +341,12 @@ rendering/batching/parameters
|
||||
baked colors.
|
||||
|
||||
- `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
|
||||
on performance but can be worth decreasing for mobile if RAM is at a premium.
|
||||
|
||||
- `item_reordering_lookahead
|
||||
<class_ProjectSettings_property_rendering/batching/parameters/item_reordering_lookahead>` -
|
||||
` -
|
||||
Item reordering can help especially with interleaved sprites using different
|
||||
textures. The lookahead for the overlap test has a small cost, so the best
|
||||
value may change per project.
|
||||
@ -355,11 +355,11 @@ rendering/batching/lights
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- `scissor_area_threshold
|
||||
<class_ProjectSettings_property_rendering/batching/lights/scissor_area_threshold>` -
|
||||
` -
|
||||
See light scissoring.
|
||||
|
||||
- `max_join_items
|
||||
<class_ProjectSettings_property_rendering/batching/lights/max_join_items>` -
|
||||
` -
|
||||
Joining items before lighting can significantly increase
|
||||
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
|
||||
@ -369,14 +369,14 @@ rendering/batching/debug
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- `flash_batching
|
||||
<class_ProjectSettings_property_rendering/batching/debug/flash_batching>` -
|
||||
` -
|
||||
This is purely a debugging feature to identify regressions between the
|
||||
batching and legacy renderer. When it is switched on, the batching and legacy
|
||||
renderer are used alternately on each frame. This will decrease performance,
|
||||
and should not be used for your final export, only for testing.
|
||||
|
||||
- `diagnose_frame
|
||||
<class_ProjectSettings_property_rendering/batching/debug/diagnose_frame>` -
|
||||
` -
|
||||
This will periodically print a diagnostic batching log to
|
||||
the Godot IDE / console.
|
||||
|
||||
@ -384,7 +384,7 @@ rendering/batching/precision
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- `uv_contract
|
||||
<class_ProjectSettings_property_rendering/batching/precision/uv_contract>` -
|
||||
` -
|
||||
On some hardware (notably some Android devices) there have been reports of
|
||||
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
|
||||
@ -392,7 +392,7 @@ rendering/batching/precision
|
||||
for precision errors on devices.
|
||||
|
||||
- `uv_contract_amount
|
||||
<class_ProjectSettings_property_rendering/batching/precision/uv_contract_amount>` -
|
||||
` -
|
||||
Hopefully, the default amount should cure artifacts on most devices,
|
||||
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 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
|
||||
is approximately twice as fast. However, it can result in flickering on some
|
||||
hardware, so its use is discouraged.
|
||||
@ -502,7 +502,7 @@ I am seeing line artifacts appear on certain hardware.
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- See the `uv_contract
|
||||
<class_ProjectSettings_property_rendering/batching/precision/uv_contract>`
|
||||
`
|
||||
project setting which can be used to solve this problem.
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
`Node.remove_child(node) <class_Node_method_remove_child>`, then reattach
|
||||
it later using `Node.add_child(node) <class_Node_method_add_child>`.
|
||||
`Node.remove_child(node)`, then reattach
|
||||
it later using `Node.add_child(node)`.
|
||||
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
|
||||
|
@ -71,7 +71,7 @@ through add-ons or may be available in core Godot in the future.
|
||||
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
|
||||
transparent objects. Transparent objects are rendered from back to front to make
|
||||
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
|
||||
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
|
||||
for flocks, grass, particles, and anything else where you have thousands of
|
||||
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
|
||||
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
|
||||
high cache efficiency.
|
||||
|
||||
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,
|
||||
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.
|
||||
The most common servers are:
|
||||
|
||||
* `VisualServer <class_VisualServer>`: handles everything related to graphics.
|
||||
* `PhysicsServer <class_PhysicsServer>`: handles everything related to 3D physics.
|
||||
* `Physics2DServer <class_Physics2DServer>`: handles everything related to 2D physics.
|
||||
* `AudioServer <class_AudioServer>`: handles everything related to audio.
|
||||
* `VisualServer`: handles everything related to graphics.
|
||||
* `PhysicsServer`: handles everything related to 3D physics.
|
||||
* `Physics2DServer`: handles everything related to 2D physics.
|
||||
* `AudioServer`: handles everything related to audio.
|
||||
|
||||
Explore their APIs and you will realize that all the functions provided are low-level
|
||||
implementations of everything Godot allows you to do.
|
||||
@ -44,38 +44,38 @@ implementations of everything Godot allows you to do.
|
||||
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
|
||||
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
|
||||
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.
|
||||
|
||||
.. 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
|
||||
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.
|
||||
|
||||
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.
|
||||
* 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.
|
||||
* 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.
|
||||
* For 3D, the `World <class_World>` resource (obtainable in the `Viewport <class_Viewport>`
|
||||
and `Spatial <class_Spatial>` nodes)
|
||||
* For 3D, the `World`
|
||||
and `Spatial` nodes)
|
||||
contains functions to get the *VisualServer Scenario*, and the *PhysicsServer Space*. This
|
||||
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>`
|
||||
and `CanvasItem <class_CanvasItem>` nodes)
|
||||
* For 2D, the `World2D`
|
||||
and `CanvasItem` nodes)
|
||||
contains functions to get the *VisualServer Canvas*, and the *Physics2DServer Space*. This
|
||||
allows creating 2D objects directly with the server API and using them.
|
||||
* The `VisualInstance<class_VisualInstance>` class, allows getting the scenario *instance* and
|
||||
*instance base* via the `VisualInstance.get_instance() <class_VisualInstance_method_get_instance>`
|
||||
and `VisualInstance.get_base() <class_VisualInstance_method_get_base>` respectively.
|
||||
*instance base* via the `VisualInstance.get_instance()`
|
||||
and `VisualInstance.get_base()` respectively.
|
||||
|
||||
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
|
||||
`CanvasItem <class_CanvasItem>` API.
|
||||
`CanvasItem` API.
|
||||
|
||||
gdscript GDScript
|
||||
|
||||
@ -160,8 +160,8 @@ gdscript GDScript
|
||||
Creating a 2D RigidBody and moving a sprite with it
|
||||
---------------------------------------------------
|
||||
|
||||
This creates a `RigidBody2D <class_RigidBody2D>` using the `Physics2DServer <class_Physics2DServer>` API,
|
||||
and moves a `CanvasItem <class_CanvasItem>` when the body moves.
|
||||
This creates a `RigidBody2D` API,
|
||||
and moves a `CanvasItem` when the body moves.
|
||||
|
||||
gdscript GDScript
|
||||
|
||||
@ -197,7 +197,7 @@ gdscript GDScript
|
||||
```
|
||||
|
||||
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
|
||||
-----------------------------
|
||||
|
@ -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
|
||||
static mesh instancing.
|
||||
|
||||
In Godot, this can be accomplished with a custom `Shader <class_Shader>` and
|
||||
a `MultiMeshInstance <class_MultiMeshInstance>`. Using the following technique you
|
||||
In Godot, this can be accomplished with a custom `Shader` and
|
||||
a `MultiMeshInstance`. Using the following technique you
|
||||
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
|
||||
@ -17,8 +17,8 @@ thousands of fish.
|
||||
Animating one Fish
|
||||
------------------
|
||||
|
||||
We will start with a single fish. Load your fish model into a `MeshInstance <class_MeshInstance>`
|
||||
and add a new `ShaderMaterial <class_ShaderMaterial>`.
|
||||
We will start with a single fish. Load your fish model into a `MeshInstance`
|
||||
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.
|
||||
|
||||
@ -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
|
||||
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
|
||||
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
|
||||
@ -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
|
||||
a school of fish.
|
||||
|
||||
Once you have a MultiMeshInstance add a `MultiMesh <class_MultiMesh>`, and to that
|
||||
MultiMesh add your `Mesh <class_Mesh>` with the shader from above.
|
||||
Once you have a MultiMeshInstance add a `MultiMesh`, and to that
|
||||
MultiMesh add your `Mesh` with the shader from above.
|
||||
|
||||
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
|
||||
a `Color <class_Color>`.
|
||||
a `Color`.
|
||||
|
||||
``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
|
||||
@ -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
|
||||
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.
|
||||
|
@ -3,20 +3,20 @@
|
||||
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
|
||||
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
|
||||
`Particles <class_Particles>` node. Particles take advantage of GPU acceleration
|
||||
by computing and setting the per-instance information in a `Shader <class_Shader>`.
|
||||
`Particles` node. Particles take advantage of GPU acceleration
|
||||
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.
|
||||
|
||||
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
|
||||
`ShaderMaterial <class_ShaderMaterial>`.
|
||||
`Mesh`. Then under "Process Material" create a new
|
||||
`ShaderMaterial`.
|
||||
|
||||
Set the ``shader_type`` to ``particles``.
|
||||
|
||||
@ -48,7 +48,7 @@ Then add the following two functions:
|
||||
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``.
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
dock.
|
||||
|
||||
@ -43,7 +43,7 @@ better performance as well.
|
||||
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
|
||||
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,
|
||||
@ -75,7 +75,7 @@ viewport. The editor exposes two generation modes:
|
||||
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
|
||||
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
|
||||
|
@ -101,8 +101,8 @@ Moving the kinematic character
|
||||
Go back to the character scene, and open the script, the magic begins
|
||||
now! Kinematic body will do nothing by default, but it has a
|
||||
useful function called
|
||||
`KinematicBody2D.move_and_collide() <class_KinematicBody2D_method_move_and_collide>`.
|
||||
This function takes a `Vector2 <class_Vector2>` as
|
||||
`KinematicBody2D.move_and_collide()`.
|
||||
This function takes a `Vector2` as
|
||||
an argument, and tries to apply that motion to the kinematic body. If a
|
||||
collision happens, it stops right at the moment of the collision.
|
||||
|
||||
|
@ -26,28 +26,28 @@ In this guide, you will learn:
|
||||
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
|
||||
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,
|
||||
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
|
||||
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
|
||||
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
|
||||
``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>`
|
||||
|
||||
- `KinematicBody2D <class_KinematicBody2D>`
|
||||
- `KinematicBody2D`
|
||||
A body that provides collision detection, but no physics. All movement and
|
||||
collision response must be implemented in code.
|
||||
|
||||
@ -61,15 +61,15 @@ and set if it's absorbent and/or rough.
|
||||
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
|
||||
and to detect contact with other objects.
|
||||
|
||||
.. note:: In order to detect collisions, at least one ``Shape2D`` must be
|
||||
assigned to the object.
|
||||
|
||||
The most common way to assign a shape is by adding a `CollisionShape2D <class_CollisionShape2D>`
|
||||
or `CollisionPolygon2D <class_CollisionPolygon2D>` as a child of the object.
|
||||
The most common way to assign a shape is by adding a `CollisionShape2D`
|
||||
or `CollisionPolygon2D` as a child of the object.
|
||||
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.
|
||||
@ -89,7 +89,7 @@ of a body's state variables such as ``position`` or ``linear velocity``
|
||||
may not be accurate for the current frame.
|
||||
|
||||
In order to avoid this inaccuracy, any code that needs to access a body's properties should
|
||||
be run in the `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
|
||||
(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
|
||||
@ -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
|
||||
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.
|
||||
|
||||
@ -216,7 +216,7 @@ RigidBody2D
|
||||
-----------
|
||||
|
||||
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
|
||||
collisions with other bodies, and collision responses, such as bouncing,
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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:
|
||||
|
||||
- **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.
|
||||
- **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
|
||||
~~~~~~~~~~~~~~~~~
|
||||
@ -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
|
||||
care - altering the ``position``, ``linear_velocity``, or other physics properties
|
||||
of a rigid body can result in unexpected behavior. If you need to alter any
|
||||
of the physics-related properties, you should use the `_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
|
||||
to the body's `Physics2DDirectBodyState <class_Physics2DDirectBodyState>`,
|
||||
to the body's `Physics2DDirectBodyState`,
|
||||
which allows for safely changing properties and synchronizing them with
|
||||
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()``
|
||||
function will not be called. To override this behavior, you will
|
||||
need to keep the body awake by creating a collision, applying a
|
||||
force to it, or by disabling the `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.
|
||||
|
||||
Contact reporting
|
||||
@ -299,19 +299,19 @@ Contact reporting
|
||||
|
||||
By default, rigid bodies do not keep track of contacts, because this can
|
||||
require a huge amount of memory if many bodies are in the scene. To enable
|
||||
contact reporting, set the `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
|
||||
`Physics2DDirectBodyState.get_contact_count() <class_Physics2DDirectBodyState_method_get_contact_count>`
|
||||
`Physics2DDirectBodyState.get_contact_count()`
|
||||
and related functions.
|
||||
|
||||
Contact monitoring via signals can be enabled via the `contact_monitor <class_RigidBody2D_property_contact_monitor>`
|
||||
property. See `RigidBody2D <class_RigidBody2D>` for the list of available
|
||||
Contact monitoring via signals can be enabled via the `contact_monitor`
|
||||
property. See `RigidBody2D` for the list of available
|
||||
signals.
|
||||
|
||||
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.
|
||||
Instead, they must be controlled by the user via code. The physics engine will
|
||||
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
|
||||
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
|
||||
`KinematicCollision2D <class_KinematicCollision2D>` object, which contains
|
||||
`KinematicCollision2D` object, which contains
|
||||
information about the collision and the colliding body. You can use this
|
||||
information to determine the response.
|
||||
|
||||
@ -368,7 +368,7 @@ gdscript GDScript
|
||||
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
|
||||
|
@ -18,7 +18,7 @@ Setting up the ragdoll
|
||||
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:
|
||||
|
||||
|
@ -14,7 +14,7 @@ do this in 2D and 3D.
|
||||
Godot stores all the low level game information in servers, while the
|
||||
scene is just a frontend. As such, ray casting is generally a
|
||||
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
|
||||
is.
|
||||
|
||||
@ -27,12 +27,12 @@ Space
|
||||
In the physics world, Godot stores all the low level collision and
|
||||
physics information in a *space*. The current 2d space (for 2D Physics)
|
||||
can be obtained by accessing
|
||||
`CanvasItem.get_world_2d().space <class_CanvasItem_method_get_world_2d>`.
|
||||
For 3D, it's `Spatial.get_world().space <class_Spatial_method_get_world>`.
|
||||
`CanvasItem.get_world_2d().space`.
|
||||
For 3D, it's `Spatial.get_world().space`.
|
||||
|
||||
The resulting space `RID <class_RID>` can be used in
|
||||
`PhysicsServer <class_PhysicsServer>` and
|
||||
`Physics2DServer <class_Physics2DServer>` respectively for 3D and 2D.
|
||||
The resulting space `RID` can be used in
|
||||
`PhysicsServer` and
|
||||
`Physics2DServer` respectively for 3D and 2D.
|
||||
|
||||
Accessing space
|
||||
---------------
|
||||
@ -40,13 +40,13 @@ Accessing space
|
||||
Godot physics runs by default in the same thread as game logic, but may
|
||||
be set to run on a separate thread to work more efficiently. Due to
|
||||
this, the only time accessing space is safe is during the
|
||||
`Node._physics_process() <class_Node_method__physics_process>`
|
||||
`Node._physics_process()`
|
||||
callback. Accessing it from outside this function may result in an error
|
||||
due to space being *locked*.
|
||||
|
||||
To perform queries into physics space, the
|
||||
`Physics2DDirectSpaceState <class_Physics2DDirectSpaceState>`
|
||||
and `PhysicsDirectSpaceState <class_PhysicsDirectSpaceState>`
|
||||
`Physics2DDirectSpaceState`
|
||||
and `PhysicsDirectSpaceState`
|
||||
must be used.
|
||||
|
||||
Use the following code in 2D:
|
||||
@ -81,7 +81,7 @@ Raycast query
|
||||
-------------
|
||||
|
||||
For performing a 2D raycast query, the method
|
||||
`Physics2DDirectSpaceState.intersect_ray() <class_Physics2DDirectSpaceState_method_intersect_ray>`
|
||||
`Physics2DDirectSpaceState.intersect_ray()`
|
||||
may be used. For example:
|
||||
|
||||
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
|
||||
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,
|
||||
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
|
||||
orthogonal. Because of this, both the ray origin and direction must be
|
||||
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.
|
||||
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
|
||||
---------------------------
|
||||
@ -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 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.
|
||||
See `RigidBody <class_RigidBody>` and `PhysicsMaterial <class_PhysicsMaterial>` for
|
||||
See `RigidBody` for
|
||||
the full list of properties and their effects.
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
~~~~~~~~~~~~
|
||||
|
||||
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.
|
||||
|
||||
@ -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.
|
||||
|
||||
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.
|
||||
|
||||
|
@ -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.
|
||||
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
|
||||
`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
|
||||
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
|
||||
`CollisionObject2D <class_CollisionObject2D>` nodes overlapping, entering,
|
||||
`CollisionObject2D` nodes overlapping, entering,
|
||||
and exiting. Areas also allow for overriding local physics properties. We'll
|
||||
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
|
||||
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``.
|
||||
|
||||
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.
|
||||
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
|
||||
`KinematicBody2D <class_KinematicBody2D>` node and show some examples
|
||||
`KinematicBody2D` node and show some examples
|
||||
of how to use it.
|
||||
|
||||
.. 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``
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
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
|
||||
frame timestep (``delta``). If the engine detects a collision anywhere along
|
||||
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
|
||||
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``
|
||||
|
||||
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``
|
||||
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.
|
||||
|
||||
See `KinematicCollision2D <class_KinematicCollision2D>` for details on what
|
||||
See `KinematicCollision2D` for details on what
|
||||
collision data is returned.
|
||||
|
||||
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
|
||||
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
|
||||
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.
|
||||
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:
|
||||
|
||||
|
@ -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
|
||||
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.
|
||||
|
||||
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
|
||||
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
|
||||
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`` |
|
||||
+---------------------------------------------------------------------------+-----------------+--------------------+
|
||||
|
||||
See the `ProjectSettings class documentation <class_ProjectSettings>`
|
||||
See the `ProjectSettings class documentation`
|
||||
for more information on those setting overrides.
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
know the import plugin isn't available anymore.
|
||||
|
||||
@ -81,7 +81,7 @@ The EditorImportPlugin class
|
||||
----------------------------
|
||||
|
||||
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
|
||||
with files.
|
||||
|
||||
@ -196,7 +196,7 @@ plugin:
|
||||
func get_preset_count():
|
||||
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
|
||||
now, but we can make this method future-proof by returning the size of our
|
||||
``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
|
||||
`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
|
||||
use short and clear names.
|
||||
|
||||
@ -237,7 +237,7 @@ you do this you have to be careful when you add more presets.
|
||||
return []
|
||||
|
||||
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
|
||||
checked to customize the option as its shown to the user. The following table
|
||||
shows the possible keys:
|
||||
@ -275,7 +275,7 @@ of options first and then change it based on the preset.
|
||||
return true
|
||||
|
||||
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
|
||||
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
|
||||
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:
|
||||
|
||||
::
|
||||
@ -302,7 +302,7 @@ method. Our sample code is a bit long, so let's split in a few parts:
|
||||
file.close()
|
||||
|
||||
The first part of our import method opens and reads the source file. We use the
|
||||
`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.
|
||||
|
||||
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,
|
||||
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
|
||||
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()
|
||||
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
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
A good practice is to use the virtual function
|
||||
`_enter_tree() <class_Node_method__enter_tree>` to initialize your plugin and
|
||||
`_exit_tree() <class_Node_method__exit_tree>` to clean it up. Thankfully,
|
||||
`_enter_tree()` to initialize your plugin and
|
||||
`_exit_tree()` to clean it up. Thankfully,
|
||||
the dialog generates these callbacks for you. Your script should look something
|
||||
like this:
|
||||
|
||||
@ -134,7 +134,7 @@ custom behavior.
|
||||
are writing GDScript or NativeScript, we recommend using Script Classes instead.
|
||||
|
||||
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
|
||||
(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
|
||||
@ -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
|
||||
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.
|
||||
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.
|
||||
@ -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
|
||||
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
|
||||
`EditorPlugin <class_EditorPlugin>` class.
|
||||
`add_control_to_dock()` from the
|
||||
`EditorPlugin` class.
|
||||
|
||||
You need to select a dock position and define the control to add
|
||||
(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
|
||||
`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
|
||||
the gizmo can be hidden or not.
|
||||
|
||||
@ -56,7 +56,7 @@ This would be a basic setup:
|
||||
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
|
||||
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()...).
|
||||
|
||||
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.
|
||||
|
||||
Alternative approach
|
||||
|
@ -136,10 +136,10 @@ Instancing scenes
|
||||
|
||||
You can instantiate packed scenes normally and add them to the scene currently
|
||||
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
|
||||
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.
|
||||
|
||||
If you are using ``tool``:
|
||||
|
@ -90,7 +90,7 @@ Resizing
|
||||
There are several types of devices, with several types of screens, which
|
||||
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
|
||||
little easier. The `Viewport <class_Viewport>`
|
||||
little easier. The `Viewport`
|
||||
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
|
||||
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
|
||||
demonstrate the effect of different stretch modes. A single sprite, also
|
||||
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
|
||||
|
||||
@ -143,7 +143,7 @@ demonstrate the effect of different stretch modes. A single sprite, also
|
||||
.. image:: img/stretch_2d_expand.gif
|
||||
|
||||
- **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.
|
||||
The scene is rendered to this viewport first. Finally, this viewport
|
||||
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
|
||||
``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
|
||||
-------------------------
|
||||
|
@ -6,23 +6,23 @@ Using Viewports
|
||||
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
|
||||
the Root `Viewport <class_Viewport>`.
|
||||
the Root `Viewport`.
|
||||
|
||||
.. image:: img/viewportnode.png
|
||||
|
||||
|
||||
`Viewports <class_Viewport>` 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>`
|
||||
`Viewports` can also be added to the scene so that there
|
||||
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
|
||||
of a render target by accessing its corresponding `texture <class_ViewportTexture>`.
|
||||
By using a `Viewport <class_Viewport>` as a render target,
|
||||
of a render target by accessing its corresponding `texture`.
|
||||
By using a `Viewport` as a render target,
|
||||
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.
|
||||
|
||||
`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 2D elements in a 3D game
|
||||
@ -37,10 +37,10 @@ what to do with the resulting texture.
|
||||
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
|
||||
nearest `Viewport <class_Viewport>` in the tree, but you can set `Viewports <class_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
|
||||
nearest `Viewport` not to receive input by checking
|
||||
'Disable Input' to 'on'; this will allow the next nearest `Viewport` in the tree to capture
|
||||
the input.
|
||||
|
||||
.. image:: img/input.png
|
||||
@ -52,27 +52,27 @@ Listener
|
||||
|
||||
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
|
||||
audible, the `Viewport <class_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
|
||||
audible, the `Viewport` needs to be enabled as a listener (for 2D or 3D).
|
||||
If you are using a custom `Viewport`, don't forget
|
||||
to enable this!
|
||||
|
||||
Cameras (2D & 3D)
|
||||
-----------------
|
||||
|
||||
When using a `Camera <class_Camera>` /
|
||||
`Camera2D <class_Camera2D>`, cameras will always display on the
|
||||
closest parent `Viewport <class_Viewport>` (going towards the root). For example, in the
|
||||
When using a `Camera` /
|
||||
`Camera2D`, cameras will always display on the
|
||||
closest parent `Viewport` (going towards the root). For example, in the
|
||||
following hierarchy:
|
||||
|
||||
.. image:: img/cameras.png
|
||||
|
||||
CameraA will display on the Root `Viewport <class_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
|
||||
hierarchy, it will still not be drawn to the Root `Viewport <class_Viewport>`. Similarly MeshA will not
|
||||
be visible from the `Viewport <class_Viewport>` node because `Viewport <class_Viewport>` nodes only
|
||||
CameraA will display on the Root `Viewport` and it will draw MeshA. CameraB
|
||||
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`. Similarly MeshA will not
|
||||
be visible from the `Viewport` nodes only
|
||||
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,
|
||||
or make it the current camera by calling:
|
||||
|
||||
@ -81,18 +81,18 @@ or make it the current camera by calling:
|
||||
camera.make_current()
|
||||
|
||||
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
|
||||
`VisualInstance's <class_VisualInstance>` `layer <class_VisualInstance_property_layers>`
|
||||
`cull_mask` property combined with the
|
||||
`VisualInstance's`
|
||||
property to restrict which objects are rendered.
|
||||
|
||||
Scale & stretching
|
||||
------------------
|
||||
|
||||
`Viewports <class_Viewport>` have a "size" property, which represents the size of the `Viewport <class_Viewport>`
|
||||
in pixels. For `Viewports <class_Viewport>` which are children of `ViewportContainers <class_viewportcontainer>`,
|
||||
`Viewports`
|
||||
in pixels. For `Viewports`,
|
||||
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:
|
||||
|
||||
::
|
||||
@ -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_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>`
|
||||
|
||||
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.
|
||||
Spatial-based nodes will register using the `World <class_World>` of the closest
|
||||
`Viewport <class_Viewport>`. By default, newly created `Viewports <class_Viewport>` do not contain a `World <class_World>` but
|
||||
use the same as their parent `Viewport <class_Viewport>` (the root `Viewport <class_Viewport>` always contains a
|
||||
`World <class_World>`, which is the one objects are rendered to by default). A `World <class_World>` can
|
||||
be set in a `Viewport <class_Viewport>` using the "world" property, and that will separate
|
||||
all children nodes of that `Viewport <class_Viewport>` from interacting with the parent
|
||||
`Viewport's <class_Viewport>` `World <class_World>`. This is especially useful in scenarios where, for
|
||||
Spatial-based nodes will register using the `World` of the closest
|
||||
`Viewport` but
|
||||
use the same as their parent `Viewport` always contains a
|
||||
`World` can
|
||||
be set in a `Viewport` using the "world" property, and that will separate
|
||||
all children nodes of that `Viewport` from interacting with the parent
|
||||
`Viewport's`. This is especially useful in scenarios where, for
|
||||
example, you might want to show a separate character in 3D imposed over
|
||||
the game (like in StarCraft).
|
||||
|
||||
As a helper for situations where you want to create `Viewports <class_Viewport>` that
|
||||
display single objects and don't want to create a `World <class_World>`, `Viewport <class_Viewport>` has
|
||||
the option to use its own `World <class_World>`. This is useful when you want to
|
||||
instance 3D characters or objects in a 2D `World <class_World2D>`.
|
||||
As a helper for situations where you want to create `Viewports` that
|
||||
display single objects and don't want to create a `World` has
|
||||
the option to use its own `World`. This is useful when you want to
|
||||
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
|
||||
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.
|
||||
|
||||
Capture
|
||||
-------
|
||||
|
||||
It is possible to query a capture of the `Viewport <class_Viewport>` contents. For the root
|
||||
`Viewport <class_Viewport>`, this is effectively a screen capture. This is done with the
|
||||
It is possible to query a capture of the `Viewport` contents. For the root
|
||||
`Viewport`, this is effectively a screen capture. This is done with the
|
||||
following code:
|
||||
|
||||
::
|
||||
@ -149,7 +149,7 @@ following code:
|
||||
# Set Sprite Texture.
|
||||
$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
|
||||
it using (for example):
|
||||
|
||||
@ -162,33 +162,33 @@ it using (for example):
|
||||
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
|
||||
|
||||
The `Viewport <class_Viewport>` will cover the area of its parent `ViewportContainer <class_viewportcontainer>` completely
|
||||
if `Stretch<class_viewportcontainer_property_stretch>` is set to ``true`` in `ViewportContainer <class_viewportcontainer>`.
|
||||
Note: The size of the `ViewportContainer <class_viewportcontainer>` cannot be smaller than the size of the `Viewport <class_Viewport>`.
|
||||
The `Viewport` completely
|
||||
if `Stretch<class_viewportcontainer_property_stretch>` is set to ``true`` in `ViewportContainer`.
|
||||
Note: The size of the `ViewportContainer`.
|
||||
|
||||
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
|
||||
choose to use a different level of MSAA for each `Viewport <class_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.
|
||||
choose to use a different level of MSAA for each `Viewport`; the default behavior is DISABLED.
|
||||
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
|
||||
restrict how the `Viewport <class_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.
|
||||
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` 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`'s Usage property to 2D if your viewport doesn't render anything in 3D.
|
||||
|
||||
.. 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.
|
||||
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”.
|
||||
Debug Draw allows you to specify one of four options for how the `Viewport <class_Viewport>` will display things drawn
|
||||
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` will display things drawn
|
||||
inside it. Debug Draw is disabled by default.
|
||||
|
||||
.. 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
|
||||
-------------
|
||||
|
||||
When rendering to a `Viewport <class_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.
|
||||
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` somewhere.
|
||||
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
|
||||
|
||||
and then selecting the `Viewport <class_Viewport>` you want to use.
|
||||
and then selecting the `Viewport` you want to use.
|
||||
|
||||
.. 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.
|
||||
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.
|
||||
|
||||
By default, re-rendering of the `Viewport <class_Viewport>` happens when the
|
||||
`Viewport <class_Viewport>`'s `ViewportTexture <class_ViewportTexture>` has been drawn in a frame. If visible, it will be
|
||||
By default, re-rendering of the `Viewport` happens when the
|
||||
`Viewport` has been drawn in a frame. If visible, it will be
|
||||
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
|
||||
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.
|
||||
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
|
||||
of the "current" scene. Autoloads fall into this category, but so do
|
||||
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,
|
||||
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
|
||||
access and integrity.
|
||||
|
||||
1. **We can delete the existing scene.**
|
||||
`SceneTree.change_scene() <class_SceneTree_method_change_scene>` and
|
||||
`SceneTree.change_scene_to() <class_SceneTree_method_change_scene_to>`
|
||||
`SceneTree.change_scene()` and
|
||||
`SceneTree.change_scene_to()`
|
||||
will delete the current scene immediately. Developers can also delete the
|
||||
main scene though. Assuming the root node's name is "Main", one could do
|
||||
``get_node("/root/Main").free()`` to delete the whole scene.
|
||||
@ -46,7 +46,7 @@ access and integrity.
|
||||
|
||||
- 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,
|
||||
or even directly to the `SceneTree <class_SceneTree>`.
|
||||
or even directly to the `SceneTree`.
|
||||
|
||||
- Processing stops.
|
||||
|
||||
@ -76,7 +76,7 @@ access and integrity.
|
||||
data.
|
||||
|
||||
- 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
|
||||
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
|
||||
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.
|
||||
|
||||
- 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
|
||||
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.
|
||||
|
||||
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
|
||||
`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
|
||||
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
|
||||
``res://script_templates/`` directory. The path can be changed by configuring
|
||||
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
|
||||
ignored.
|
||||
@ -107,7 +107,7 @@ Base placeholders
|
||||
| ``%TS%`` | Indentation placeholder. The exact type and number of |
|
||||
| | whitespace characters used for indentation is determined by |
|
||||
| | the ``text_editor/indent/type`` and ``text_editor/indent/size``|
|
||||
| | settings in the `EditorSettings <class_EditorSettings>` |
|
||||
| | settings in the `EditorSettings` |
|
||||
| | respectively. |
|
||||
+-------------+----------------------------------------------------------------+
|
||||
|
||||
@ -117,7 +117,7 @@ Type placeholders
|
||||
These are only relevant for GDScript with static typing. Whether these
|
||||
placeholders are actually replaced is determined by the
|
||||
``text_editor/completion/add_type_hints`` setting in the
|
||||
`EditorSettings <class_EditorSettings>`.
|
||||
`EditorSettings`.
|
||||
|
||||
+-------------------+--------------+
|
||||
| Placeholder | Value |
|
||||
|
@ -44,7 +44,7 @@ Instantiating C# nodes from GDScript
|
||||
|
||||
Using C# from GDScript doesn't need much work. Once loaded
|
||||
(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
|
||||
be instantiated with `GDScript.New() <class_GDScript_method_new>`.
|
||||
be instantiated with `GDScript.New()`.
|
||||
|
||||
.. 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
|
||||
convoluted, you will have to use `Object.Get() <class_Object_method_get>`
|
||||
and `Object.Set() <class_Object_method_set>`. The first argument is the name of the field you want to access.
|
||||
convoluted, you will have to use `Object.Get()`
|
||||
and `Object.Set()`. The first argument is the name of the field you want to access.
|
||||
|
||||
.. code-block:: csharp
|
||||
|
||||
@ -145,7 +145,7 @@ Calling GDScript methods from C#
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
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
|
||||
to said method.
|
||||
|
||||
|
@ -11,7 +11,7 @@ An expression can be:
|
||||
- A built-in method call like ``deg2rad(90)``.
|
||||
- A method call on an user-provided script like ``update_health()``,
|
||||
if ``base_instance`` is set to a value other than ``null`` when calling
|
||||
`Expression.execute() <class_Expression_method_execute>`.
|
||||
`Expression.execute()`.
|
||||
|
||||
.. 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
|
||||
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
|
||||
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
|
||||
be assigned any other value.
|
||||
|
||||
`bool <class_bool>`
|
||||
`bool`
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Short for "boolean", it can only contain ``true`` or ``false``.
|
||||
|
||||
`int <class_int>`
|
||||
`int`
|
||||
^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Short for "integer", it stores whole numbers (positive and negative).
|
||||
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.
|
||||
@ -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
|
||||
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>`_.
|
||||
@ -405,56 +405,56 @@ GDScript also supports `doc_gdscript_printf`.
|
||||
Vector built-in types
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
`Vector2 <class_Vector2>`
|
||||
`Vector2`
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
2D vector type containing ``x`` and ``y`` fields. Can also be
|
||||
accessed as an array.
|
||||
|
||||
`Rect2 <class_Rect2>`
|
||||
`Rect2`
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
2D Rectangle type containing two vectors fields: ``position`` and ``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
|
||||
be accessed as an array.
|
||||
|
||||
`Transform2D <class_Transform2D>`
|
||||
`Transform2D`
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
3×2 matrix used for 2D transforms.
|
||||
|
||||
`Plane <class_Plane>`
|
||||
`Plane`
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
3D Plane type in normalized form that contains a ``normal`` vector field
|
||||
and a ``d`` scalar distance.
|
||||
|
||||
`Quat <class_Quat>`
|
||||
`Quat`
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Quaternion is a datatype used for representing a 3D rotation. It's
|
||||
useful for interpolating rotations.
|
||||
|
||||
`AABB <class_AABB>`
|
||||
`AABB`
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Axis-aligned bounding box (or 3D box) contains 2 vectors fields: ``position``
|
||||
and ``size``. Also contains an ``end`` field which is
|
||||
``position + size``.
|
||||
|
||||
`Basis <class_Basis>`
|
||||
`Basis`
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
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
|
||||
vectors.
|
||||
|
||||
`Transform <class_Transform>`
|
||||
`Transform`
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
3D Transform contains a Basis field ``basis`` and a Vector3 field
|
||||
@ -463,24 +463,24 @@ vectors.
|
||||
Engine built-in types
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
`Color <class_Color>`
|
||||
`Color`
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Color data type contains ``r``, ``g``, ``b``, and ``a`` fields. It can
|
||||
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
|
||||
easily assigned to, and from, a String.
|
||||
|
||||
`RID <class_RID>`
|
||||
`RID`
|
||||
^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
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.
|
||||
@ -488,7 +488,7 @@ Base class for anything that is not a built-in type.
|
||||
Container built-in types
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
`Array <class_Array>`
|
||||
`Array`
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
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
|
||||
arrays. They are therefore only recommended to use for large data sets:
|
||||
|
||||
- `PoolByteArray <class_PoolByteArray>`: An array of bytes (integers from 0 to 255).
|
||||
- `PoolIntArray <class_PoolIntArray>`: An array of integers.
|
||||
- `PoolRealArray <class_PoolRealArray>`: An array of floats.
|
||||
- `PoolStringArray <class_PoolStringArray>`: An array of strings.
|
||||
- `PoolVector2Array <class_PoolVector2Array>`: An array of `Vector2 <class_Vector2>` objects.
|
||||
- `PoolVector3Array <class_PoolVector3Array>`: An array of `Vector3 <class_Vector3>` objects.
|
||||
- `PoolColorArray <class_PoolColorArray>`: An array of `Color <class_Color>` objects.
|
||||
- `PoolByteArray`: An array of bytes (integers from 0 to 255).
|
||||
- `PoolIntArray`: An array of integers.
|
||||
- `PoolRealArray`: An array of floats.
|
||||
- `PoolStringArray`: An array of strings.
|
||||
- `PoolVector2Array` objects.
|
||||
- `PoolVector3Array` objects.
|
||||
- `PoolColorArray` objects.
|
||||
|
||||
`Dictionary <class_Dictionary>`
|
||||
`Dictionary`
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
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
|
||||
`class_Object`, not just Dictionaries. Keep in mind it will cause a
|
||||
script error when attempting to index a non-existing property. To avoid
|
||||
this, use the `Object.get() <class_Object_method_get>` and
|
||||
`Object.set() <class_Object_method_set>` methods instead.
|
||||
this, use the `Object.get()` and
|
||||
`Object.set()` methods instead.
|
||||
|
||||
Data
|
||||
----
|
||||
@ -1270,7 +1270,7 @@ function.
|
||||
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
|
||||
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::
|
||||
@ -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.
|
||||
|
||||
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
|
||||
the `Object.connect() <class_Object_method_connect>` method::
|
||||
the `Object.connect()` method::
|
||||
|
||||
# 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