summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
Diffstat (limited to 'doc')
-rw-r--r--doc/classes/AStarGrid2D.xml14
-rw-r--r--doc/classes/DirAccess.xml95
-rw-r--r--doc/classes/DisplayServer.xml9
-rw-r--r--doc/classes/EditorInspector.xml8
-rw-r--r--doc/classes/EditorSettings.xml6
-rw-r--r--doc/classes/Engine.xml58
-rw-r--r--doc/classes/FileAccess.xml17
-rw-r--r--doc/classes/Font.xml10
-rw-r--r--doc/classes/ImageFormatLoader.xml19
-rw-r--r--doc/classes/ImageFormatLoaderExtension.xml42
-rw-r--r--doc/classes/JSON.xml5
-rw-r--r--doc/classes/Node.xml24
-rw-r--r--doc/classes/OS.xml10
-rw-r--r--doc/classes/PlaneMesh.xml4
-rw-r--r--doc/classes/ProjectSettings.xml78
-rw-r--r--doc/classes/QuadMesh.xml16
-rw-r--r--doc/classes/ScriptEditorBase.xml10
-rw-r--r--doc/classes/StreamPeerGZIP.xml42
-rw-r--r--doc/classes/Tween.xml187
19 files changed, 559 insertions, 95 deletions
diff --git a/doc/classes/AStarGrid2D.xml b/doc/classes/AStarGrid2D.xml
index 19cd9d21d7..331862ebfa 100644
--- a/doc/classes/AStarGrid2D.xml
+++ b/doc/classes/AStarGrid2D.xml
@@ -6,14 +6,24 @@
<description>
Compared to [AStar2D] you don't need to manually create points or connect them together. It also supports multiple type of heuristics and modes for diagonal movement. This class also provides a jumping mode which is faster to calculate than without it in the [AStar2D] class.
In contrast to [AStar2D], you only need set the [member size] of the grid, optionally set the [member cell_size] and then call the [method update] method:
- [codeblock]
+ [codeblocks]
+ [gdscript]
var astar_grid = AStarGrid2D.new()
astar_grid.size = Vector2i(32, 32)
astar_grid.cell_size = Vector2(16, 16)
astar_grid.update()
print(astar_grid.get_id_path(Vector2i(0, 0), Vector2i(3, 4))) # prints (0, 0), (1, 1), (2, 2), (3, 3), (3, 4)
print(astar_grid.get_point_path(Vector2i(0, 0), Vector2i(3, 4))) # prints (0, 0), (16, 16), (32, 32), (48, 48), (48, 64)
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ AStarGrid2D astarGrid = new AStarGrid2D();
+ astarGrid.Size = new Vector2i(32, 32);
+ astarGrid.CellSize = new Vector2i(16, 16);
+ astarGrid.Update();
+ GD.Print(astarGrid.GetIdPath(Vector2i.Zero, new Vector2i(3, 4))); // prints (0, 0), (1, 1), (2, 2), (3, 3), (3, 4)
+ GD.Print(astarGrid.GetPointPath(Vector2i.Zero, new Vector2i(3, 4))); // prints (0, 0), (16, 16), (32, 32), (48, 48), (48, 64)
+ [/csharp]
+ [/codeblocks]
</description>
<tutorials>
</tutorials>
diff --git a/doc/classes/DirAccess.xml b/doc/classes/DirAccess.xml
index ddb98030eb..cb7bf56f11 100644
--- a/doc/classes/DirAccess.xml
+++ b/doc/classes/DirAccess.xml
@@ -6,6 +6,15 @@
<description>
Directory type. It is used to manage directories and their content (not restricted to the project folder).
[DirAccess] can't be instantiated directly. Instead it is created with a static method that takes a path for which it will be opened.
+ Most of the methods have a static alternative that can be used without creating a [DirAccess]. Static methods only support absolute paths (including [code]res://[/code] and [code]user://[/code]).
+ [codeblock]
+ # Standard
+ var dir = Directory.new()
+ dir.open("user://levels")
+ dir.make_dir("world1")
+ # Static
+ Directory.make_dir_absolute("user://levels/world1")
+ [/codeblock]
[b]Note:[/b] Many resources types are imported (e.g. textures or sound files), and their source asset will not be included in the exported game, as only the imported version is used. Use [ResourceLoader] to access imported resources.
Here is an example on how to iterate through the files of a directory:
[codeblocks]
@@ -27,7 +36,7 @@
[csharp]
public void DirContents(string path)
{
- var dir = DirAccess.Open(path);
+ using var dir = DirAccess.Open(path);
if (dir != null)
{
dir.ListDirBegin();
@@ -59,7 +68,7 @@
<methods>
<method name="change_dir">
<return type="int" enum="Error" />
- <param index="0" name="todir" type="String" />
+ <param index="0" name="to_dir" type="String" />
<description>
Changes the currently opened directory to the one passed as an argument. The argument can be relative to the current directory (e.g. [code]newdir[/code] or [code]../newdir[/code]), or an absolute path (e.g. [code]/tmp/newdir[/code] or [code]res://somedir/newdir[/code]).
Returns one of the [enum Error] code constants ([code]OK[/code] on success).
@@ -76,6 +85,15 @@
Returns one of the [enum Error] code constants ([code]OK[/code] on success).
</description>
</method>
+ <method name="copy_absolute" qualifiers="static">
+ <return type="int" enum="Error" />
+ <param index="0" name="from" type="String" />
+ <param index="1" name="to" type="String" />
+ <param index="2" name="chmod_flags" type="int" default="-1" />
+ <description>
+ Static version of [method copy]. Supports only absolute paths.
+ </description>
+ </method>
<method name="current_is_dir" qualifiers="const">
<return type="bool" />
<description>
@@ -87,7 +105,13 @@
<param index="0" name="path" type="String" />
<description>
Returns whether the target directory exists. The argument can be relative to the current directory, or an absolute path.
- If the [DirAccess] is not open, the path is relative to [code]res://[/code].
+ </description>
+ </method>
+ <method name="dir_exists_absolute" qualifiers="static">
+ <return type="bool" />
+ <param index="0" name="path" type="String" />
+ <description>
+ Static version of [method dir_exists]. Supports only absolute paths.
</description>
</method>
<method name="file_exists">
@@ -95,7 +119,7 @@
<param index="0" name="path" type="String" />
<description>
Returns whether the target file exists. The argument can be relative to the current directory, or an absolute path.
- If the [DirAccess] is not open, the path is relative to [code]res://[/code].
+ For a static equivalent, use [method FileAccess.file_exists].
</description>
</method>
<method name="get_current_dir" qualifiers="const">
@@ -108,7 +132,7 @@
<method name="get_current_drive">
<return type="int" />
<description>
- Returns the currently opened directory's drive index. See [method get_drive] to convert returned index to the name of the drive.
+ Returns the currently opened directory's drive index. See [method get_drive_name] to convert returned index to the name of the drive.
</description>
</method>
<method name="get_directories">
@@ -118,17 +142,15 @@
Affected by [member include_hidden] and [member include_navigational].
</description>
</method>
- <method name="get_drive">
- <return type="String" />
- <param index="0" name="idx" type="int" />
+ <method name="get_directories_at" qualifiers="static">
+ <return type="PackedStringArray" />
+ <param index="0" name="path" type="String" />
<description>
- On Windows, returns the name of the drive (partition) passed as an argument (e.g. [code]C:[/code]).
- On macOS, returns the path to the mounted volume passed as an argument.
- On Linux, returns the path to the mounted volume or GTK 3 bookmark passed as an argument.
- On other platforms, or if the requested drive does not exist, the method returns an empty String.
+ Returns a [PackedStringArray] containing filenames of the directory contents, excluding files, at the given [param path]. The array is sorted alphabetically.
+ Use [method get_directories] if you want more control of what gets included.
</description>
</method>
- <method name="get_drive_count">
+ <method name="get_drive_count" qualifiers="static">
<return type="int" />
<description>
On Windows, returns the number of drives (partitions) mounted on the current filesystem.
@@ -137,6 +159,16 @@
On other platforms, the method returns 0.
</description>
</method>
+ <method name="get_drive_name" qualifiers="static">
+ <return type="String" />
+ <param index="0" name="idx" type="int" />
+ <description>
+ On Windows, returns the name of the drive (partition) passed as an argument (e.g. [code]C:[/code]).
+ On macOS, returns the path to the mounted volume passed as an argument.
+ On Linux, returns the path to the mounted volume or GTK 3 bookmark passed as an argument.
+ On other platforms, or if the requested drive does not exist, the method returns an empty String.
+ </description>
+ </method>
<method name="get_files">
<return type="PackedStringArray" />
<description>
@@ -144,6 +176,14 @@
Affected by [member include_hidden].
</description>
</method>
+ <method name="get_files_at" qualifiers="static">
+ <return type="PackedStringArray" />
+ <param index="0" name="path" type="String" />
+ <description>
+ Returns a [PackedStringArray] containing filenames of the directory contents, excluding directories, at the given [param path]. The array is sorted alphabetically.
+ Use [method get_files] if you want more control of what gets included.
+ </description>
+ </method>
<method name="get_next">
<return type="String" />
<description>
@@ -185,6 +225,13 @@
Returns one of the [enum Error] code constants ([code]OK[/code] on success).
</description>
</method>
+ <method name="make_dir_absolute" qualifiers="static">
+ <return type="int" enum="Error" />
+ <param index="0" name="path" type="String" />
+ <description>
+ Static version of [method make_dir]. Supports only absolute paths.
+ </description>
+ </method>
<method name="make_dir_recursive">
<return type="int" enum="Error" />
<param index="0" name="path" type="String" />
@@ -193,6 +240,13 @@
Returns one of the [enum Error] code constants ([code]OK[/code] on success).
</description>
</method>
+ <method name="make_dir_recursive_absolute" qualifiers="static">
+ <return type="int" enum="Error" />
+ <param index="0" name="path" type="String" />
+ <description>
+ Static version of [method make_dir_recursive]. Supports only absolute paths.
+ </description>
+ </method>
<method name="open" qualifiers="static">
<return type="DirAccess" />
<param index="0" name="path" type="String" />
@@ -210,6 +264,13 @@
Returns one of the [enum Error] code constants ([code]OK[/code] on success).
</description>
</method>
+ <method name="remove_absolute" qualifiers="static">
+ <return type="int" enum="Error" />
+ <param index="0" name="path" type="String" />
+ <description>
+ Static version of [method remove]. Supports only absolute paths.
+ </description>
+ </method>
<method name="rename">
<return type="int" enum="Error" />
<param index="0" name="from" type="String" />
@@ -219,6 +280,14 @@
Returns one of the [enum Error] code constants ([code]OK[/code] on success).
</description>
</method>
+ <method name="rename_absolute" qualifiers="static">
+ <return type="int" enum="Error" />
+ <param index="0" name="from" type="String" />
+ <param index="1" name="to" type="String" />
+ <description>
+ Static version of [method rename]. Supports only absolute paths.
+ </description>
+ </method>
</methods>
<members>
<member name="include_hidden" type="bool" setter="set_include_hidden" getter="get_include_hidden">
diff --git a/doc/classes/DisplayServer.xml b/doc/classes/DisplayServer.xml
index d22d64c276..a1dee7ecc7 100644
--- a/doc/classes/DisplayServer.xml
+++ b/doc/classes/DisplayServer.xml
@@ -1336,6 +1336,15 @@
Depending on the platform and used renderer, the engine will fall back to [constant VSYNC_ENABLED], if the desired mode is not supported.
</description>
</method>
+ <method name="window_set_window_buttons_offset">
+ <return type="void" />
+ <param index="0" name="offset" type="Vector2i" />
+ <param index="1" name="window_id" type="int" default="0" />
+ <description>
+ When [constant WINDOW_FLAG_EXTEND_TO_TITLE] flag is set, set offset to the center of the first titlebar button.
+ [b]Note:[/b] This flag is implemented on macOS.
+ </description>
+ </method>
<method name="window_set_window_event_callback">
<return type="void" />
<param index="0" name="callback" type="Callable" />
diff --git a/doc/classes/EditorInspector.xml b/doc/classes/EditorInspector.xml
index 280a7bf34a..a1a43dd5bf 100644
--- a/doc/classes/EditorInspector.xml
+++ b/doc/classes/EditorInspector.xml
@@ -13,6 +13,14 @@
</description>
<tutorials>
</tutorials>
+ <methods>
+ <method name="get_selected_path" qualifiers="const">
+ <return type="String" />
+ <description>
+ Gets the path of the currently selected property.
+ </description>
+ </method>
+ </methods>
<members>
<member name="horizontal_scroll_mode" type="int" setter="set_horizontal_scroll_mode" getter="get_horizontal_scroll_mode" overrides="ScrollContainer" enum="ScrollContainer.ScrollMode" default="0" />
</members>
diff --git a/doc/classes/EditorSettings.xml b/doc/classes/EditorSettings.xml
index 329cd3fe63..6007128965 100644
--- a/doc/classes/EditorSettings.xml
+++ b/doc/classes/EditorSettings.xml
@@ -405,7 +405,7 @@
If [code]true[/code], allows panning by holding down [kbd]Space[/kbd] in the 2D editor viewport (in addition to panning with the middle or right mouse buttons). If [code]false[/code], the left mouse button must be held down while holding down [kbd]Space[/kbd] to pan in the 2D editor viewport.
</member>
<member name="editors/panning/sub_editors_panning_scheme" type="int" setter="" getter="">
- Controls whether the mouse wheel scroll zooms or pans in subeditors. The list of affected subeditors is: animation blend tree editor, [Polygon2D] editor, tileset editor, texture region editor, visual shader editor and visual script editor. See also [member editors/panning/2d_editor_panning_scheme] and [member editors/panning/animation_editors_panning_scheme].
+ Controls whether the mouse wheel scroll zooms or pans in subeditors. The list of affected subeditors is: animation blend tree editor, [Polygon2D] editor, tileset editor, texture region editor and visual shader editor. See also [member editors/panning/2d_editor_panning_scheme] and [member editors/panning/animation_editors_panning_scheme].
</member>
<member name="editors/panning/warped_mouse_panning" type="bool" setter="" getter="">
If [code]true[/code], warps the mouse around the 2D viewport while panning in the 2D editor. This makes it possible to pan over a large area without having to exit panning then mouse the mouse back constantly.
@@ -424,10 +424,10 @@
[b]Note:[/b] Only effective if [member editors/tiles_editor/display_grid] is [code]true[/code].
</member>
<member name="editors/visual_editors/lines_curvature" type="float" setter="" getter="">
- The curvature to use for connection lines in the visual script and visual shader editors. Higher values will make connection lines appear more curved, with values above [code]0.5[/code] resulting in more "angular" turns in the middle of connection lines.
+ The curvature to use for connection lines in the visual shader editor. Higher values will make connection lines appear more curved, with values above [code]0.5[/code] resulting in more "angular" turns in the middle of connection lines.
</member>
<member name="editors/visual_editors/minimap_opacity" type="float" setter="" getter="">
- The opacity of the minimap displayed in the bottom-right corner of the visual script and visual shader editors.
+ The opacity of the minimap displayed in the bottom-right corner of the visual shader editor.
</member>
<member name="editors/visual_editors/visual_shader/port_preview_size" type="int" setter="" getter="">
The size to use for port previews in the visual shader uniforms (toggled by clicking the "eye" icon next to an output). The value is defined in pixels at 100% zoom, and will scale with zoom automatically.
diff --git a/doc/classes/Engine.xml b/doc/classes/Engine.xml
index 301a3e55fb..ecf3d87a70 100644
--- a/doc/classes/Engine.xml
+++ b/doc/classes/Engine.xml
@@ -14,12 +14,20 @@
<description>
Returns the name of the CPU architecture the Godot binary was built for. Possible return values are [code]x86_64[/code], [code]x86_32[/code], [code]arm64[/code], [code]armv7[/code], [code]rv64[/code], [code]riscv[/code], [code]ppc64[/code], [code]ppc[/code], [code]wasm64[/code] and [code]wasm32[/code].
To detect whether the current CPU architecture is 64-bit, you can use the fact that all 64-bit architecture names have [code]64[/code] in their name:
- [codeblock]
+ [codeblocks]
+ [gdscript]
if "64" in Engine.get_architecture_name():
print("Running on 64-bit CPU.")
else:
print("Running on 32-bit CPU.")
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ if (Engine.GetArchitectureName().Contains("64"))
+ GD.Print("Running on 64-bit CPU.");
+ else
+ GD.Print("Running on 32-bit CPU.");
+ [/csharp]
+ [/codeblocks]
[b]Note:[/b] [method get_architecture_name] does [i]not[/i] return the name of the host CPU architecture. For example, if running an x86_32 Godot binary on a x86_64 system, the returned value will be [code]x86_32[/code].
</description>
</method>
@@ -83,11 +91,24 @@
<description>
Returns the total number of frames passed since engine initialization which is advanced on each [b]physics frame[/b]. See also [method get_process_frames].
[method get_physics_frames] can be used to run expensive logic less often without relying on a [Timer]:
- [codeblock]
+ [codeblocks]
+ [gdscript]
func _physics_process(_delta):
if Engine.get_physics_frames() % 2 == 0:
pass # Run expensive logic only once every 2 physics frames here.
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ public override void _PhysicsProcess(double delta)
+ {
+ base._PhysicsProcess(delta);
+
+ if (Engine.GetPhysicsFrames() % 2 == 0)
+ {
+ // Run expensive logic only once every 2 physics frames here.
+ }
+ }
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="get_physics_interpolation_fraction" qualifiers="const">
@@ -101,11 +122,24 @@
<description>
Returns the total number of frames passed since engine initialization which is advanced on each [b]process frame[/b], regardless of whether the render loop is enabled. See also [method get_frames_drawn] and [method get_physics_frames].
[method get_process_frames] can be used to run expensive logic less often without relying on a [Timer]:
- [codeblock]
+ [codeblocks]
+ [gdscript]
func _process(_delta):
if Engine.get_process_frames() % 2 == 0:
pass # Run expensive logic only once every 2 process (render) frames here.
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ public override void _Process(double delta)
+ {
+ base._Process(delta);
+
+ if (Engine.GetProcessFrames() % 2 == 0)
+ {
+ // Run expensive logic only once every 2 physics frames here.
+ }
+ }
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="get_script_language" qualifiers="const">
@@ -182,12 +216,20 @@
<return type="bool" />
<description>
Returns [code]true[/code] if the script is currently running inside the editor, [code]false[/code] otherwise. This is useful for [code]@tool[/code] scripts to conditionally draw editor helpers, or prevent accidentally running "game" code that would affect the scene state while in the editor:
- [codeblock]
+ [codeblocks]
+ [gdscript]
if Engine.is_editor_hint():
draw_gizmos()
else:
simulate_physics()
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ if (Engine.IsEditorHint())
+ DrawGizmos();
+ else
+ SimulatePhysics();
+ [/csharp]
+ [/codeblocks]
See [url=$DOCS_URL/tutorials/plugins/running_code_in_the_editor.html]Running code in the editor[/url] in the documentation for more information.
[b]Note:[/b] To detect whether the script is run from an editor [i]build[/i] (e.g. when pressing [kbd]F5[/kbd]), use [method OS.has_feature] with the [code]"editor"[/code] argument instead. [code]OS.has_feature("editor")[/code] will evaluate to [code]true[/code] both when the code is running in the editor and when running the project from the editor, but it will evaluate to [code]false[/code] when the code is run from an exported project.
</description>
diff --git a/doc/classes/FileAccess.xml b/doc/classes/FileAccess.xml
index 61377fb13a..adc0f4c3dd 100644
--- a/doc/classes/FileAccess.xml
+++ b/doc/classes/FileAccess.xml
@@ -20,24 +20,30 @@
[csharp]
public void Save(string content)
{
- var file = FileAccess.Open("user://save_game.dat", File.ModeFlags.Write);
+ using var file = FileAccess.Open("user://save_game.dat", File.ModeFlags.Write);
file.StoreString(content);
}
public string Load()
{
- var file = FileAccess.Open("user://save_game.dat", File.ModeFlags.Read);
+ using var file = FileAccess.Open("user://save_game.dat", File.ModeFlags.Read);
string content = file.GetAsText();
return content;
}
[/csharp]
[/codeblocks]
In the example above, the file will be saved in the user data folder as specified in the [url=$DOCS_URL/tutorials/io/data_paths.html]Data paths[/url] documentation.
- There is no method to close a file in order to free it from use. Instead, [FileAccess] will close when it's freed, which happens when it goes out of scope or when it gets assigned with [code]null[/code].
- [codeblock]
+ There is no method to close a file in order to free it from use. Instead, [FileAccess] will close when it's freed, which happens when it goes out of scope or when it gets assigned with [code]null[/code]. In C# the reference must be disposed after we are done using it, this can be done with the [code]using[/code] statement or calling the [code]Dispose[/code] method directly.
+ [codeblocks]
+ [gdscript]
var file = FileAccess.open("res://something") # File is opened and locked for use.
file = null # File is closed.
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ using var file = FileAccess.Open("res://something"); // File is opened and locked for use.
+ // The using statement calls Dispose when going out of scope.
+ [/csharp]
+ [/codeblocks]
[b]Note:[/b] To access project resources once exported, it is recommended to use [ResourceLoader] instead of the [FileAccess] API, as some files are converted to engine-specific formats and their original source files might not be present in the exported PCK package.
[b]Note:[/b] Files are automatically closed only if the process exits "normally" (such as by clicking the window manager's close button or pressing [b]Alt + F4[/b]). If you stop the project execution by pressing [b]F8[/b] while the project is running, the file won't be closed as the game process will be killed. You can work around this by calling [method flush] at regular intervals.
</description>
@@ -71,6 +77,7 @@
<description>
Returns [code]true[/code] if the file exists in the given path.
[b]Note:[/b] Many resources types are imported (e.g. textures or sound files), and their source asset will not be included in the exported game, as only the imported version is used. See [method ResourceLoader.exists] for an alternative approach that takes resource remapping into account.
+ For a non-static, relative equivalent, use [method DirAccess.file_exists].
</description>
</method>
<method name="flush">
diff --git a/doc/classes/Font.xml b/doc/classes/Font.xml
index ad3a16afbb..6a42b62bcf 100644
--- a/doc/classes/Font.xml
+++ b/doc/classes/Font.xml
@@ -228,9 +228,15 @@
<description>
Returns the size of a bounding box of a single-line string, taking kerning and advance into account. See also [method get_multiline_string_size] and [method draw_string].
For example, to get the string size as displayed by a single-line Label, use:
- [codeblock]
+ [codeblocks]
+ [gdscript]
var string_size = $Label.get_theme_font("font").get_string_size($Label.text, HORIZONTAL_ALIGNMENT_LEFT, -1, $Label.get_theme_font_size("font_size"))
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ Label label = GetNode&lt;Label&gt;("Label");
+ Vector2 stringSize = label.GetThemeFont("font").GetStringSize(label.Text, HorizontalAlignment.Left, -1, label.GetThemeFontSize("font_size"));
+ [/csharp]
+ [/codeblocks]
[b]Note:[/b] Real height of the string is context-dependent and can be significantly different from the value returned by [method get_height].
</description>
</method>
diff --git a/doc/classes/ImageFormatLoader.xml b/doc/classes/ImageFormatLoader.xml
new file mode 100644
index 0000000000..c6b1ec922a
--- /dev/null
+++ b/doc/classes/ImageFormatLoader.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="ImageFormatLoader" inherits="RefCounted" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
+ <brief_description>
+ Base class to add support for specific image formats.
+ </brief_description>
+ <description>
+ The engine supports multiple image formats out of the box (PNG, SVG, JPEG, WebP to name a few), but you can choose to implement support for additional image formats by extending [ImageFormatLoaderExtension].
+ </description>
+ <tutorials>
+ </tutorials>
+ <constants>
+ <constant name="FLAG_NONE" value="0" enum="LoaderFlags" is_bitfield="true">
+ </constant>
+ <constant name="FLAG_FORCE_LINEAR" value="1" enum="LoaderFlags" is_bitfield="true">
+ </constant>
+ <constant name="FLAG_CONVERT_COLORS" value="2" enum="LoaderFlags" is_bitfield="true">
+ </constant>
+ </constants>
+</class>
diff --git a/doc/classes/ImageFormatLoaderExtension.xml b/doc/classes/ImageFormatLoaderExtension.xml
new file mode 100644
index 0000000000..b2a7ebc60f
--- /dev/null
+++ b/doc/classes/ImageFormatLoaderExtension.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="ImageFormatLoaderExtension" inherits="ImageFormatLoader" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
+ <brief_description>
+ Base class for creating [ImageFormatLoader] extensions (adding support for extra image formats).
+ </brief_description>
+ <description>
+ The engine supports multiple image formats out of the box (PNG, SVG, JPEG, WebP to name a few), but you can choose to implement support for additional image formats by extending this class.
+ Be sure to respect the documented return types and values. You should create an instance of it, and call [method add_format_loader] to register that loader during the initializaiton phase.
+ </description>
+ <tutorials>
+ </tutorials>
+ <methods>
+ <method name="_get_recognized_extensions" qualifiers="virtual const">
+ <return type="PackedStringArray" />
+ <description>
+ Returns the list of file extensions for this image format. Files with the given extentions will be treated as image file and loaded using this class.
+ </description>
+ </method>
+ <method name="_load_image" qualifiers="virtual">
+ <return type="int" enum="Error" />
+ <param index="0" name="image" type="Image" />
+ <param index="1" name="fileaccess" type="FileAccess" />
+ <param index="2" name="flags" type="int" enum="ImageFormatLoader.LoaderFlags" />
+ <param index="3" name="scale" type="float" />
+ <description>
+ Loads the content of [param fileaccess] into the provided [param image].
+ </description>
+ </method>
+ <method name="add_format_loader">
+ <return type="void" />
+ <description>
+ Add this format loader to the engine, allowing it to recognize the file extensions returned by [method _get_recognized_extensions].
+ </description>
+ </method>
+ <method name="remove_format_loader">
+ <return type="void" />
+ <description>
+ Remove this format loader from the engine.
+ </description>
+ </method>
+ </methods>
+</class>
diff --git a/doc/classes/JSON.xml b/doc/classes/JSON.xml
index 38ddca2727..125d016632 100644
--- a/doc/classes/JSON.xml
+++ b/doc/classes/JSON.xml
@@ -28,6 +28,11 @@
[codeblock]
var data = JSON.parse_string(json_string) # Returns null if parsing failed.
[/codeblock]
+ [b]Note:[/b] Both parse methods do not fully comply with the JSON specification:
+ - Trailing commas in arrays or objects are ignored, instead of causing a parser error.
+ - New line and tab characters are accepted in string literals, and are treated like their corresponding escape sequences [code]\n[/code] and [code]\t[/code].
+ - Numbers are parsed using [method String.to_float] which is generally more lax than the JSON specification.
+ - Certain errors, such as invalid Unicode sequences, do not cause a parser error. Instead, the string is cleansed and an error is logged to the console.
</description>
<tutorials>
</tutorials>
diff --git a/doc/classes/Node.xml b/doc/classes/Node.xml
index d8ad65082f..d9732da3a3 100644
--- a/doc/classes/Node.xml
+++ b/doc/classes/Node.xml
@@ -179,9 +179,14 @@
<return type="Tween" />
<description>
Creates a new [Tween] and binds it to this node. This is equivalent of doing:
- [codeblock]
+ [codeblocks]
+ [gdscript]
get_tree().create_tween().bind_node(self)
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ GetTree().CreateTween().BindNode(this);
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="duplicate" qualifiers="const">
@@ -267,13 +272,24 @@
Returns an array listing the groups that the node is a member of.
[b]Note:[/b] For performance reasons, the order of node groups is [i]not[/i] guaranteed. The order of node groups should not be relied upon as it can vary across project runs.
[b]Note:[/b] The engine uses some group names internally (all starting with an underscore). To avoid conflicts with internal groups, do not add custom groups whose name starts with an underscore. To exclude internal groups while looping over [method get_groups], use the following snippet:
- [codeblock]
+ [codeblocks]
+ [gdscript]
# Stores the node's non-internal groups only (as an array of Strings).
var non_internal_groups = []
for group in get_groups():
if not group.begins_with("_"):
non_internal_groups.push_back(group)
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ // Stores the node's non-internal groups only (as a List of strings).
+ List&lt;string&gt; nonInternalGroups = new List&lt;string&gt;();
+ foreach (string group in GetGroups())
+ {
+ if (!group.BeginsWith("_"))
+ nonInternalGroups.Add(group);
+ }
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="get_index" qualifiers="const">
diff --git a/doc/classes/OS.xml b/doc/classes/OS.xml
index d920c45de4..be7bacd994 100644
--- a/doc/classes/OS.xml
+++ b/doc/classes/OS.xml
@@ -525,10 +525,16 @@
Moves the file or directory to the system's recycle bin. See also [method DirAccess.remove].
The method takes only global paths, so you may need to use [method ProjectSettings.globalize_path]. Do not use it for files in [code]res://[/code] as it will not work in exported project.
[b]Note:[/b] If the user has disabled the recycle bin on their system, the file will be permanently deleted instead.
- [codeblock]
+ [codeblocks]
+ [gdscript]
var file_to_remove = "user://slot1.sav"
OS.move_to_trash(ProjectSettings.globalize_path(file_to_remove))
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ var fileToRemove = "user://slot1.sav";
+ OS.MoveToTrash(ProjectSettings.GlobalizePath(fileToRemove));
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="open_midi_inputs">
diff --git a/doc/classes/PlaneMesh.xml b/doc/classes/PlaneMesh.xml
index 564b6fe743..1dceac70b0 100644
--- a/doc/classes/PlaneMesh.xml
+++ b/doc/classes/PlaneMesh.xml
@@ -31,10 +31,10 @@
[PlaneMesh] will face the positive X-axis.
</constant>
<constant name="FACE_Y" value="1" enum="Orientation">
- [PlaneMesh] will face the positive Y-axis. This matches the behaviour of the [PlaneMesh] in Godot 3.x.
+ [PlaneMesh] will face the positive Y-axis. This matches the behavior of the [PlaneMesh] in Godot 3.x.
</constant>
<constant name="FACE_Z" value="2" enum="Orientation">
- [PlaneMesh] will face the positive Z-axis. This matches the behvaiour of the QuadMesh in Godot 3.x.
+ [PlaneMesh] will face the positive Z-axis. This matches the behavior of the QuadMesh in Godot 3.x.
</constant>
</constants>
</class>
diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml
index 7c0ce656ab..4c2cf330af 100644
--- a/doc/classes/ProjectSettings.xml
+++ b/doc/classes/ProjectSettings.xml
@@ -1714,13 +1714,6 @@
If [code]true[/code], performs a previous depth pass before rendering 3D materials. This increases performance significantly in scenes with high overdraw, when complex materials and lighting are used. However, in scenes with few occluded surfaces, the depth prepass may reduce performance. If your game is viewed from a fixed angle that makes it easy to avoid overdraw (such as top-down or side-scrolling perspective), consider disabling the depth prepass to improve performance. This setting can be changed at run-time to optimize performance depending on the scene currently being viewed.
[b]Note:[/b] Only supported when using the Vulkan Clustered backend or the OpenGL backend. When using Vulkan Mobile there is no depth prepass performed.
</member>
- <member name="rendering/driver/driver_name" type="String" setter="" getter="" default="&quot;vulkan&quot;">
- The video driver to use.
- [b]Note:[/b] OpenGL support is currently incomplete. Only basic rendering is supported.
- [b]Note:[/b] The backend in use can be overridden at runtime via the [code]--rendering-driver[/code] command line argument.
- [b]FIXME:[/b] No longer valid after DisplayServer split:
- In such cases, this property is not updated, so use [code]OS.get_current_video_driver[/code] to query it at run-time.
- </member>
<member name="rendering/driver/threads/thread_model" type="int" setter="" getter="" default="1">
Thread model for rendering. Rendering on a thread can vastly improve performance, but synchronizing to the main thread can cause a bit more jitter.
</member>
@@ -1796,6 +1789,27 @@
<member name="rendering/environment/volumetric_fog/volume_size" type="int" setter="" getter="" default="64">
Base size used to determine size of froxel buffer in the camera X-axis and Y-axis. The final size is scaled by the aspect ratio of the screen, so actual values may differ from what is set. Set a larger size for more detailed fog, set a smaller size for better performance.
</member>
+ <member name="rendering/gl_compatibility/driver" type="String" setter="" getter="" default="&quot;opengl3&quot;">
+ Sets the driver to be used by the renderer when using the Compatibility renderer. This property can not be edited directly, instead, set the driver using the platform-specific overrides.
+ </member>
+ <member name="rendering/gl_compatibility/driver.android" type="String" setter="" getter="" default="&quot;opengl3&quot;">
+ Android override for [member rendering/gl_compatibility/driver].
+ </member>
+ <member name="rendering/gl_compatibility/driver.ios" type="String" setter="" getter="" default="&quot;opengl3&quot;">
+ iOS override for [member rendering/gl_compatibility/driver].
+ </member>
+ <member name="rendering/gl_compatibility/driver.linuxbsd" type="String" setter="" getter="" default="&quot;opengl3&quot;">
+ LinuxBSD override for [member rendering/gl_compatibility/driver].
+ </member>
+ <member name="rendering/gl_compatibility/driver.macos" type="String" setter="" getter="" default="&quot;opengl3&quot;">
+ macOS override for [member rendering/gl_compatibility/driver].
+ </member>
+ <member name="rendering/gl_compatibility/driver.web" type="String" setter="" getter="" default="&quot;opengl3&quot;">
+ Web override for [member rendering/gl_compatibility/driver].
+ </member>
+ <member name="rendering/gl_compatibility/driver.windows" type="String" setter="" getter="" default="&quot;opengl3&quot;">
+ Windows override for [member rendering/gl_compatibility/driver].
+ </member>
<member name="rendering/global_illumination/gi/use_half_resolution" type="bool" setter="" getter="" default="false">
If [code]true[/code], renders [VoxelGI] and SDFGI ([member Environment.sdfgi_enabled]) buffers at halved resolution (e.g. 960×540 when the viewport size is 1920×1080). This improves performance significantly when VoxelGI or SDFGI is enabled, at the cost of artifacts that may be visible on polygon edges. The loss in quality becomes less noticeable as the viewport resolution increases. [LightmapGI] rendering is not affected by this setting.
[b]Note:[/b] This property is only read when the project starts. To set half-resolution GI at run-time, call [method RenderingServer.gi_set_use_half_resolution] instead.
@@ -1956,6 +1970,44 @@
<member name="rendering/reflections/sky_reflections/texture_array_reflections.mobile" type="bool" setter="" getter="" default="false">
Lower-end override for [member rendering/reflections/sky_reflections/texture_array_reflections] on mobile devices, due to performance concerns or driver support.
</member>
+ <member name="rendering/renderer/rendering_method" type="String" setter="" getter="" default="&quot;forward_plus&quot;">
+ Sets the renderer that will be used by the project. Options are:
+ [b]Clustered[/b]: High-end renderer designed for Desktop devices. Has a higher base overhead, but scales well with complex scenes. Not suitable for older devices or mobile.
+ [b]Mobile[/b]: Modern renderer designed for mobile devices. Has a lower base overhead than Clustered, but does not scale as well to large scenes with many elements.
+ [b]Compatibility[/b]: Low-end renderer designed for older devices. Based on the limitations of the OpenGL 3.3/ OpenGL ES 3.0 / WebGL 2 APIs.
+ </member>
+ <member name="rendering/renderer/rendering_method.mobile" type="String" setter="" getter="" default="&quot;forward_plus&quot;">
+ Override for [member rendering/renderer/rendering_method] on mobile devices.
+ </member>
+ <member name="rendering/renderer/rendering_method.web" type="String" setter="" getter="" default="&quot;gl_compatibility&quot;">
+ Override for [member rendering/renderer/rendering_method] on web.
+ </member>
+ <member name="rendering/rendering_device/descriptor_pools/max_descriptors_per_pool" type="int" setter="" getter="" default="64">
+ </member>
+ <member name="rendering/rendering_device/driver" type="String" setter="" getter="" default="&quot;vulkan&quot;">
+ Sets the driver to be used by the renderer when using a RenderingDevice-based renderer like the clustered renderer or the mobile renderer. This property can not be edited directly, instead, set the driver using the platform-specific overrides.
+ </member>
+ <member name="rendering/rendering_device/driver.android" type="String" setter="" getter="" default="&quot;vulkan&quot;">
+ Android override for [member rendering/rendering_device/driver].
+ </member>
+ <member name="rendering/rendering_device/driver.ios" type="String" setter="" getter="" default="&quot;vulkan&quot;">
+ iOS override for [member rendering/rendering_device/driver].
+ </member>
+ <member name="rendering/rendering_device/driver.linuxbsd" type="String" setter="" getter="" default="&quot;vulkan&quot;">
+ LinuxBSD override for [member rendering/rendering_device/driver].
+ </member>
+ <member name="rendering/rendering_device/driver.macos" type="String" setter="" getter="" default="&quot;vulkan&quot;">
+ macOS override for [member rendering/rendering_device/driver].
+ </member>
+ <member name="rendering/rendering_device/driver.windows" type="String" setter="" getter="" default="&quot;vulkan&quot;">
+ Windows override for [member rendering/rendering_device/driver].
+ </member>
+ <member name="rendering/rendering_device/staging_buffer/block_size_kb" type="int" setter="" getter="" default="256">
+ </member>
+ <member name="rendering/rendering_device/staging_buffer/max_size_mb" type="int" setter="" getter="" default="128">
+ </member>
+ <member name="rendering/rendering_device/staging_buffer/texture_upload_region_size_px" type="int" setter="" getter="" default="64">
+ </member>
<member name="rendering/scaling_3d/fsr_sharpness" type="float" setter="" getter="" default="0.2">
Determines how sharp the upscaled image will be when using the FSR upscaling mode. Sharpness halves with every whole number. Values go from 0.0 (sharpest) to 2.0. Values above 2.0 won't make a visible difference.
</member>
@@ -2037,18 +2089,6 @@
<member name="rendering/vrs/texture" type="String" setter="" getter="" default="&quot;&quot;">
If [member rendering/vrs/mode] is set to texture, this is the path to default texture loaded as the VRS image.
</member>
- <member name="rendering/vulkan/descriptor_pools/max_descriptors_per_pool" type="int" setter="" getter="" default="64">
- </member>
- <member name="rendering/vulkan/rendering/back_end" type="int" setter="" getter="" default="0">
- </member>
- <member name="rendering/vulkan/rendering/back_end.mobile" type="int" setter="" getter="" default="1">
- </member>
- <member name="rendering/vulkan/staging_buffer/block_size_kb" type="int" setter="" getter="" default="256">
- </member>
- <member name="rendering/vulkan/staging_buffer/max_size_mb" type="int" setter="" getter="" default="128">
- </member>
- <member name="rendering/vulkan/staging_buffer/texture_upload_region_size_px" type="int" setter="" getter="" default="64">
- </member>
<member name="threading/worker_pool/low_priority_thread_ratio" type="float" setter="" getter="" default="0.3">
</member>
<member name="threading/worker_pool/max_threads" type="int" setter="" getter="" default="-1">
diff --git a/doc/classes/QuadMesh.xml b/doc/classes/QuadMesh.xml
new file mode 100644
index 0000000000..7469338ef9
--- /dev/null
+++ b/doc/classes/QuadMesh.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="QuadMesh" inherits="PlaneMesh" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
+ <brief_description>
+ Class representing a square mesh facing the camera.
+ </brief_description>
+ <description>
+ Class representing a square [PrimitiveMesh]. This flat mesh does not have a thickness. By default, this mesh is aligned on the X and Y axes; this rotation is more suited for use with billboarded materials. A [QuadMesh] is equivalent to a [PlaneMesh] except its default [member PlaneMesh.orientation] is [constant PlaneMesh.FACE_Z].
+ </description>
+ <tutorials>
+ <link title="GUI in 3D Demo">https://godotengine.org/asset-library/asset/127</link>
+ <link title="2D in 3D Demo">https://godotengine.org/asset-library/asset/129</link>
+ </tutorials>
+ <members>
+ <member name="orientation" type="int" setter="set_orientation" getter="get_orientation" overrides="PlaneMesh" enum="PlaneMesh.Orientation" default="2" />
+ </members>
+</class>
diff --git a/doc/classes/ScriptEditorBase.xml b/doc/classes/ScriptEditorBase.xml
index c365e0971b..68834839f3 100644
--- a/doc/classes/ScriptEditorBase.xml
+++ b/doc/classes/ScriptEditorBase.xml
@@ -19,14 +19,14 @@
<method name="get_base_editor" qualifiers="const">
<return type="Control" />
<description>
- Returns the underlying [Control] used for editing scripts. This can be either [CodeEdit] (for text scripts) or [GraphEdit] (for visual scripts).
+ Returns the underlying [Control] used for editing scripts. For text scripts, this is a [CodeEdit].
</description>
</method>
</methods>
<signals>
<signal name="edited_script_changed">
<description>
- Emitted after script validation. For visual scripts on modification.
+ Emitted after script validation.
</description>
</signal>
<signal name="go_to_help">
@@ -37,13 +37,13 @@
</signal>
<signal name="name_changed">
<description>
- Emitted after script validation or when the edited resource has changed. Not used by visual scripts.
+ Emitted after script validation or when the edited resource has changed.
</description>
</signal>
<signal name="replace_in_files_requested">
<param index="0" name="text" type="String" />
<description>
- Emitted when the user request to find and replace text in the file system. Not used by visual scripts.
+ Emitted when the user request to find and replace text in the file system.
</description>
</signal>
<signal name="request_help">
@@ -67,7 +67,7 @@
<signal name="search_in_files_requested">
<param index="0" name="text" type="String" />
<description>
- Emitted when the user request to search text in the file system. Not used by visual scripts.
+ Emitted when the user request to search text in the file system.
</description>
</signal>
</signals>
diff --git a/doc/classes/StreamPeerGZIP.xml b/doc/classes/StreamPeerGZIP.xml
new file mode 100644
index 0000000000..71dd36160d
--- /dev/null
+++ b/doc/classes/StreamPeerGZIP.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="StreamPeerGZIP" inherits="StreamPeer" is_experimental="true" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
+ <brief_description>
+ Stream peer handling GZIP and deflate compression/decompresison.
+ </brief_description>
+ <description>
+ This class allows to compress or decompress data using GZIP/deflate in a streaming fashion. This is particularly useful when compressing or decompressing files that has to be sent through the network without having to allocate them all in memory.
+ After starting the stream via [method start_compression] (or [method start_decompression]), calling [method StreamPeer.put_partial_data] on this stream will compress (or decompress) the data, writing it to the internal buffer. Calling [method StreamPeer.get_available_bytes] will return the pending bytes in the internal buffer, and [method StreamPeer.get_partial_data] will retrieve the compressed (or decompressed) bytes from it. When the stream is over, you must call [method finish] to ensure the internal buffer is properly flushed (make sure to call [method StreamPeer.get_available_bytes] on last time to check if more data needs to be read after that).
+ </description>
+ <tutorials>
+ </tutorials>
+ <methods>
+ <method name="clear">
+ <return type="void" />
+ <description>
+ Clears this stream, resetting the internal state.
+ </description>
+ </method>
+ <method name="finish">
+ <return type="int" enum="Error" />
+ <description>
+ Finalizes the stream, compressing or decompressing any buffered chunk left.
+ </description>
+ </method>
+ <method name="start_compression">
+ <return type="int" enum="Error" />
+ <param index="0" name="use_deflate" type="bool" default="false" />
+ <param index="1" name="buffer_size" type="int" default="65535" />
+ <description>
+ Start the stream in compression mode with the given [param buffer_size], if [param use_deflate] is [code]true[/code] uses deflate instead of GZIP.
+ </description>
+ </method>
+ <method name="start_decompression">
+ <return type="int" enum="Error" />
+ <param index="0" name="use_deflate" type="bool" default="false" />
+ <param index="1" name="buffer_size" type="int" default="65535" />
+ <description>
+ Start the stream in decompression mode with the given [param buffer_size], if [param use_deflate] is [code]true[/code] uses deflate instead of GZIP.
+ </description>
+ </method>
+ </methods>
+</class>
diff --git a/doc/classes/Tween.xml b/doc/classes/Tween.xml
index 5186972477..acf900ae55 100644
--- a/doc/classes/Tween.xml
+++ b/doc/classes/Tween.xml
@@ -8,42 +8,85 @@
[Tween] is more suited than [AnimationPlayer] for animations where you don't know the final values in advance. For example, interpolating a dynamically-chosen camera zoom value is best done with a [Tween]; it would be difficult to do the same thing with an [AnimationPlayer] node. Tweens are also more light-weight than [AnimationPlayer], so they are very much suited for simple animations or general tasks that don't require visual tweaking provided by the editor. They can be used in a fire-and-forget manner for some logic that normally would be done by code. You can e.g. make something shoot periodically by using a looped [CallbackTweener] with a delay.
A [Tween] can be created by using either [method SceneTree.create_tween] or [method Node.create_tween]. [Tween]s created manually (i.e. by using [code]Tween.new()[/code]) are invalid and can't be used for tweening values.
A tween animation is created by adding [Tweener]s to the [Tween] object, using [method tween_property], [method tween_interval], [method tween_callback] or [method tween_method]:
- [codeblock]
+ [codeblocks]
+ [gdscript]
var tween = get_tree().create_tween()
tween.tween_property($Sprite, "modulate", Color.red, 1)
tween.tween_property($Sprite, "scale", Vector2(), 1)
tween.tween_callback($Sprite.queue_free)
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ Tween tween = GetTree().CreateTween();
+ tween.TweenProperty(GetNode("Sprite"), "modulate", Colors.Red, 1.0f);
+ tween.TweenProperty(GetNode("Sprite"), "scale", Vector2.Zero, 1.0f);
+ tween.TweenCallback(new Callable(GetNode("Sprite").QueueFree));
+ [/csharp]
+ [/codeblocks]
This sequence will make the [code]$Sprite[/code] node turn red, then shrink, before finally calling [method Node.queue_free] to free the sprite. [Tweener]s are executed one after another by default. This behavior can be changed using [method parallel] and [method set_parallel].
When a [Tweener] is created with one of the [code]tween_*[/code] methods, a chained method call can be used to tweak the properties of this [Tweener]. For example, if you want to set a different transition type in the above example, you can use [method set_trans]:
- [codeblock]
+ [codeblocks]
+ [gdscript]
var tween = get_tree().create_tween()
tween.tween_property($Sprite, "modulate", Color.red, 1).set_trans(Tween.TRANS_SINE)
tween.tween_property($Sprite, "scale", Vector2(), 1).set_trans(Tween.TRANS_BOUNCE)
tween.tween_callback($Sprite.queue_free)
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ Tween tween = GetTree().CreateTween();
+ tween.TweenProperty(GetNode("Sprite"), "modulate", Colors.Red, 1.0f).SetTrans(Tween.TransitionType.Sine);
+ tween.TweenProperty(GetNode("Sprite"), "scale", Vector2.Zero, 1.0f).SetTrans(Tween.TransitionType.Bounce);
+ tween.TweenCallback(new Callable(GetNode("Sprite").QueueFree));
+ [/csharp]
+ [/codeblocks]
Most of the [Tween] methods can be chained this way too. In the following example the [Tween] is bound to the running script's node and a default transition is set for its [Tweener]s:
- [codeblock]
+ [codeblocks]
+ [gdscript]
var tween = get_tree().create_tween().bind_node(self).set_trans(Tween.TRANS_ELASTIC)
tween.tween_property($Sprite, "modulate", Color.red, 1)
tween.tween_property($Sprite, "scale", Vector2(), 1)
tween.tween_callback($Sprite.queue_free)
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ var tween = GetTree().CreateTween().BindNode(this).SetTrans(Tween.TransitionType.Elastic);
+ tween.TweenProperty(GetNode("Sprite"), "modulate", Colors.Red, 1.0f);
+ tween.TweenProperty(GetNode("Sprite"), "scale", Vector2.Zero, 1.0f);
+ tween.TweenCallback(new Callable(GetNode("Sprite").QueueFree));
+ [/csharp]
+ [/codeblocks]
Another interesting use for [Tween]s is animating arbitrary sets of objects:
- [codeblock]
+ [codeblocks]
+ [gdscript]
var tween = create_tween()
for sprite in get_children():
tween.tween_property(sprite, "position", Vector2(0, 0), 1)
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ Tween tween = CreateTween();
+ foreach (Node sprite in GetChildren())
+ tween.TweenProperty(sprite, "position", Vector2.Zero, 1.0f);
+ [/csharp]
+ [/codeblocks]
In the example above, all children of a node are moved one after another to position (0, 0).
You should avoid using more than one [Tween] per object's property. If two or more tweens animate one property at the same time, the last one created will take priority and assign the final value. If you want to interrupt and restart an animation, consider assigning the [Tween] to a variable:
- [codeblock]
+ [codeblocks]
+ [gdscript]
var tween
func animate():
if tween:
tween.kill() # Abort the previous animation.
tween = create_tween()
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ private Tween tween;
+
+ public void Animate()
+ {
+ if (tween != null)
+ tween.Kill(); // Abort the previous animation
+ tween = CreateTween();
+ }
+ [/csharp]
+ [/codeblocks]
Some [Tweener]s use transitions and eases. The first accepts a [enum TransitionType] constant, and refers to the way the timing of the animation is handled (see [url=https://easings.net/]easings.net[/url] for some examples). The second accepts an [enum EaseType] constant, and controls where the [code]trans_type[/code] is applied to the interpolation (in the beginning, the end, or both). If you don't know which transition and easing to pick, you can try different [enum TransitionType] constants with [constant EASE_IN_OUT], and use the one that looks best.
[url=https://raw.githubusercontent.com/godotengine/godot-docs/master/img/tween_cheatsheet.png]Tween easing and transition types cheatsheet[/url]
[b]Note:[/b] All [Tween]s will automatically start by default. To prevent a [Tween] from autostarting, you can call [method stop] immediately after it is created.
@@ -64,12 +107,20 @@
<return type="Tween" />
<description>
Used to chain two [Tweener]s after [method set_parallel] is called with [code]true[/code].
- [codeblock]
+ [codeblocks]
+ [gdscript]
var tween = create_tween().set_parallel(true)
tween.tween_property(...)
tween.tween_property(...) # Will run parallelly with above.
tween.chain().tween_property(...) # Will run after two above are finished.
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ Tween tween = CreateTween().SetParallel(true);
+ tween.TweenProperty(...);
+ tween.TweenProperty(...); // Will run parallelly with above.
+ tween.Chain().TweenProperty(...); // Will run after two above are finished.
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="custom_step">
@@ -127,12 +178,20 @@
<return type="Tween" />
<description>
Makes the next [Tweener] run parallelly to the previous one. Example:
- [codeblock]
+ [codeblocks]
+ [gdscript]
var tween = create_tween()
tween.tween_property(...)
tween.parallel().tween_property(...)
tween.parallel().tween_property(...)
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ Tween tween = CreateTween();
+ tween.TweenProperty(...);
+ tween.Parallel().TweenProperty(...);
+ tween.Parallel().TweenProperty(...);
+ [/csharp]
+ [/codeblocks]
All [Tweener]s in the example will run at the same time.
You can make the [Tween] parallel by default by using [method set_parallel].
</description>
@@ -214,16 +273,30 @@
<description>
Creates and appends a [CallbackTweener]. This method can be used to call an arbitrary method in any object. Use [method Callable.bind] to bind additional arguments for the call.
Example: object that keeps shooting every 1 second.
- [codeblock]
+ [codeblocks]
+ [gdscript]
var tween = get_tree().create_tween().set_loops()
tween.tween_callback(shoot).set_delay(1)
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ Tween tween = GetTree().CreateTween().SetLoops();
+ tween.TweenCallback(new Callable(Shoot)).SetDelay(1.0f);
+ [/csharp]
+ [/codeblocks]
Example: turning a sprite red and then blue, with 2 second delay.
- [codeblock]
+ [codeblocks]
+ [gdscript]
var tween = get_tree().create_tween()
tween.tween_callback($Sprite.set_modulate.bind(Color.red)).set_delay(2)
tween.tween_callback($Sprite.set_modulate.bind(Color.blue)).set_delay(2)
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ Tween tween = GetTree().CreateTween();
+ Sprite2D sprite = GetNode&lt;Sprite2D&gt;("Sprite");
+ tween.TweenCallback(new Callable(() =&gt; sprite.Modulate = Colors.Red)).SetDelay(2.0f);
+ tween.TweenCallback(new Callable(() =&gt; sprite.Modulate = Colors.Blue)).SetDelay(2.0f);
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="tween_interval">
@@ -232,13 +305,21 @@
<description>
Creates and appends an [IntervalTweener]. This method can be used to create delays in the tween animation, as an alternative to using the delay in other [Tweener]s, or when there's no animation (in which case the [Tween] acts as a timer). [param time] is the length of the interval, in seconds.
Example: creating an interval in code execution.
- [codeblock]
+ [codeblocks]
+ [gdscript]
# ... some code
await create_tween().tween_interval(2).finished
# ... more code
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ // ... some code
+ await ToSignal(CreateTween().TweenInterval(2.0f), Tween.SignalName.Finished);
+ // ... more code
+ [/csharp]
+ [/codeblocks]
Example: creating an object that moves back and forth and jumps every few seconds.
- [codeblock]
+ [codeblocks]
+ [gdscript]
var tween = create_tween().set_loops()
tween.tween_property($Sprite, "position:x", 200.0, 1).as_relative()
tween.tween_callback(jump)
@@ -246,7 +327,17 @@
tween.tween_property($Sprite, "position:x", -200.0, 1).as_relative()
tween.tween_callback(jump)
tween.tween_interval(2)
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ Tween tween = CreateTween().SetLoops();
+ tween.TweenProperty(GetNode("Sprite"), "position:x", 200.0f, 1.0f).AsRelative();
+ tween.TweenCallback(new Callable(Jump));
+ tween.TweenInterval(2.0f);
+ tween.TweenProperty(GetNode("Sprite"), "position:x", -200.0f, 1.0f).AsRelative();
+ tween.TweenCallback(new Callable(Jump));
+ tween.TweenInterval(2.0f);
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="tween_method">
@@ -258,19 +349,41 @@
<description>
Creates and appends a [MethodTweener]. This method is similar to a combination of [method tween_callback] and [method tween_property]. It calls a method over time with a tweened value provided as an argument. The value is tweened between [param from] and [param to] over the time specified by [param duration], in seconds. Use [method Callable.bind] to bind additional arguments for the call. You can use [method MethodTweener.set_ease] and [method MethodTweener.set_trans] to tweak the easing and transition of the value or [method MethodTweener.set_delay] to delay the tweening.
Example: making a 3D object look from one point to another point.
- [codeblock]
+ [codeblocks]
+ [gdscript]
var tween = create_tween()
tween.tween_method(look_at.bind(Vector3.UP), Vector3(-1, 0, -1), Vector3(1, 0, -1), 1) # The look_at() method takes up vector as second argument.
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ Tween tween = CreateTween();
+ tween.TweenMethod(new Callable(() =&gt; LookAt(Vector3.Up)), new Vector3(-1.0f, 0.0f, -1.0f), new Vector3(1.0f, 0.0f, -1.0f), 1.0f); // The LookAt() method takes up vector as second argument.
+ [/csharp]
+ [/codeblocks]
Example: setting a text of a [Label], using an intermediate method and after a delay.
- [codeblock]
+ [codeblocks]
+ [gdscript]
func _ready():
var tween = create_tween()
tween.tween_method(set_label_text, 0, 10, 1).set_delay(1)
func set_label_text(value: int):
$Label.text = "Counting " + str(value)
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ public override void _Ready()
+ {
+ base._Ready();
+
+ Tween tween = CreateTween();
+ tween.TweenMethod(new Callable(SetLabelText), 0.0f, 10.0f, 1.0f).SetDelay(1.0f);
+ }
+
+ private void SetLabelText(int value)
+ {
+ GetNode&lt;Label&gt;("Label").Text = $"Counting {value}";
+ }
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="tween_property">
@@ -281,19 +394,33 @@
<param index="3" name="duration" type="float" />
<description>
Creates and appends a [PropertyTweener]. This method tweens a [param property] of an [param object] between an initial value and [param final_val] in a span of time equal to [param duration], in seconds. The initial value by default is the property's value at the time the tweening of the [PropertyTweener] starts. For example:
- [codeblock]
+ [codeblocks]
+ [gdscript]
var tween = create_tween()
tween.tween_property($Sprite, "position", Vector2(100, 200), 1)
tween.tween_property($Sprite, "position", Vector2(200, 300), 1)
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ Tween tween = CreateTween();
+ tween.TweenProperty(GetNode("Sprite"), "position", new Vector2(100.0f, 200.0f), 1.0f);
+ tween.TweenProperty(GetNode("Sprite"), "position", new Vector2(200.0f, 300.0f), 1.0f);
+ [/csharp]
+ [/codeblocks]
will move the sprite to position (100, 200) and then to (200, 300). If you use [method PropertyTweener.from] or [method PropertyTweener.from_current], the starting position will be overwritten by the given value instead. See other methods in [PropertyTweener] to see how the tweening can be tweaked further.
[b]Note:[/b] You can find the correct property name by hovering over the property in the Inspector. You can also provide the components of a property directly by using [code]"property:component"[/code] (eg. [code]position:x[/code]), where it would only apply to that particular component.
Example: moving object twice from the same position, with different transition types.
- [codeblock]
+ [codeblocks]
+ [gdscript]
var tween = create_tween()
tween.tween_property($Sprite, "position", Vector2.RIGHT * 300, 1).as_relative().set_trans(Tween.TRANS_SINE)
tween.tween_property($Sprite, "position", Vector2.RIGHT * 300, 1).as_relative().from_current().set_trans(Tween.TRANS_EXPO)
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ Tween tween = CreateTween();
+ tween.TweenProperty(GetNode("Sprite"), "position", Vector2.Right * 300.0f, 1.0f).AsRelative().SetTrans(Tween.TransitionType.Sine);
+ tween.TweenProperty(GetNode("Sprite"), "position", Vector2.Right * 300.0f, 1.0f).AsRelative().FromCurrent().SetTrans(Tween.TransitionType.Expo);
+ [/csharp]
+ [/codeblocks]
</description>
</method>
</methods>