Skip to content

Commit f17b236

Browse files
committed
update c# class examples
1 parent 33c6191 commit f17b236

37 files changed

+147
-124
lines changed

getting_started/first_2d_game/03.coding_the_player.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ Start by declaring the member variables this object will need:
3636
.. code-tab:: csharp
3737

3838
using Godot;
39-
using System;
4039

4140
public partial class Player : Area2D
4241
{

getting_started/first_2d_game/04.creating_the_enemy.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ Add a script to the ``Mob`` like this:
6565

6666
.. code-tab:: csharp
6767

68-
public class Mob : RigidBody2D
68+
using Godot;
69+
70+
public partial class Mob : RigidBody2D
6971
{
7072
// Don't forget to rebuild the project.
7173
}

getting_started/first_2d_game/06.heads_up_display.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ Now add this script to ``HUD``:
107107

108108
.. code-tab:: csharp
109109

110-
public class HUD : CanvasLayer
110+
using Godot;
111+
112+
public partial class HUD : CanvasLayer
111113
{
112114
// Don't forget to rebuild the project so the editor knows about the new signal.
113115

getting_started/step_by_step/signals.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ Your complete ``Sprite2D.gd`` code should look like the following.
208208

209209
using Godot;
210210

211-
public class Sprite : Godot.Sprite2D
211+
public partial class Sprite : Sprite2D
212212
{
213213
private float Speed = 400;
214214
private float AngularSpeed = Mathf.Pi;
@@ -370,7 +370,7 @@ Here is the complete ``Sprite2D.gd`` file for reference.
370370

371371
using Godot;
372372

373-
public class Sprite : Godot.Sprite2D
373+
public partial class Sprite : Sprite2D
374374
{
375375
private float Speed = 400;
376376
private float AngularSpeed = Mathf.Pi;
@@ -423,7 +423,7 @@ reaches 0.
423423

424424
using Godot;
425425

426-
public class CustomSignal : Node2D
426+
public partial class CustomSignal : Node2D
427427
{
428428
[Signal]
429429
public delegate void HealthDepletedEventHandler();
@@ -477,7 +477,7 @@ names between parentheses:
477477

478478
using Godot;
479479

480-
public class CustomSignal : Node
480+
public partial class CustomSignal : Node
481481
{
482482
[Signal]
483483
public delegate void HealthChangedEventHandler(int oldValue, int newValue);

tutorials/2d/2d_movement.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ Add a script to the character body and add the following code:
5656
.. code-tab:: csharp
5757

5858
using Godot;
59-
using System;
6059

6160
public partial class Movement : CharacterBody2D
6261
{
@@ -123,7 +122,6 @@ while up/down moves it forward or backward in whatever direction it's facing.
123122
.. code-tab:: csharp
124123

125124
using Godot;
126-
using System;
127125

128126
public partial class Movement : CharacterBody2D
129127
{
@@ -182,7 +180,6 @@ is set by the mouse position instead of the keyboard. The character will always
182180
.. code-tab:: csharp
183181

184182
using Godot;
185-
using System;
186183

187184
public partial class Movement : CharacterBody2D
188185
{
@@ -246,7 +243,6 @@ on the screen will cause the player to move to the target location.
246243
.. code-tab:: csharp
247244

248245
using Godot;
249-
using System;
250246

251247
public partial class Movement : CharacterBody2D
252248
{

tutorials/2d/2d_sprite_animation.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ released.
8888

8989
.. code-tab:: csharp
9090

91-
public class Character : CharacterBody2D
91+
using Godot;
92+
93+
public partial class Character : CharacterBody2D
9294
{
9395
private AnimatedSprite2D _animatedSprite;
9496

@@ -227,7 +229,9 @@ released.
227229

228230
.. code-tab:: csharp
229231

230-
public class Character : CharacterBody2D
232+
using Godot;
233+
234+
public partial class Character : CharacterBody2D
231235
{
232236
private AnimationPlayer _animationPlayer;
233237

tutorials/2d/custom_drawing_in_2d.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ redrawn if modified:
8282

8383
.. code-tab:: csharp
8484

85-
public class CustomNode2D : Node2D
85+
using Godot;
86+
87+
public partial class CustomNode2D : Node2D
8688
{
8789
private Texture _texture;
8890
public Texture Texture
@@ -122,7 +124,9 @@ call ``queue_redraw()`` from the ``_process()`` callback, like this:
122124

123125
.. code-tab:: csharp
124126

125-
public class CustomNode2D : Node2D
127+
using Godot;
128+
129+
public partial class CustomNode2D : Node2D
126130
{
127131
public override void _Draw()
128132
{
@@ -326,7 +330,9 @@ using ``get_node()``.
326330

327331
.. code-tab:: csharp
328332

329-
public class CustomNode2D : Node2D
333+
using Godot;
334+
335+
public partial class CustomNode2D : Node2D
330336
{
331337
private float _rotationAngle = 50;
332338
private float _angleFrom = 75;

tutorials/best_practices/data_preferences.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,10 @@ tree structures.
248248

249249
.. code-tab:: csharp
250250

251+
using Godot;
252+
251253
// Can decide whether to expose getters/setters for properties later
252-
public class TreeNode : Object
254+
public partial class TreeNode : Object
253255
{
254256
private TreeNode _parent = null;
255257

tutorials/best_practices/godot_interfaces.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,9 @@ accesses:
481481
.. code-tab:: csharp
482482

483483
// Child.cs
484-
public class Child : Node
484+
using Godot;
485+
486+
public partial class Child : Node
485487
{
486488
public FuncRef FN = null;
487489

@@ -493,7 +495,9 @@ accesses:
493495
}
494496

495497
// Parent.cs
496-
public class Parent : Node
498+
using Godot;
499+
500+
public partial class Parent : Node
497501
{
498502
public Node Child;
499503

tutorials/best_practices/godot_notifications.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ deltatime methods as needed.
113113

114114
.. code-tab:: csharp
115115

116-
public class MyNode : Node
116+
using Godot;
117+
118+
public partial class MyNode : Node
117119
{
118120

119121
// Called every frame, even when the engine detects no input.
@@ -171,7 +173,9 @@ instantiation:
171173

172174
.. code-tab:: csharp
173175

174-
public class MyNode : Node
176+
using Godot;
177+
178+
public partial class MyNode : Node
175179
{
176180
private string _test = "one";
177181

@@ -255,7 +259,9 @@ nodes that one might create at runtime.
255259

256260
.. code-tab:: csharp
257261

258-
public class MyNode : Node
262+
using Godot;
263+
264+
public partial class MyNode : Node
259265
{
260266
public Node ParentCache = null;
261267

0 commit comments

Comments
 (0)