summaryrefslogtreecommitdiff
path: root/doc/classes
diff options
context:
space:
mode:
Diffstat (limited to 'doc/classes')
-rw-r--r--doc/classes/AESContext.xml43
-rw-r--r--doc/classes/AStar.xml89
-rw-r--r--doc/classes/AStar2D.xml72
-rw-r--r--doc/classes/AcceptDialog.xml1
-rw-r--r--doc/classes/Animation.xml15
-rw-r--r--doc/classes/AnimationNodeStateMachine.xml10
-rw-r--r--doc/classes/AnimationNodeStateMachinePlayback.xml10
-rw-r--r--doc/classes/AnimationNodeStateMachineTransition.xml11
-rw-r--r--doc/classes/Array.xml75
-rw-r--r--doc/classes/ArrayMesh.xml25
-rw-r--r--doc/classes/Button.xml20
-rw-r--r--doc/classes/Callable.xml21
-rw-r--r--doc/classes/CanvasItem.xml13
-rw-r--r--doc/classes/CharFXTransform.xml11
-rw-r--r--doc/classes/Color.xml250
-rw-r--r--doc/classes/ColorRect.xml9
-rw-r--r--doc/classes/ConfigFile.xml22
-rw-r--r--doc/classes/ConfirmationDialog.xml9
-rw-r--r--doc/classes/Control.xml217
-rw-r--r--doc/classes/Crypto.xml55
-rw-r--r--doc/classes/Sprite3D.xml3
-rw-r--r--doc/classes/SpriteBase3D.xml12
-rw-r--r--doc/classes/bool.xml83
23 files changed, 893 insertions, 183 deletions
diff --git a/doc/classes/AESContext.xml b/doc/classes/AESContext.xml
index ff433370bd..f577bab992 100644
--- a/doc/classes/AESContext.xml
+++ b/doc/classes/AESContext.xml
@@ -5,7 +5,8 @@
</brief_description>
<description>
This class provides access to AES encryption/decryption of raw data. Both AES-ECB and AES-CBC mode are supported.
- [codeblock]
+ [codeblocks]
+ [gdscript]
extends Node
var aes = AESContext.new()
@@ -35,7 +36,45 @@
aes.finish()
# Check CBC
assert(decrypted == data.to_utf8())
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ using Godot;
+ using System;
+ using System.Diagnostics;
+
+ public class Example : Node
+ {
+ public AESContext Aes = new AESContext();
+ public override void _Ready()
+ {
+ string key = "My secret key!!!"; // Key must be either 16 or 32 bytes.
+ string data = "My secret text!!"; // Data size must be multiple of 16 bytes, apply padding if needed.
+ // Encrypt ECB
+ Aes.Start(AESContext.Mode.EcbEncrypt, key.ToUTF8());
+ byte[] encrypted = Aes.Update(data.ToUTF8());
+ Aes.Finish();
+ // Decrypt ECB
+ Aes.Start(AESContext.Mode.EcbDecrypt, key.ToUTF8());
+ byte[] decrypted = Aes.Update(encrypted);
+ Aes.Finish();
+ // Check ECB
+ Debug.Assert(decrypted == data.ToUTF8());
+
+ string iv = "My secret iv!!!!"; // IV must be of exactly 16 bytes.
+ // Encrypt CBC
+ Aes.Start(AESContext.Mode.EcbEncrypt, key.ToUTF8(), iv.ToUTF8());
+ encrypted = Aes.Update(data.ToUTF8());
+ Aes.Finish();
+ // Decrypt CBC
+ Aes.Start(AESContext.Mode.EcbDecrypt, key.ToUTF8(), iv.ToUTF8());
+ decrypted = Aes.Update(encrypted);
+ Aes.Finish();
+ // Check CBC
+ Debug.Assert(decrypted == data.ToUTF8());
+ }
+ }
+ [/csharp]
+ [/codeblocks]
</description>
<tutorials>
</tutorials>
diff --git a/doc/classes/AStar.xml b/doc/classes/AStar.xml
index 2695e86f47..0cd7d3dc25 100644
--- a/doc/classes/AStar.xml
+++ b/doc/classes/AStar.xml
@@ -7,7 +7,8 @@
A* (A star) is a computer algorithm that is widely used in pathfinding and graph traversal, the process of plotting short paths among vertices (points), passing through a given set of edges (segments). It enjoys widespread use due to its performance and accuracy. Godot's A* implementation uses points in three-dimensional space and Euclidean distances by default.
You must add points manually with [method add_point] and create segments manually with [method connect_points]. Then you can test if there is a path between two points with the [method are_points_connected] function, get a path containing indices by [method get_id_path], or one containing actual coordinates with [method get_point_path].
It is also possible to use non-Euclidean distances. To do so, create a class that extends [code]AStar[/code] and override methods [method _compute_cost] and [method _estimate_cost]. Both take two indices and return a length, as is shown in the following example.
- [codeblock]
+ [codeblocks]
+ [gdscript]
class MyAStar:
extends AStar
@@ -16,7 +17,21 @@
func _estimate_cost(u, v):
return min(0, abs(u - v) - 1)
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ public class MyAStar : AStar
+ {
+ public override float _ComputeCost(int u, int v)
+ {
+ return Mathf.Abs(u - v);
+ }
+ public override float _EstimateCost(int u, int v)
+ {
+ return Mathf.Min(0, Mathf.Abs(u - v) - 1);
+ }
+ }
+ [/csharp]
+ [/codeblocks]
[method _estimate_cost] should return a lower bound of the distance, i.e. [code]_estimate_cost(u, v) &lt;= _compute_cost(u, v)[/code]. This serves as a hint to the algorithm because the custom [code]_compute_cost[/code] might be computation-heavy. If this is not the case, make [method _estimate_cost] return the same value as [method _compute_cost] to provide the algorithm with the most accurate information.
</description>
<tutorials>
@@ -57,10 +72,16 @@
</argument>
<description>
Adds a new point at the given position with the given identifier. The algorithm prefers points with lower [code]weight_scale[/code] to form a path. The [code]id[/code] must be 0 or larger, and the [code]weight_scale[/code] must be 1 or larger.
- [codeblock]
+ [codeblocks]
+ [gdscript]
var astar = AStar.new()
astar.add_point(1, Vector3(1, 0, 0), 4) # Adds the point (1, 0, 0) with weight_scale 4 and id 1
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ var astar = new AStar();
+ astar.AddPoint(1, new Vector3(1, 0, 0), 4); // Adds the point (1, 0, 0) with weight_scale 4 and id 1
+ [/csharp]
+ [/codeblocks]
If there already exists a point for the given [code]id[/code], its position and weight scale are updated to the given values.
</description>
</method>
@@ -95,12 +116,20 @@
</argument>
<description>
Creates a segment between the given points. If [code]bidirectional[/code] is [code]false[/code], only movement from [code]id[/code] to [code]to_id[/code] is allowed, not the reverse direction.
- [codeblock]
+ [codeblocks]
+ [gdscript]
var astar = AStar.new()
astar.add_point(1, Vector3(1, 1, 0))
astar.add_point(2, Vector3(0, 5, 0))
astar.connect_points(1, 2, false)
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ var astar = new AStar();
+ astar.AddPoint(1, new Vector3(1, 1, 0));
+ astar.AddPoint(2, new Vector3(0, 5, 0));
+ astar.ConnectPoints(1, 2, false);
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="disconnect_points">
@@ -142,13 +171,22 @@
</argument>
<description>
Returns the closest position to [code]to_position[/code] that resides inside a segment between two connected points.
- [codeblock]
+ [codeblocks]
+ [gdscript]
var astar = AStar.new()
astar.add_point(1, Vector3(0, 0, 0))
astar.add_point(2, Vector3(0, 5, 0))
astar.connect_points(1, 2)
var res = astar.get_closest_position_in_segment(Vector3(3, 3, 0)) # Returns (0, 3, 0)
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ var astar = new AStar();
+ astar.AddPoint(1, new Vector3(0, 0, 0));
+ astar.AddPoint(2, new Vector3(0, 5, 0));
+ astar.ConnectPoints(1, 2);
+ Vector3 res = astar.GetClosestPositionInSegment(new Vector3(3, 3, 0)); // Returns (0, 3, 0)
+ [/csharp]
+ [/codeblocks]
The result is in the segment that goes from [code]y = 0[/code] to [code]y = 5[/code]. It's the closest position in the segment to the given point.
</description>
</method>
@@ -161,7 +199,8 @@
</argument>
<description>
Returns an array with the IDs of the points that form the path found by AStar between the given points. The array is ordered from the starting point to the ending point of the path.
- [codeblock]
+ [codeblocks]
+ [gdscript]
var astar = AStar.new()
astar.add_point(1, Vector3(0, 0, 0))
astar.add_point(2, Vector3(0, 1, 0), 1) # Default weight is 1
@@ -174,7 +213,20 @@
astar.connect_points(1, 4, false)
var res = astar.get_id_path(1, 3) # Returns [1, 2, 3]
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ var astar = new AStar();
+ astar.AddPoint(1, new Vector3(0, 0, 0));
+ astar.AddPoint(2, new Vector3(0, 1, 0), 1); // Default weight is 1
+ astar.AddPoint(3, new Vector3(1, 1, 0));
+ astar.AddPoint(4, new Vector3(2, 0, 0));
+ astar.ConnectPoints(1, 2, false);
+ astar.ConnectPoints(2, 3, false);
+ astar.ConnectPoints(4, 3, false);
+ astar.ConnectPoints(1, 4, false);
+ int[] res = astar.GetIdPath(1, 3); // Returns [1, 2, 3]
+ [/csharp]
+ [/codeblocks]
If you change the 2nd point's weight to 3, then the result will be [code][1, 4, 3][/code] instead, because now even though the distance is longer, it's "easier" to get through point 4 than through point 2.
</description>
</method>
@@ -192,7 +244,8 @@
</argument>
<description>
Returns an array with the IDs of the points that form the connection with the given point.
- [codeblock]
+ [codeblocks]
+ [gdscript]
var astar = AStar.new()
astar.add_point(1, Vector3(0, 0, 0))
astar.add_point(2, Vector3(0, 1, 0))
@@ -203,7 +256,19 @@
astar.connect_points(1, 3, true)
var neighbors = astar.get_point_connections(1) # Returns [2, 3]
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ var astar = new AStar();
+ astar.AddPoint(1, new Vector3(0, 0, 0));
+ astar.AddPoint(2, new Vector3(0, 1, 0));
+ astar.AddPoint(3, new Vector3(1, 1, 0));
+ astar.AddPoint(4, new Vector3(2, 0, 0));
+ astar.ConnectPoints(1, 2, true);
+ astar.ConnectPoints(1, 3, true);
+
+ int[] neighbors = astar.GetPointConnections(1); // Returns [2, 3]
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="get_point_count" qualifiers="const">
diff --git a/doc/classes/AStar2D.xml b/doc/classes/AStar2D.xml
index 622d336ef6..1540d8dacc 100644
--- a/doc/classes/AStar2D.xml
+++ b/doc/classes/AStar2D.xml
@@ -44,10 +44,16 @@
</argument>
<description>
Adds a new point at the given position with the given identifier. The algorithm prefers points with lower [code]weight_scale[/code] to form a path. The [code]id[/code] must be 0 or larger, and the [code]weight_scale[/code] must be 1 or larger.
- [codeblock]
+ [codeblocks]
+ [gdscript]
var astar = AStar2D.new()
astar.add_point(1, Vector2(1, 0), 4) # Adds the point (1, 0) with weight_scale 4 and id 1
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ var astar = new AStar2D();
+ astar.AddPoint(1, new Vector2(1, 0), 4); // Adds the point (1, 0) with weight_scale 4 and id 1
+ [/csharp]
+ [/codeblocks]
If there already exists a point for the given [code]id[/code], its position and weight scale are updated to the given values.
</description>
</method>
@@ -80,12 +86,20 @@
</argument>
<description>
Creates a segment between the given points. If [code]bidirectional[/code] is [code]false[/code], only movement from [code]id[/code] to [code]to_id[/code] is allowed, not the reverse direction.
- [codeblock]
+ [codeblocks]
+ [gdscript]
var astar = AStar2D.new()
astar.add_point(1, Vector2(1, 1))
astar.add_point(2, Vector2(0, 5))
astar.connect_points(1, 2, false)
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ var astar = new AStar2D();
+ astar.AddPoint(1, new Vector2(1, 1));
+ astar.AddPoint(2, new Vector2(0, 5));
+ astar.ConnectPoints(1, 2, false);
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="disconnect_points">
@@ -125,13 +139,22 @@
</argument>
<description>
Returns the closest position to [code]to_position[/code] that resides inside a segment between two connected points.
- [codeblock]
+ [codeblocks]
+ [gdscript]
var astar = AStar2D.new()
astar.add_point(1, Vector2(0, 0))
astar.add_point(2, Vector2(0, 5))
astar.connect_points(1, 2)
var res = astar.get_closest_position_in_segment(Vector2(3, 3)) # Returns (0, 3)
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ var astar = new AStar2D();
+ astar.AddPoint(1, new Vector2(0, 0));
+ astar.AddPoint(2, new Vector2(0, 5));
+ astar.ConnectPoints(1, 2);
+ Vector2 res = astar.GetClosestPositionInSegment(new Vector2(3, 3)); // Returns (0, 3)
+ [/csharp]
+ [/codeblocks]
The result is in the segment that goes from [code]y = 0[/code] to [code]y = 5[/code]. It's the closest position in the segment to the given point.
</description>
</method>
@@ -144,7 +167,8 @@
</argument>
<description>
Returns an array with the IDs of the points that form the path found by AStar2D between the given points. The array is ordered from the starting point to the ending point of the path.
- [codeblock]
+ [codeblocks]
+ [gdscript]
var astar = AStar2D.new()
astar.add_point(1, Vector2(0, 0))
astar.add_point(2, Vector2(0, 1), 1) # Default weight is 1
@@ -157,7 +181,21 @@
astar.connect_points(1, 4, false)
var res = astar.get_id_path(1, 3) # Returns [1, 2, 3]
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ var astar = new AStar2D();
+ astar.AddPoint(1, new Vector2(0, 0));
+ astar.AddPoint(2, new Vector2(0, 1), 1); // Default weight is 1
+ astar.AddPoint(3, new Vector2(1, 1));
+ astar.AddPoint(4, new Vector2(2, 0));
+
+ astar.ConnectPoints(1, 2, false);
+ astar.ConnectPoints(2, 3, false);
+ astar.ConnectPoints(4, 3, false);
+ astar.ConnectPoints(1, 4, false);
+ int[] res = astar.GetIdPath(1, 3); // Returns [1, 2, 3]
+ [/csharp]
+ [/codeblocks]
If you change the 2nd point's weight to 3, then the result will be [code][1, 4, 3][/code] instead, because now even though the distance is longer, it's "easier" to get through point 4 than through point 2.
</description>
</method>
@@ -175,7 +213,8 @@
</argument>
<description>
Returns an array with the IDs of the points that form the connection with the given point.
- [codeblock]
+ [codeblocks]
+ [gdscript]
var astar = AStar2D.new()
astar.add_point(1, Vector2(0, 0))
astar.add_point(2, Vector2(0, 1))
@@ -186,7 +225,20 @@
astar.connect_points(1, 3, true)
var neighbors = astar.get_point_connections(1) # Returns [2, 3]
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ var astar = new AStar2D();
+ astar.AddPoint(1, new Vector2(0, 0));
+ astar.AddPoint(2, new Vector2(0, 1));
+ astar.AddPoint(3, new Vector2(1, 1));
+ astar.AddPoint(4, new Vector2(2, 0));
+
+ astar.ConnectPoints(1, 2, true);
+ astar.ConnectPoints(1, 3, true);
+
+ int[] neighbors = astar.GetPointConnections(1); // Returns [2, 3]
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="get_point_count" qualifiers="const">
diff --git a/doc/classes/AcceptDialog.xml b/doc/classes/AcceptDialog.xml
index 6b1864b679..e5eb216062 100644
--- a/doc/classes/AcceptDialog.xml
+++ b/doc/classes/AcceptDialog.xml
@@ -76,6 +76,7 @@
<signals>
<signal name="cancelled">
<description>
+ Emitted when the dialog is closed or the button created with [method add_cancel] is pressed.
</description>
</signal>
<signal name="confirmed">
diff --git a/doc/classes/Animation.xml b/doc/classes/Animation.xml
index 0a2925e6d5..9529c60771 100644
--- a/doc/classes/Animation.xml
+++ b/doc/classes/Animation.xml
@@ -5,7 +5,8 @@
</brief_description>
<description>
An Animation resource contains data used to animate everything in the engine. Animations are divided into tracks, and each track must be linked to a node. The state of that node can be changed through time, by adding timed keys (events) to the track.
- [codeblock]
+ [codeblocks]
+ [gdscript]
# This creates an animation that makes the node "Enemy" move to the right by
# 100 pixels in 0.5 seconds.
var animation = Animation.new()
@@ -13,7 +14,17 @@
animation.track_set_path(track_index, "Enemy:position:x")
animation.track_insert_key(track_index, 0.0, 0)
animation.track_insert_key(track_index, 0.5, 100)
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ // This creates an animation that makes the node "Enemy" move to the right by
+ // 100 pixels in 0.5 seconds.
+ var animation = new Animation();
+ int trackIndex = animation.AddTrack(Animation.TrackType.Value);
+ animation.TrackSetPath(trackIndex, "Enemy:position:x");
+ animation.TrackInsertKey(trackIndex, 0.0f, 0);
+ animation.TrackInsertKey(trackIndex, 0.5f, 100);
+ [/csharp]
+ [/codeblocks]
Animations are just data containers, and must be added to nodes such as an [AnimationPlayer] to be played back. Animation tracks have different types, each with its own set of dedicated methods. Check [enum TrackType] to see available types.
</description>
<tutorials>
diff --git a/doc/classes/AnimationNodeStateMachine.xml b/doc/classes/AnimationNodeStateMachine.xml
index 9ea83d2c5e..e08e288c59 100644
--- a/doc/classes/AnimationNodeStateMachine.xml
+++ b/doc/classes/AnimationNodeStateMachine.xml
@@ -6,10 +6,16 @@
<description>
Contains multiple nodes representing animation states, connected in a graph. Node transitions can be configured to happen automatically or via code, using a shortest-path algorithm. Retrieve the [AnimationNodeStateMachinePlayback] object from the [AnimationTree] node to control it programmatically.
[b]Example:[/b]
- [codeblock]
+ [codeblocks]
+ [gdscript]
var state_machine = $AnimationTree.get("parameters/playback")
state_machine.travel("some_state")
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ var stateMachine = GetNode&lt;AnimationTree&gt;("AnimationTree").Get("parameters/playback") as AnimationNodeStateMachinePlayback;
+ stateMachine.Travel("some_state");
+ [/csharp]
+ [/codeblocks]
</description>
<tutorials>
<link title="AnimationTree">https://docs.godotengine.org/en/latest/tutorials/animation/animation_tree.html</link>
diff --git a/doc/classes/AnimationNodeStateMachinePlayback.xml b/doc/classes/AnimationNodeStateMachinePlayback.xml
index fec68d5b74..60ff425cdb 100644
--- a/doc/classes/AnimationNodeStateMachinePlayback.xml
+++ b/doc/classes/AnimationNodeStateMachinePlayback.xml
@@ -6,10 +6,16 @@
<description>
Allows control of [AnimationTree] state machines created with [AnimationNodeStateMachine]. Retrieve with [code]$AnimationTree.get("parameters/playback")[/code].
[b]Example:[/b]
- [codeblock]
+ [codeblocks]
+ [gdscript]
var state_machine = $AnimationTree.get("parameters/playback")
state_machine.travel("some_state")
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ var stateMachine = GetNode&lt;AnimationTree&gt;("AnimationTree").Get("parameters/playback") as AnimationNodeStateMachinePlayback;
+ stateMachine.Travel("some_state");
+ [/csharp]
+ [/codeblocks]
</description>
<tutorials>
<link title="AnimationTree">https://docs.godotengine.org/en/latest/tutorials/animation/animation_tree.html</link>
diff --git a/doc/classes/AnimationNodeStateMachineTransition.xml b/doc/classes/AnimationNodeStateMachineTransition.xml
index fe0154acad..2f0ebd7de6 100644
--- a/doc/classes/AnimationNodeStateMachineTransition.xml
+++ b/doc/classes/AnimationNodeStateMachineTransition.xml
@@ -12,9 +12,14 @@
<members>
<member name="advance_condition" type="StringName" setter="set_advance_condition" getter="get_advance_condition" default="@&quot;&quot;">
Turn on auto advance when this condition is set. The provided name will become a boolean parameter on the [AnimationTree] that can be controlled from code (see [url=https://docs.godotengine.org/en/latest/tutorials/animation/animation_tree.html#controlling-from-code][/url]). For example, if [member AnimationTree.tree_root] is an [AnimationNodeStateMachine] and [member advance_condition] is set to [code]"idle"[/code]:
- [codeblock]
- $animation_tree["parameters/conditions/idle"] = is_on_floor and (linear_velocity.x == 0)
- [/codeblock]
+ [codeblocks]
+ [gdscript]
+ $animation_tree.set("parameters/conditions/idle", is_on_floor and (linear_velocity.x == 0))
+ [/gdscript]
+ [csharp]
+ GetNode&lt;AnimationTree&gt;("animation_tree").Set("parameters/conditions/idle", IsOnFloor &amp;&amp; (LinearVelocity.x == 0));
+ [/csharp]
+ [/codeblocks]
</member>
<member name="auto_advance" type="bool" setter="set_auto_advance" getter="has_auto_advance" default="false">
Turn on the transition automatically when this state is reached. This works best with [constant SWITCH_MODE_AT_END].
diff --git a/doc/classes/Array.xml b/doc/classes/Array.xml
index 8bbb0817ea..87b7443a8a 100644
--- a/doc/classes/Array.xml
+++ b/doc/classes/Array.xml
@@ -6,20 +6,38 @@
<description>
Generic array which can contain several elements of any type, accessible by a numerical index starting at 0. Negative indices can be used to count from the back, like in Python (-1 is the last element, -2 the second to last, etc.).
[b]Example:[/b]
- [codeblock]
+ [codeblocks]
+ [gdscript]
var array = ["One", 2, 3, "Four"]
print(array[0]) # One.
print(array[2]) # 3.
print(array[-1]) # Four.
array[2] = "Three"
print(array[-2]) # Three.
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ var array = new Godot.Collections.Array{"One", 2, 3, "Four"};
+ GD.Print(array[0]); // One.
+ GD.Print(array[2]); // 3.
+ GD.Print(array[array.Count - 1]); // Four.
+ array[2] = "Three";
+ GD.Print(array[array.Count - 2]); // Three.
+ [/csharp]
+ [/codeblocks]
Arrays can be concatenated using the [code]+[/code] operator:
- [codeblock]
+ [codeblocks]
+ [gdscript]
var array1 = ["One", 2]
var array2 = [3, "Four"]
print(array1 + array2) # ["One", 2, 3, "Four"]
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ // Array concatenation is not possible with C# arrays, but is with Godot.Collections.Array.
+ var array1 = new Godot.Collections.Array("One", 2);
+ var array2 = new Godot.Collections.Array(3, "Four");
+ GD.Print(array1 + array2); // Prints [One, 2, 3, Four]
+ [/csharp]
+ [/codeblocks]
[b]Note:[/b] Arrays are always passed by reference. To get a copy of an array which can be modified independently of the original array, use [method duplicate].
</description>
<tutorials>
@@ -228,18 +246,39 @@
</argument>
<description>
Returns [code]true[/code] if the array contains the given value.
- [codeblock]
+ [codeblocks]
+ [gdscript]
print(["inside", 7].has("inside")) # True
print(["inside", 7].has("outside")) # False
print(["inside", 7].has(7)) # True
print(["inside", 7].has("7")) # False
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ var arr = new Godot.Collections.Array{"inside", 7};
+ // has is renamed to Contains
+ GD.Print(arr.Contains("inside")); // True
+ GD.Print(arr.Contains("outside")); // False
+ GD.Print(arr.Contains(7)); // True
+ GD.Print(arr.Contains("7")); // False
+ [/csharp]
+ [/codeblocks]
+
[b]Note:[/b] This is equivalent to using the [code]in[/code] operator as follows:
- [codeblock]
+ [codeblocks]
+ [gdscript]
# Will evaluate to `true`.
if 2 in [2, 4, 6, 8]:
- pass
- [/codeblock]
+ print("Containes!")
+ [/gdscript]
+ [csharp]
+ // As there is no "in" keyword in C#, you have to use Contains
+ var array = new Godot.Collections.Array{2, 4, 6, 8};
+ if (array.Contains(2))
+ {
+ GD.Print("Containes!");
+ }
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="hash">
@@ -377,11 +416,16 @@
<description>
Sorts the array.
[b]Note:[/b] Strings are sorted in alphabetical order (as opposed to natural order). This may lead to unexpected behavior when sorting an array of strings ending with a sequence of numbers. Consider the following example:
- [codeblock]
+ [codeblocks]
+ [gdscript]
var strings = ["string1", "string2", "string10", "string11"]
strings.sort()
print(strings) # Prints [string1, string10, string11, string2]
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ // There is no sort support for Godot.Collections.Array
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="sort_custom">
@@ -394,7 +438,8 @@
<description>
Sorts the array using a custom method. The arguments are an object that holds the method and the name of such method. The custom method receives two arguments (a pair of elements from the array) and must return either [code]true[/code] or [code]false[/code].
[b]Note:[/b] you cannot randomize the return value as the heapsort algorithm expects a deterministic result. Doing so will result in unexpected behavior.
- [codeblock]
+ [codeblocks]
+ [gdscript]
class MyCustomSorter:
static func sort_ascending(a, b):
if a[0] &lt; b[0]:
@@ -404,7 +449,11 @@
var my_items = [[5, "Potato"], [9, "Rice"], [4, "Tomato"]]
my_items.sort_custom(MyCustomSorter, "sort_ascending")
print(my_items) # Prints [[4, Tomato], [5, Potato], [9, Rice]].
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ // There is no custom sort support for Godot.Collections.Array
+ [/csharp]
+ [/codeblocks]
</description>
</method>
</methods>
diff --git a/doc/classes/ArrayMesh.xml b/doc/classes/ArrayMesh.xml
index 4ec39ecc2f..4edf69ccb2 100644
--- a/doc/classes/ArrayMesh.xml
+++ b/doc/classes/ArrayMesh.xml
@@ -6,21 +6,42 @@
<description>
The [ArrayMesh] is used to construct a [Mesh] by specifying the attributes as arrays.
The most basic example is the creation of a single triangle:
- [codeblock]
+ [codeblocks]
+ [gdscript]
var vertices = PackedVector3Array()
vertices.push_back(Vector3(0, 1, 0))
vertices.push_back(Vector3(1, 0, 0))
vertices.push_back(Vector3(0, 0, 1))
+
# Initialize the ArrayMesh.
var arr_mesh = ArrayMesh.new()
var arrays = []
arrays.resize(ArrayMesh.ARRAY_MAX)
arrays[ArrayMesh.ARRAY_VERTEX] = vertices
+
# Create the Mesh.
arr_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arrays)
var m = MeshInstance3D.new()
m.mesh = arr_mesh
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ var vertices = new Godot.Collections.Array&lt;Vector3&gt;();
+ vertices.Add(new Vector3(0, 1, 0));
+ vertices.Add(new Vector3(1, 0, 0));
+ vertices.Add(new Vector3(0, 0, 1));
+
+ // Initialize the ArrayMesh.
+ var arrMesh = new ArrayMesh();
+ var arrays = new Godot.Collections.Array();
+ arrays.Resize((int)ArrayMesh.ArrayType.Max);
+ arrays[(int)ArrayMesh.ArrayType.Vertex] = vertices;
+
+ // Create the Mesh.
+ arrMesh.AddSurfaceFromArrays(Mesh.PrimitiveType.Triangles, arrays);
+ var m = new MeshInstance();
+ m.Mesh = arrMesh;
+ [/csharp]
+ [/codeblocks]
The [MeshInstance3D] is ready to be added to the [SceneTree] to be shown.
See also [ImmediateGeometry3D], [MeshDataTool] and [SurfaceTool] for procedural geometry generation.
[b]Note:[/b] Godot uses clockwise [url=https://learnopengl.com/Advanced-OpenGL/Face-culling]winding order[/url] for front faces of triangle primitive modes.
diff --git a/doc/classes/Button.xml b/doc/classes/Button.xml
index 7795fb6d4c..e0ccda957f 100644
--- a/doc/classes/Button.xml
+++ b/doc/classes/Button.xml
@@ -6,7 +6,8 @@
<description>
Button is the standard themed button. It can contain text and an icon, and will display them according to the current [Theme].
[b]Example of creating a button and assigning an action when pressed by code:[/b]
- [codeblock]
+ [codeblocks]
+ [gdscript]
func _ready():
var button = Button.new()
button.text = "Click me"
@@ -15,7 +16,22 @@
func _button_pressed():
print("Hello world!")
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ public override void _Ready()
+ {
+ var button = new Button();
+ button.Text = "Click me";
+ button.Connect("pressed", this, nameof(ButtonPressed));
+ AddChild(button);
+ }
+
+ private void ButtonPressed()
+ {
+ GD.Print("Hello world!");
+ }
+ [/csharp]
+ [/codeblocks]
Buttons (like all Control nodes) can also be created in the editor, but some situations may require creating them from code.
See also [BaseButton] which contains common properties and methods associated with this node.
</description>
diff --git a/doc/classes/Callable.xml b/doc/classes/Callable.xml
index 3cc74beb58..3bbee993ac 100644
--- a/doc/classes/Callable.xml
+++ b/doc/classes/Callable.xml
@@ -6,15 +6,32 @@
<description>
[Callable] is a first class object which can be held in variables and passed to functions. It represents a given method in an [Object], and is typically used for signal callbacks.
[b]Example:[/b]
- [codeblock]
+ [codeblocks]
+ [gdscript]
var callable = Callable(self, "print_args")
func print_args(arg1, arg2, arg3 = ""):
prints(arg1, arg2, arg3)
+
func test():
callable.call("hello", "world") # Prints "hello world".
callable.call(Vector2.UP, 42, callable) # Prints "(0, -1) 42 Node(Node.gd)::print_args".
callable.call("invalid") # Invalid call, should have at least 2 arguments.
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ Callable callable = new Callable(this, "print_args");
+ public void PrintArgs(object arg1, object arg2, object arg3 = "")
+ {
+ GD.PrintS(arg1, arg2, arg3);
+ }
+
+ public void Test()
+ {
+ callable.Call("hello", "world"); // Prints "hello world".
+ callable.Call(Vector2.Up, 42, callable); // Prints "(0, -1) 42 Node(Node.gd)::print_args".
+ callable.Call("invalid"); // Invalid call, should have at least 2 arguments.
+ }
+ [/csharp]
+ [/codeblocks]
</description>
<tutorials>
</tutorials>
diff --git a/doc/classes/CanvasItem.xml b/doc/classes/CanvasItem.xml
index 0eecada4fe..946c4f8988 100644
--- a/doc/classes/CanvasItem.xml
+++ b/doc/classes/CanvasItem.xml
@@ -318,13 +318,22 @@
<description>
Draws [code]text[/code] using the specified [code]font[/code] at the [code]position[/code] (top-left corner). The text will have its color multiplied by [code]modulate[/code]. If [code]clip_w[/code] is greater than or equal to 0, the text will be clipped if it exceeds the specified width.
[b]Example using the default project font:[/b]
- [codeblock]
+ [codeblocks]
+ [gdscript]
# If using this method in a script that redraws constantly, move the
# `default_font` declaration to a member variable assigned in `_ready()`
# so the Control is only created once.
var default_font = Control.new().get_font("font")
draw_string(default_font, Vector2(64, 64), "Hello world")
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ // If using this method in a script that redraws constantly, move the
+ // `default_font` declaration to a member variable assigned in `_ready()`
+ // so the Control is only created once.
+ Font defaultFont = new Control().GetFont("font");
+ DrawString(defaultFont, new Vector2(64, 64), "Hello world");
+ [/csharp]
+ [/codeblocks]
See also [method Font.draw].
</description>
</method>
diff --git a/doc/classes/CharFXTransform.xml b/doc/classes/CharFXTransform.xml
index a988035c36..d1759adf30 100644
--- a/doc/classes/CharFXTransform.xml
+++ b/doc/classes/CharFXTransform.xml
@@ -18,11 +18,18 @@
</member>
<member name="character" type="int" setter="set_character" getter="get_character" default="0">
The Unicode codepoint the character will use. This only affects non-whitespace characters. [method @GDScript.ord] can be useful here. For example, the following will replace all characters with asterisks:
- [codeblock]
+ [codeblocks]
+ [gdscript]
# `char_fx` is the CharFXTransform parameter from `_process_custom_fx()`.
# See the RichTextEffect documentation for details.
char_fx.character = ord("*")
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ // `char_fx` is the CharFXTransform parameter from `_process_custom_fx()`.
+ // See the RichTextEffect documentation for details.
+ charFx.Character = char.GetNumericValue('*');
+ [/csharp]
+ [/codeblocks]
</member>
<member name="color" type="Color" setter="set_color" getter="get_color" default="Color( 0, 0, 0, 1 )">
The color the character will be drawn with.
diff --git a/doc/classes/Color.xml b/doc/classes/Color.xml
index 850e95d5ef..1d249a253c 100644
--- a/doc/classes/Color.xml
+++ b/doc/classes/Color.xml
@@ -20,21 +20,39 @@
</argument>
<description>
Constructs a color from an HTML hexadecimal color string in RGB or RGBA format. See also [method @GDScript.ColorN].
- [codeblock]
+ [codeblocks]
+ [gdscript]
# Each of the following creates the same color RGBA(178, 217, 10, 255).
var c3 = Color("#b2d90a") # RGB format with "#".
var c4 = Color("b2d90a") # RGB format.
var c1 = Color("#b2d90aff") # RGBA format with "#".
var c2 = Color("b2d90aff") # RGBA format.
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ // Each of the following creates the same color RGBA(178, 217, 10, 255).
+ var c3 = new Color("#b2d90a");
+ var c4 = new Color("b2d90a"); // RGB format.
+ var c1 = new Color("#b2d90aff");
+ var c2 = new Color("b2d90aff"); // RGBA format.
+ [/csharp]
+ [/codeblocks]
You can also use the "web color" short-hand form by only using 3 or 4 digits.
- [codeblock]
+ [codeblocks]
+ [gdscript]
# Each of the following creates the same color RGBA(17, 34, 51, 255).
var c3 = Color("#123") # RGB format with "#".
var c4 = Color("123") # RGB format.
var c1 = Color("#123f") # RGBA format with "#".
var c2 = Color("123f") # RGBA format.
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ // Each of the following creates the same color RGBA(17, 34, 51, 255).
+ var c3 = new Color("#123");
+ var c4 = new Color("123"); // RGB format.
+ var c1 = new Color("#123f");
+ var c2 = new Color("123f"); // RGBA format.
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="Color">
@@ -44,9 +62,14 @@
</argument>
<description>
Constructs a color from a 32-bit integer (each byte represents a component of the RGBA profile).
- [codeblock]
+ [codeblocks]
+ [gdscript]
var c = Color(274) # Equivalent to RGBA(0, 0, 1, 18)
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ var c = new Color(274); // Equivalent to RGBA(0, 0, 1, 18)
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="Color">
@@ -58,9 +81,14 @@
</argument>
<description>
Constructs a color from an existing color, but with a custom alpha value.
- [codeblock]
+ [codeblocks]
+ [gdscript]
var red = Color(Color.red, 0.5) # 50% transparent red.
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ var red = new Color(Colors.Red, 0.5f); // 50% transparent red.
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="Color">
@@ -74,9 +102,14 @@
</argument>
<description>
Constructs a color from an RGB profile using values between 0 and 1. Alpha will always be 1.
- [codeblock]
- var c = Color(0.2, 1.0, 0.7) # Equivalent to RGBA(51, 255, 178, 255)
- [/codeblock]
+ [codeblocks]
+ [gdscript]
+ var color = Color(0.2, 1.0, 0.7) # Equivalent to RGBA(51, 255, 178, 255)
+ [/gdscript]
+ [csharp]
+ var color = new Color(0.2f, 1.0f, 0.7f); // Equivalent to RGBA(51, 255, 178, 255)
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="Color">
@@ -92,9 +125,14 @@
</argument>
<description>
Constructs a color from an RGBA profile using values between 0 and 1.
- [codeblock]
- var c = Color(0.2, 1.0, 0.7, 0.8) # Equivalent to RGBA(51, 255, 178, 204)
- [/codeblock]
+ [codeblocks]
+ [gdscript]
+ var color = Color(0.2, 1.0, 0.7, 0.8) # Equivalent to RGBA(51, 255, 178, 204)
+ [/gdscript]
+ [csharp]
+ var color = new Color(0.2f, 1.0f, 0.7f, 0.8f); // Equivalent to RGBA(51, 255, 178, 255, 204)
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="blend">
@@ -104,11 +142,18 @@
</argument>
<description>
Returns a new color resulting from blending this color over another. If the color is opaque, the result is also opaque. The second color may have a range of alpha values.
- [codeblock]
+ [codeblocks]
+ [gdscript]
var bg = Color(0.0, 1.0, 0.0, 0.5) # Green with alpha of 50%
var fg = Color(1.0, 0.0, 0.0, 0.5) # Red with alpha of 50%
var blended_color = bg.blend(fg) # Brown with alpha of 75%
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ var bg = new Color(0.0f, 1.0f, 0.0f, 0.5f); // Green with alpha of 50%
+ var fg = new Color(1.0f, 0.0f, 0.0f, 0.5f); // Red with alpha of 50%
+ Color blendedColor = bg.Blend(fg); // Brown with alpha of 75%
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="contrasted">
@@ -116,10 +161,16 @@
</return>
<description>
Returns the most contrasting color.
- [codeblock]
- var c = Color(0.3, 0.4, 0.9)
- var contrasted_color = c.contrasted() # Equivalent to RGBA(204, 229, 102, 255)
- [/codeblock]
+ [codeblocks]
+ [gdscript]
+ var color = Color(0.3, 0.4, 0.9)
+ var contrasted_color = color.contrasted() # Equivalent to RGBA(204, 229, 102, 255)
+ [/gdscript]
+ [csharp]
+ var color = new Color(0.3f, 0.4f, 0.9f);
+ Color contrastedColor = color.Contrasted(); // Equivalent to RGBA(204, 229, 102, 255)
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="darkened">
@@ -129,10 +180,16 @@
</argument>
<description>
Returns a new color resulting from making this color darker by the specified percentage (ratio from 0 to 1).
- [codeblock]
+ [codeblocks]
+ [gdscript]
var green = Color(0.0, 1.0, 0.0)
var darkgreen = green.darkened(0.2) # 20% darker than regular green
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ var green = new Color(0.0f, 1.0f, 0.0f);
+ Color darkgreen = green.Darkened(0.2f); // 20% darker than regular green
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="from_hsv">
@@ -148,9 +205,14 @@
</argument>
<description>
Constructs a color from an HSV profile. [code]h[/code], [code]s[/code], and [code]v[/code] are values between 0 and 1.
- [codeblock]
- var c = Color.from_hsv(0.58, 0.5, 0.79, 0.8) # Equivalent to HSV(210, 50, 79, 0.8) or Color8(100, 151, 201, 0.8)
- [/codeblock]
+ [codeblocks]
+ [gdscript]
+ var color = Color.from_hsv(0.58, 0.5, 0.79, 0.8) # Equivalent to HSV(210, 50, 79, 0.8) or Color8(100, 151, 201, 0.8)
+ [/gdscript]
+ [csharp]
+ Color color = Color.FromHsv(0.58f, 0.5f, 0.79f, 0.8f); // Equivalent to HSV(210, 50, 79, 0.8) or Color8(100, 151, 201, 0.8)
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="inverted">
@@ -158,10 +220,16 @@
</return>
<description>
Returns the inverted color [code](1 - r, 1 - g, 1 - b, a)[/code].
- [codeblock]
- var c = Color(0.3, 0.4, 0.9)
- var inverted_color = c.inverted() # A color of an RGBA(178, 153, 26, 255)
- [/codeblock]
+ [codeblocks]
+ [gdscript]
+ var color = Color(0.3, 0.4, 0.9)
+ var inverted_color = color.inverted() # A color of an RGBA(178, 153, 26, 255)
+ [/gdscript]
+ [csharp]
+ var color = new Color(0.3f, 0.4f, 0.9f);
+ Color invertedColor = color.Inverted(); // A color of an RGBA(178, 153, 26, 255)
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="is_equal_approx">
@@ -182,11 +250,18 @@
</argument>
<description>
Returns the linear interpolation with another color. The interpolation factor [code]t[/code] is between 0 and 1.
- [codeblock]
+ [codeblocks]
+ [gdscript]
var c1 = Color(1.0, 0.0, 0.0)
var c2 = Color(0.0, 1.0, 0.0)
- var li_c = c1.lerp(c2, 0.5) # A color of an RGBA(128, 128, 0, 255)
- [/codeblock]
+ var lerp_color = c1.lerp(c2, 0.5) # A color of an RGBA(128, 128, 0, 255)
+ [/gdscript]
+ [csharp]
+ var c1 = new Color(1.0f, 0.0f, 0.0f);
+ var c2 = new Color(0.0f, 1.0f, 0.0f);
+ Color lerpColor = c1.Lerp(c2, 0.5f); // A color of an RGBA(128, 128, 0, 255)
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="lightened">
@@ -196,10 +271,16 @@
</argument>
<description>
Returns a new color resulting from making this color lighter by the specified percentage (ratio from 0 to 1).
- [codeblock]
+ [codeblocks]
+ [gdscript]
var green = Color(0.0, 1.0, 0.0)
var lightgreen = green.lightened(0.2) # 20% lighter than regular green
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ var green = new Color(0.0f, 1.0f, 0.0f);
+ Color lightgreen = green.Lightened(0.2f); // 20% lighter than regular green
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="to_abgr32">
@@ -207,10 +288,16 @@
</return>
<description>
Returns the color's 32-bit integer in ABGR format (each byte represents a component of the ABGR profile). ABGR is the reversed version of the default format.
- [codeblock]
- var c = Color(1, 0.5, 0.2)
- print(c.to_abgr32()) # Prints 4281565439
- [/codeblock]
+ [codeblocks]
+ [gdscript]
+ var color = Color(1, 0.5, 0.2)
+ print(color.to_abgr32()) # Prints 4281565439
+ [/gdscript]
+ [csharp]
+ var color = new Color(1.0f, 0.5f, 0.2f);
+ GD.Print(color.ToAbgr32()); // Prints 4281565439
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="to_abgr64">
@@ -218,10 +305,16 @@
</return>
<description>
Returns the color's 64-bit integer in ABGR format (each word represents a component of the ABGR profile). ABGR is the reversed version of the default format.
- [codeblock]
- var c = Color(1, 0.5, 0.2)
- print(c.to_abgr64()) # Prints -225178692812801
- [/codeblock]
+ [codeblocks]
+ [gdscript]
+ var color = Color(1, 0.5, 0.2)
+ print(color.to_abgr64()) # Prints -225178692812801
+ [/gdscript]
+ [csharp]
+ var color = new Color(1.0f, 0.5f, 0.2f);
+ GD.Print(color.ToAbgr64()); // Prints -225178692812801
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="to_argb32">
@@ -229,10 +322,16 @@
</return>
<description>
Returns the color's 32-bit integer in ARGB format (each byte represents a component of the ARGB profile). ARGB is more compatible with DirectX.
- [codeblock]
- var c = Color(1, 0.5, 0.2)
- print(c.to_argb32()) # Prints 4294934323
- [/codeblock]
+ [codeblocks]
+ [gdscript]
+ var color = Color(1, 0.5, 0.2)
+ print(color.to_argb32()) # Prints 4294934323
+ [/gdscript]
+ [csharp]
+ var color = new Color(1.0f, 0.5f, 0.2f);
+ GD.Print(color.ToArgb32()); // Prints 4294934323
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="to_argb64">
@@ -240,10 +339,16 @@
</return>
<description>
Returns the color's 64-bit integer in ARGB format (each word represents a component of the ARGB profile). ARGB is more compatible with DirectX.
- [codeblock]
- var c = Color(1, 0.5, 0.2)
- print(c.to_argb64()) # Prints -2147470541
- [/codeblock]
+ [codeblocks]
+ [gdscript]
+ var color = Color(1, 0.5, 0.2)
+ print(color.to_argb64()) # Prints -2147470541
+ [/gdscript]
+ [csharp]
+ var color = new Color(1.0f, 0.5f, 0.2f);
+ GD.Print(color.ToArgb64()); // Prints -2147470541
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="to_html">
@@ -254,11 +359,18 @@
<description>
Returns the color's HTML hexadecimal color string in RGBA format (ex: [code]ff34f822[/code]).
Setting [code]with_alpha[/code] to [code]false[/code] excludes alpha from the hexadecimal string (and uses RGB instead of RGBA format).
- [codeblock]
- var c = Color(1, 1, 1, 0.5)
- var s1 = c.to_html() # Returns "ffffff7f"
- var s2 = c.to_html(false) # Returns "ffffff"
- [/codeblock]
+ [codeblocks]
+ [gdscript]
+ var color = Color(1, 1, 1, 0.5)
+ var with_alpha = color.to_html() # Returns "ffffff7f"
+ var without_alpha = color.to_html(false) # Returns "ffffff"
+ [/gdscript]
+ [csharp]
+ var color = new Color(1, 1, 1, 0.5f);
+ String withAlpha = color.ToHtml(); // Returns "ffffff7f"
+ String withoutAlpha = color.ToHtml(false); // Returns "ffffff"
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="to_rgba32">
@@ -266,10 +378,16 @@
</return>
<description>
Returns the color's 32-bit integer in RGBA format (each byte represents a component of the RGBA profile). RGBA is Godot's default format.
- [codeblock]
- var c = Color(1, 0.5, 0.2)
- print(c.to_rgba32()) # Prints 4286526463
- [/codeblock]
+ [codeblocks]
+ [gdscript]
+ var color = Color(1, 0.5, 0.2)
+ print(color.to_rgba32()) # Prints 4286526463
+ [/gdscript]
+ [csharp]
+ var color = new Color(1, 0.5f, 0.2f);
+ GD.Print(color.ToRgba32()); // Prints 4286526463
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="to_rgba64">
@@ -277,10 +395,16 @@
</return>
<description>
Returns the color's 64-bit integer in RGBA format (each word represents a component of the RGBA profile). RGBA is Godot's default format.
- [codeblock]
- var c = Color(1, 0.5, 0.2)
- print(c.to_rgba64()) # Prints -140736629309441
- [/codeblock]
+ [codeblocks]
+ [gdscript]
+ var color = Color(1, 0.5, 0.2)
+ print(color.to_rgba64()) # Prints -140736629309441
+ [/gdscript]
+ [csharp]
+ var color = new Color(1, 0.5f, 0.2f);
+ GD.Print(color.ToRgba64()); // Prints -140736629309441
+ [/csharp]
+ [/codeblocks]
</description>
</method>
</methods>
diff --git a/doc/classes/ColorRect.xml b/doc/classes/ColorRect.xml
index 92f42b6dd3..9bfcf5071d 100644
--- a/doc/classes/ColorRect.xml
+++ b/doc/classes/ColorRect.xml
@@ -13,9 +13,14 @@
<members>
<member name="color" type="Color" setter="set_frame_color" getter="get_frame_color" default="Color( 1, 1, 1, 1 )">
The fill color.
- [codeblock]
+ [codeblocks]
+ [gdscript]
$ColorRect.color = Color(1, 0, 0, 1) # Set ColorRect's color to red.
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ GetNode&lt;ColorRect&gt;("ColorRect").Color = new Color(1, 0, 0, 1); // Set ColorRect's color to red.
+ [/csharp]
+ [/codeblocks]
</member>
</members>
<constants>
diff --git a/doc/classes/ConfigFile.xml b/doc/classes/ConfigFile.xml
index 522d484131..da17d993e3 100644
--- a/doc/classes/ConfigFile.xml
+++ b/doc/classes/ConfigFile.xml
@@ -13,7 +13,8 @@
[/codeblock]
The stored data can be saved to or parsed from a file, though ConfigFile objects can also be used directly without accessing the filesystem.
The following example shows how to parse an INI-style file from the system, read its contents and store new values in it:
- [codeblock]
+ [codeblocks]
+ [gdscript]
var config = ConfigFile.new()
var err = config.load("user://settings.cfg")
if err == OK: # If not, something went wrong with the file loading
@@ -24,7 +25,24 @@
config.set_value("audio", "mute", false)
# Save the changes by overwriting the previous file
config.save("user://settings.cfg")
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ var config = new ConfigFile();
+ Error err = config.Load("user://settings.cfg");
+ if (err == Error.Ok) // If not, something went wrong with the file loading
+ {
+ // Look for the display/width pair, and default to 1024 if missing
+ int screenWidth = (int)config.GetValue("display", "width", 1024);
+ // Store a variable if and only if it hasn't been defined yet
+ if (!config.HasSectionKey("audio", "mute"))
+ {
+ config.SetValue("audio", "mute", false);
+ }
+ // Save the changes by overwriting the previous file
+ config.Save("user://settings.cfg");
+ }
+ [/csharp]
+ [/codeblocks]
Keep in mind that section and property names can't contain spaces. Anything after a space will be ignored on save and on load.
ConfigFiles can also contain manually written comment lines starting with a semicolon ([code];[/code]). Those lines will be ignored when parsing the file. Note that comments will be lost when saving the ConfigFile. This can still be useful for dedicated server configuration files, which are typically never overwritten without explicit user action.
</description>
diff --git a/doc/classes/ConfirmationDialog.xml b/doc/classes/ConfirmationDialog.xml
index 6d5871508b..a850afdd9f 100644
--- a/doc/classes/ConfirmationDialog.xml
+++ b/doc/classes/ConfirmationDialog.xml
@@ -6,9 +6,14 @@
<description>
Dialog for confirmation of actions. This dialog inherits from [AcceptDialog], but has by default an OK and Cancel button (in host OS order).
To get cancel action, you can use:
- [codeblock]
+ [codeblocks]
+ [gdscript]
get_cancel().connect("pressed", self, "cancelled")
- [/codeblock].
+ [/gdscript]
+ [csharp]
+ GetCancel().Connect("pressed", this, nameof(Cancelled));
+ [/csharp]
+ [/codeblocks]
</description>
<tutorials>
</tutorials>
diff --git a/doc/classes/Control.xml b/doc/classes/Control.xml
index c8e37d7d7b..bb00ac33bf 100644
--- a/doc/classes/Control.xml
+++ b/doc/classes/Control.xml
@@ -44,12 +44,27 @@
<description>
Virtual method to be implemented by the user. Use this method to process and accept inputs on UI elements. See [method accept_event].
Example: clicking a control.
- [codeblock]
+ [codeblocks]
+ [gdscript]
func _gui_input(event):
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT and event.pressed:
print("I've been clicked D:")
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ public override void _GuiInput(InputEvent @event)
+ {
+ if (@event is InputEventMouseButton)
+ {
+ var mb = @event as InputEventMouseButton;
+ if (mb.ButtonIndex == (int)ButtonList.Left &amp;&amp; mb.Pressed)
+ {
+ GD.Print("I've been clicked D:");
+ }
+ }
+ }
+ [/csharp]
+ [/codeblocks]
The event won't trigger if:
* clicking outside the control (see [method has_point]);
* control has [member mouse_filter] set to [constant MOUSE_FILTER_IGNORE];
@@ -68,19 +83,39 @@
The returned node must be of type [Control] or Control-derieved. It can have child nodes of any type. It is freed when the tooltip disappears, so make sure you always provide a new instance, not e.g. a node from scene. When [code]null[/code] or non-Control node is returned, the default tooltip will be used instead.
[b]Note:[/b] The tooltip is shrunk to minimal size. If you want to ensure it's fully visible, you might want to set its [member rect_min_size] to some non-zero value.
Example of usage with custom-constructed node:
- [codeblock]
+ [codeblocks]
+ [gdscript]
func _make_custom_tooltip(for_text):
var label = Label.new()
label.text = for_text
return label
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ public override Godot.Object _MakeCustomTooltip(String forText)
+ {
+ var label = new Label();
+ label.Text = forText;
+ return label;
+ }
+ [/csharp]
+ [/codeblocks]
Example of usage with custom scene instance:
- [codeblock]
+ [codeblocks]
+ [gdscript]
func _make_custom_tooltip(for_text):
var tooltip = preload("SomeTooltipScene.tscn").instance()
tooltip.get_node("Label").text = for_text
return tooltip
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ public override Godot.Object _MakeCustomTooltip(String forText)
+ {
+ Node tooltip = ResourceLoader.Load&lt;PackedScene&gt;("SomeTooltipScene.tscn").Instance();
+ tooltip.GetNode&lt;Label&gt;("Label").Text = forText;
+ return tooltip;
+ }
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="accept_event">
@@ -101,14 +136,22 @@
Overrides the [Color] with given [code]name[/code] in the [member theme] resource the control uses.
[b]Note:[/b] Unlike other theme overrides, there is no way to undo a color override without manually assigning the previous color.
[b]Example of overriding a label's color and resetting it later:[/b]
- [codeblock]
+ [codeblocks]
+ [gdscript]
# Override the child node "MyLabel"'s font color to orange.
$MyLabel.add_theme_color_override("font_color", Color(1, 0.5, 0))
-
# Reset the color by creating a new node to get the default value:
var default_label_color = Label.new().get_theme_color("font_color")
$MyLabel.add_theme_color_override("font_color", default_label_color)
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ // Override the child node "MyLabel"'s font color to orange.
+ GetNode&lt;Label&gt;("MyLabel").AddThemeColorOverride("font_color", new Color(1, 0.5f, 0));
+ // Reset the color by creating a new node to get the default value:
+ var defaultLabelColor = new Label().GetThemeColor("font_color");
+ GetNode&lt;Label&gt;("MyLabel").AddThemeColorOverride("font_color", defaultLabelColor);
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="add_theme_constant_override">
@@ -165,7 +208,8 @@
<description>
Overrides the [StyleBox] with given [code]name[/code] in the [member theme] resource the control uses. If [code]stylebox[/code] is empty or invalid, the override is cleared and the [StyleBox] from assigned [Theme] is used.
[b]Example of modifying a property in a StyleBox by duplicating it:[/b]
- [codeblock]
+ [codeblocks]
+ [gdscript]
# The snippet below assumes the child node MyButton has a StyleBoxFlat assigned.
# Resources are shared across instances, so we need to duplicate it
# to avoid modifying the appearance of all other buttons.
@@ -173,10 +217,21 @@
new_stylebox_normal.border_width_top = 3
new_stylebox_normal.border_color = Color(0, 1, 0.5)
$MyButton.add_theme_stylebox_override("normal", new_stylebox_normal)
-
# Remove the stylebox override:
$MyButton.add_theme_stylebox_override("normal", null)
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ // The snippet below assumes the child node MyButton has a StyleBoxFlat assigned.
+ // Resources are shared across instances, so we need to duplicate it
+ // to avoid modifying the appearance of all other buttons.
+ StyleBoxFlat newStyleboxNormal = GetNode&lt;Button&gt;("MyButton").GetThemeStylebox("normal").Duplicate() as StyleBoxFlat;
+ newStyleboxNormal.BorderWidthTop = 3;
+ newStyleboxNormal.BorderColor = new Color(0, 1, 0.5f);
+ GetNode&lt;Button&gt;("MyButton").AddThemeStyleboxOverride("normal", newStyleboxNormal);
+ // Remove the stylebox override:
+ GetNode&lt;Button&gt;("MyButton").AddThemeStyleboxOverride("normal", null);
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="can_drop_data" qualifiers="virtual">
@@ -189,12 +244,22 @@
<description>
Godot calls this method to test if [code]data[/code] from a control's [method get_drag_data] can be dropped at [code]position[/code]. [code]position[/code] is local to this control.
This method should only be used to test the data. Process the data in [method drop_data].
- [codeblock]
+ [codeblocks]
+ [gdscript]
func can_drop_data(position, data):
# Check position if it is relevant to you
# Otherwise, just check data
return typeof(data) == TYPE_DICTIONARY and data.has("expected")
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ public override bool CanDropData(Vector2 position, object data)
+ {
+ // Check position if it is relevant to you
+ // Otherwise, just check data
+ return data is Godot.Collections.Dictionary &amp;&amp; (data as Godot.Collections.Dictionary).Contains("expected");
+ }
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="drop_data" qualifiers="virtual">
@@ -206,13 +271,24 @@
</argument>
<description>
Godot calls this method to pass you the [code]data[/code] from a control's [method get_drag_data] result. Godot first calls [method can_drop_data] to test if [code]data[/code] is allowed to drop at [code]position[/code] where [code]position[/code] is local to this control.
- [codeblock]
+ [codeblocks]
+ [gdscript]
func can_drop_data(position, data):
return typeof(data) == TYPE_DICTIONARY and data.has("color")
-
func drop_data(position, data):
- color = data["color"]
- [/codeblock]
+ var color = data["color"]
+ [/gdscript]
+ [csharp]
+ public override bool CanDropData(Vector2 position, object data)
+ {
+ return data is Godot.Collections.Dictionary &amp;&amp; (data as Godot.Collections.Dictionary).Contains("color");
+ }
+ public override void DropData(Vector2 position, object data)
+ {
+ Color color = (Color)(data as Godot.Collections.Dictionary)["color"];
+ }
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="force_drag">
@@ -267,12 +343,22 @@
<description>
Godot calls this method to get data that can be dragged and dropped onto controls that expect drop data. Returns [code]null[/code] if there is no data to drag. Controls that want to receive drop data should implement [method can_drop_data] and [method drop_data]. [code]position[/code] is local to this control. Drag may be forced with [method force_drag].
A preview that will follow the mouse that should represent the data can be set with [method set_drag_preview]. A good time to set the preview is in this method.
- [codeblock]
+ [codeblocks]
+ [gdscript]
func get_drag_data(position):
- var mydata = make_data()
- set_drag_preview(make_preview(mydata))
+ var mydata = make_data() # This is your custom method generating the drag data.
+ set_drag_preview(make_preview(mydata)) # This is your custom method generating the preview of the drag data.
return mydata
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ public override object GetDragData(Vector2 position)
+ {
+ object mydata = MakeData(); // This is your custom method generating the drag data.
+ SetDragPreview(MakePreview(mydata)); // This is your custom method generating the preview of the drag data.
+ return mydata;
+ }
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="get_end" qualifiers="const">
@@ -358,10 +444,18 @@
</argument>
<description>
Returns a color from assigned [Theme] with given [code]name[/code] and associated with [Control] of given [code]type[/code].
- [codeblock]
+ [codeblocks]
+ [gdscript]
func _ready():
modulate = get_theme_color("font_color", "Button") #get the color defined for button fonts
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ public override void _Ready()
+ {
+ Modulate = GetThemeColor("font_color", "Button"); //get the color defined for button fonts
+ }
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="get_theme_constant" qualifiers="const">
@@ -422,10 +516,18 @@
</return>
<description>
Creates an [InputEventMouseButton] that attempts to click the control. If the event is received, the control acquires focus.
- [codeblock]
+ [codeblocks]
+ [gdscript]
func _process(delta):
grab_click_focus() #when clicking another Control node, this node will be clicked instead
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ public override void _Process(float delta)
+ {
+ GrabClickFocus(); //when clicking another Control node, this node will be clicked instead
+ }
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="grab_focus">
@@ -652,24 +754,61 @@
Forwarding can be implemented in the target control similar to the methods [method get_drag_data], [method can_drop_data], and [method drop_data] but with two differences:
1. The function name must be suffixed with [b]_fw[/b]
2. The function must take an extra argument that is the control doing the forwarding
- [codeblock]
+ [codeblocks]
+ [gdscript]
# ThisControl.gd
extends Control
+ export(Control) var target_control
+
func _ready():
set_drag_forwarding(target_control)
# TargetControl.gd
extends Control
+
func can_drop_data_fw(position, data, from_control):
return true
func drop_data_fw(position, data, from_control):
- my_handle_data(data)
+ my_handle_data(data) # Your handler method.
func get_drag_data_fw(position, from_control):
set_drag_preview(my_preview)
return my_data()
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ // ThisControl.cs
+ public class ThisControl : Control
+ {
+ [Export]
+ public Control TargetControl { get; set; }
+ public override void _Ready()
+ {
+ SetDragForwarding(TargetControl);
+ }
+ }
+
+ // TargetControl.cs
+ public class TargetControl : Control
+ {
+ public void CanDropDataFw(Vector2 position, object data, Control fromControl)
+ {
+ return true;
+ }
+
+ public void DropDataFw(Vector2 position, object data, Control fromControl)
+ {
+ MyHandleData(data); // Your handler method.
+ }
+
+ public void GetDragDataFw(Vector2 position, Control fromControl)
+ {
+ SetDragPreview(MyPreview);
+ return MyData();
+ }
+ }
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="set_drag_preview">
@@ -679,7 +818,8 @@
</argument>
<description>
Shows the given control at the mouse pointer. A good time to call this method is in [method get_drag_data]. The control must not be in the scene tree.
- [codeblock]
+ [codeblocks]
+ [gdscript]
export (Color, RGBA) var color = Color(1, 0, 0, 1)
func get_drag_data(position):
@@ -689,7 +829,22 @@
cpb.rect_size = Vector2(50, 50)
set_drag_preview(cpb)
return color
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ [Export]
+ public Color Color = new Color(1, 0, 0, 1);
+
+ public override object GetDragData(Vector2 position)
+ {
+ // Use a control that is not in the tree
+ var cpb = new ColorPickerButton();
+ cpb.Color = Color;
+ cpb.RectSize = new Vector2(50, 50);
+ SetDragPreview(cpb);
+ return Color;
+ }
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="set_end">
diff --git a/doc/classes/Crypto.xml b/doc/classes/Crypto.xml
index 4edb3eda0a..b3bbbae94f 100644
--- a/doc/classes/Crypto.xml
+++ b/doc/classes/Crypto.xml
@@ -6,13 +6,12 @@
<description>
The Crypto class allows you to access some more advanced cryptographic functionalities in Godot.
For now, this includes generating cryptographically secure random bytes, RSA keys and self-signed X509 certificates generation, asymmetric key encryption/decryption, and signing/verification.
- [codeblock]
+ [codeblocks]
+ [gdscript]
extends Node
-
var crypto = Crypto.new()
var key = CryptoKey.new()
var cert = X509Certificate.new()
-
func _ready():
# Generate new RSA key.
key = crypto.generate_rsa(4096)
@@ -33,7 +32,42 @@
# Checks
assert(verified)
assert(data.to_utf8() == decrypted)
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ using Godot;
+ using System;
+ using System.Diagnostics;
+
+ public class CryptoNode : Node
+ {
+ public Crypto Crypto = new Crypto();
+ public CryptoKey Key = new CryptoKey();
+ public X509Certificate Cert = new X509Certificate();
+ public override void _Ready()
+ {
+ // Generate new RSA key.
+ Key = Crypto.GenerateRsa(4096);
+ // Generate new self-signed certificate with the given key.
+ Cert = Crypto.GenerateSelfSignedCertificate(Key, "CN=mydomain.com,O=My Game Company,C=IT");
+ // Save key and certificate in the user folder.
+ Key.Save("user://generated.key");
+ Cert.Save("user://generated.crt");
+ // Encryption
+ string data = "Some data";
+ byte[] encrypted = Crypto.Encrypt(Key, data.ToUTF8());
+ // Decryption
+ byte[] decrypted = Crypto.Decrypt(Key, encrypted);
+ // Signing
+ byte[] signature = Crypto.Sign(HashingContext.HashType.Sha256, Data.SHA256Buffer(), Key);
+ // Verifying
+ bool verified = Crypto.Verify(HashingContext.HashType.Sha256, Data.SHA256Buffer(), signature, Key);
+ // Checks
+ Debug.Assert(verified);
+ Debug.Assert(data.ToUTF8() == decrypted);
+ }
+ }
+ [/csharp]
+ [/codeblocks]
[b]Note:[/b] Not available in HTML5 exports.
</description>
<tutorials>
@@ -95,13 +129,22 @@
<description>
Generates a self-signed [X509Certificate] from the given [CryptoKey] and [code]issuer_name[/code]. The certificate validity will be defined by [code]not_before[/code] and [code]not_after[/code] (first valid date and last valid date). The [code]issuer_name[/code] must contain at least "CN=" (common name, i.e. the domain name), "O=" (organization, i.e. your company name), "C=" (country, i.e. 2 lettered ISO-3166 code of the country the organization is based in).
A small example to generate an RSA key and a X509 self-signed certificate.
- [codeblock]
+ [codeblocks]
+ [gdscript]
var crypto = Crypto.new()
# Generate 4096 bits RSA key.
var key = crypto.generate_rsa(4096)
# Generate self-signed certificate using the given key.
var cert = crypto.generate_self_signed_certificate(key, "CN=example.com,O=A Game Company,C=IT")
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ var crypto = new Crypto();
+ // Generate 4096 bits RSA key.
+ CryptoKey key = crypto.GenerateRsa(4096);
+ // Generate self-signed certificate using the given key.
+ X509Certificate cert = crypto.GenerateSelfSignedCertificate(key, "CN=mydomain.com,O=My Game Company,C=IT");
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="sign">
diff --git a/doc/classes/Sprite3D.xml b/doc/classes/Sprite3D.xml
index 934471c445..f9b947fa3d 100644
--- a/doc/classes/Sprite3D.xml
+++ b/doc/classes/Sprite3D.xml
@@ -4,8 +4,7 @@
2D sprite node in a 3D world.
</brief_description>
<description>
- A node that displays a 2D texture in a 3D environment. The texture displayed can be a region from a larger atlas texture, or a frame from a sprite sheet animation.
- [b]Note:[/b] There are [url=https://github.com/godotengine/godot/issues/20855]known performance issues[/url] when using [Sprite3D]. Consider using a [MeshInstance3D] with a [QuadMesh] as the mesh instead. You can still have billboarding by enabling billboard properties in the QuadMesh's [StandardMaterial3D].
+ A node that displays a 2D texture in a 3D environment. The texture displayed can be a region from a larger atlas texture, or a frame from a sprite sheet animation. See also [SpriteBase3D] where properties such as the billboard mode are defined.
</description>
<tutorials>
</tutorials>
diff --git a/doc/classes/SpriteBase3D.xml b/doc/classes/SpriteBase3D.xml
index 479dc5f94c..44b08408c1 100644
--- a/doc/classes/SpriteBase3D.xml
+++ b/doc/classes/SpriteBase3D.xml
@@ -4,7 +4,7 @@
2D sprite node in 3D environment.
</brief_description>
<description>
- A node that displays 2D texture information in a 3D environment.
+ A node that displays 2D texture information in a 3D environment. See also [Sprite3D] where many other properties are defined.
</description>
<tutorials>
</tutorials>
@@ -13,6 +13,7 @@
<return type="TriangleMesh">
</return>
<description>
+ Returns a [TriangleMesh] with the sprite's vertices following its current configuration (such as its [member axis] and [member pixel_size]).
</description>
</method>
<method name="get_draw_flag" qualifiers="const">
@@ -39,17 +40,19 @@
<argument index="1" name="enabled" type="bool">
</argument>
<description>
- If [code]true[/code], the specified flag will be enabled.
+ If [code]true[/code], the specified flag will be enabled. See [enum SpriteBase3D.DrawFlags] for a list of flags.
</description>
</method>
</methods>
<members>
<member name="alpha_cut" type="int" setter="set_alpha_cut_mode" getter="get_alpha_cut_mode" enum="SpriteBase3D.AlphaCutMode" default="0">
+ The alpha cutting mode to use for the sprite. See [enum AlphaCutMode] for possible values.
</member>
<member name="axis" type="int" setter="set_axis" getter="get_axis" enum="Vector3.Axis" default="2">
The direction in which the front of the texture faces.
</member>
<member name="billboard" type="int" setter="set_billboard_mode" getter="get_billboard_mode" enum="BaseMaterial3D.BillboardMode" default="0">
+ The billboard mode to use for the sprite. See [enum BaseMaterial3D.BillboardMode] for possible values.
</member>
<member name="centered" type="bool" setter="set_centered" getter="is_centered" default="true">
If [code]true[/code], texture will be centered.
@@ -90,16 +93,19 @@
If set, lights in the environment affect the sprite.
</constant>
<constant name="FLAG_DOUBLE_SIDED" value="2" enum="DrawFlags">
- If set, texture can be seen from the back as well, if not, it is invisible when looking at it from behind.
+ If set, texture can be seen from the back as well. If not, the texture is invisible when looking at it from behind.
</constant>
<constant name="FLAG_MAX" value="3" enum="DrawFlags">
Represents the size of the [enum DrawFlags] enum.
</constant>
<constant name="ALPHA_CUT_DISABLED" value="0" enum="AlphaCutMode">
+ This mode performs standard alpha blending. It can display translucent areas, but transparency sorting issues may be visible when multiple transparent materials are overlapping.
</constant>
<constant name="ALPHA_CUT_DISCARD" value="1" enum="AlphaCutMode">
+ This mode only allows fully transparent or fully opaque pixels. Harsh edges will be visible unless some form of screen-space antialiasing is enabled (see [member ProjectSettings.rendering/quality/screen_filters/screen_space_aa]). On the bright side, this mode doesn't suffer from transparency sorting issues when multiple transparent materials are overlapping. This mode is also known as [i]alpha testing[/i] or [i]1-bit transparency[/i].
</constant>
<constant name="ALPHA_CUT_OPAQUE_PREPASS" value="2" enum="AlphaCutMode">
+ This mode draws fully opaque pixels in the depth prepass. This is slower than [constant ALPHA_CUT_DISABLED] or [constant ALPHA_CUT_DISCARD], but it allows displaying translucent areas and smooth edges while using proper sorting.
</constant>
</constants>
</class>
diff --git a/doc/classes/bool.xml b/doc/classes/bool.xml
index 869fc14d40..ce4d000a9b 100644
--- a/doc/classes/bool.xml
+++ b/doc/classes/bool.xml
@@ -6,36 +6,87 @@
<description>
Boolean is a built-in type. There are two boolean values: [code]true[/code] and [code]false[/code]. You can think of it as an switch with on or off (1 or 0) setting. Booleans are used in programming for logic in condition statements, like [code]if[/code] statements.
Booleans can be directly used in [code]if[/code] statements. The code below demonstrates this on the [code]if can_shoot:[/code] line. You don't need to use [code]== true[/code], you only need [code]if can_shoot:[/code]. Similarly, use [code]if not can_shoot:[/code] rather than [code]== false[/code].
- [codeblock]
- var can_shoot = true
+ [codeblocks]
+ [gdscript]
+ var _can_shoot = true
func shoot():
- if can_shoot:
+ if _can_shoot:
pass # Perform shooting actions here.
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ private bool _canShoot = true;
+
+ public void Shoot()
+ {
+ if (_canShoot)
+ {
+ // Perform shooting actions here.
+ }
+ }
+ [/csharp]
+ [/codeblocks]
The following code will only create a bullet if both conditions are met: action "shoot" is pressed and if [code]can_shoot[/code] is [code]true[/code].
[b]Note:[/b] [code]Input.is_action_pressed("shoot")[/code] is also a boolean that is [code]true[/code] when "shoot" is pressed and [code]false[/code] when "shoot" isn't pressed.
- [codeblock]
- var can_shoot = true
+ [codeblocks]
+ [gdscript]
+ var _can_shoot = true
func shoot():
- if can_shoot and Input.is_action_pressed("shoot"):
+ if _can_shoot and Input.is_action_pressed("shoot"):
create_bullet()
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ private bool _canShoot = true;
+
+ public void Shoot()
+ {
+ if (_canShoot &amp;&amp; Input.IsActionPressed("shoot"))
+ {
+ CreateBullet();
+ }
+ }
+ [/csharp]
+ [/codeblocks]
The following code will set [code]can_shoot[/code] to [code]false[/code] and start a timer. This will prevent player from shooting until the timer runs out. Next [code]can_shoot[/code] will be set to [code]true[/code] again allowing player to shoot once again.
- [codeblock]
- var can_shoot = true
- onready var cool_down = $CoolDownTimer
+ [gdscript]
+ var _can_shoot = true
+ onready var _cool_down = $CoolDownTimer
func shoot():
- if can_shoot and Input.is_action_pressed("shoot"):
+ if _can_shoot and Input.is_action_pressed("shoot"):
create_bullet()
- can_shoot = false
- cool_down.start()
+ _can_shoot = false
+ _cool_down.start()
func _on_CoolDownTimer_timeout():
- can_shoot = true
- [/codeblock]
+ _can_shoot = true
+ [/gdscript]
+ [csharp]
+ private bool _canShoot = true;
+ private Timer _coolDown;
+
+ public override void _Ready()
+ {
+ _coolDown = GetNode&lt;Timer&gt;("CoolDownTimer");
+ }
+
+ public void Shoot()
+ {
+ if (_canShoot &amp;&amp; Input.IsActionPressed("shoot"))
+ {
+ CreateBullet();
+ _canShoot = false;
+ _coolDown.Start();
+ }
+ }
+
+ public void OnCoolDownTimerTimeout()
+ {
+ _canShoot = true;
+ }
+ [/csharp]
+ [/codeblocks]
</description>
<tutorials>
</tutorials>