diff --git a/getting_started/first_2d_game/01.project_setup.rst b/getting_started/first_2d_game/01.project_setup.rst index 9c2f3ae8225..78c3e42f8f5 100644 --- a/getting_started/first_2d_game/01.project_setup.rst +++ b/getting_started/first_2d_game/01.project_setup.rst @@ -25,7 +25,7 @@ Launch Godot and create a new project. and ``fonts/`` directories to your project's directory. Ensure that you have the required dependencies to use C# in Godot. - You need the .NET Core 3.1 SDK, and an editor such as VS Code. + You need the latest stable .NET SDK, and an editor such as VS Code. See :ref:`doc_c_sharp_setup`. .. tab:: C++ diff --git a/getting_started/first_2d_game/03.coding_the_player.rst b/getting_started/first_2d_game/03.coding_the_player.rst index aaa40d951d2..8c003d10145 100644 --- a/getting_started/first_2d_game/03.coding_the_player.rst +++ b/getting_started/first_2d_game/03.coding_the_player.rst @@ -89,11 +89,18 @@ node and you'll see the property now appears in the "Script Variables" section of the Inspector. Remember, if you change the value here, it will override the value written in the script. -.. warning:: If you're using C#, you need to (re)build the project assemblies - whenever you want to see new export variables or signals. This - build can be manually triggered by clicking the word "Mono" at the - bottom of the editor window to reveal the Mono Panel, then clicking - the "Build Project" button. +.. warning:: + + If you're using C#, you need to (re)build the project assemblies + whenever you want to see new export variables or signals. This + build can be manually triggered by clicking the "Build" button at + the top right of the editor. + + .. image:: img/build_dotnet.webp + + A manual build can also be triggered from the MSBuild Panel. Click + the word "MSBuild" at the bottom of the editor window to reveal the + MSBuild Panel, then click the "Build" button. .. image:: img/export_variable.webp @@ -390,7 +397,7 @@ movement. Let's place this code at the end of the ``_process()`` function: .. code-tab:: csharp - if (velocity.x < 0) + if (velocity.X < 0) { animatedSprite2D.FlipH = true; } @@ -490,12 +497,12 @@ this code to the function: .. code-tab:: csharp - public void OnBodyEntered(PhysicsBody2D body) + private void OnBodyEntered(PhysicsBody2D body) { Hide(); // Player disappears after being hit. EmitSignal(SignalName.Hit); // Must be deferred as we can't change physics properties on a physics callback. - GetNode("CollisionShape2D").SetDeferred("disabled", true); + GetNode("CollisionShape2D").SetDeferred(CollisionShape2D.PropertyName.Disabled, true); } .. code-tab:: cpp @@ -530,9 +537,9 @@ starting a new game. .. code-tab:: csharp - public void Start(Vector2 pos) + public void Start(Vector2 position) { - Position = pos; + Position = position; Show(); GetNode("CollisionShape2D").Disabled = false; } diff --git a/getting_started/first_2d_game/04.creating_the_enemy.rst b/getting_started/first_2d_game/04.creating_the_enemy.rst index 57c88d7bdd2..f5c8d5c1473 100644 --- a/getting_started/first_2d_game/04.creating_the_enemy.rst +++ b/getting_started/first_2d_game/04.creating_the_enemy.rst @@ -108,18 +108,16 @@ and randomly choose one of the three animation types: .. code-tab:: gdscript GDScript func _ready(): - $AnimatedSprite2D.play() - var mob_types = $AnimatedSprite2D.get_sprite_frames().get_animation_names() - $AnimatedSprite2D.animation = mob_types[randi() % mob_types.size()] + var mob_types = $AnimatedSprite2D.sprite_frames.get_animation_names() + $AnimatedSprite2D.play(mob_types[randi() % mob_types.size()]) .. code-tab:: csharp public override void _Ready() { - var animSprite2D = GetNode("AnimatedSprite2D"); - animSprite2D.Play(); - string[] mobTypes = animSprite2D.SpriteFrames.GetAnimationNames(); - animSprite2D.Animation = mobTypes[GD.Randi() % mobTypes.Length]; + var animatedSprite2D = GetNode("AnimatedSprite2D"); + string[] mobTypes = animatedSprite2D.SpriteFrames.GetAnimationNames(); + animatedSprite2D.Play(mobTypes[GD.Randi() % mobTypes.Length]); } .. code-tab:: cpp @@ -132,7 +130,6 @@ and randomly choose one of the three animation types: void Mob::_ready() { godot::Ref random = godot::RandomNumberGenerator::_new(); - random->randomize(); _animated_sprite = get_node("AnimatedSprite2D"); _animated_sprite->set_playing(true); godot::PoolStringArray mob_types = _animated_sprite->get_sprite_frames()->get_animation_names(); @@ -147,10 +144,6 @@ We then need to pick a random number between ``0`` and ``2`` to select one of these names from the list (array indices start at ``0``). ``randi() % n`` selects a random integer between ``0`` and ``n-1``. -.. note:: You must use ``randomize()`` if you want your sequence of "random" - numbers to be different every time you run the scene. We're going to - use ``randomize()`` in our ``Main`` scene, so we won't need it here. - The last piece is to make the mobs delete themselves when they leave the screen. Connect the ``screen_exited()`` signal of the ``VisibleOnScreenNotifier2D`` node and add this code: @@ -163,7 +156,7 @@ add this code: .. code-tab:: csharp - public void OnVisibleOnScreenNotifier2DScreenExited() + private void OnVisibleOnScreenNotifier2DScreenExited() { QueueFree(); } diff --git a/getting_started/first_2d_game/05.the_main_game_scene.rst b/getting_started/first_2d_game/05.the_main_game_scene.rst index d999ed95bb4..be2e85f1479 100644 --- a/getting_started/first_2d_game/05.the_main_game_scene.rst +++ b/getting_started/first_2d_game/05.the_main_game_scene.rst @@ -93,13 +93,10 @@ to instance. { // Don't forget to rebuild the project so the editor knows about the new export variable. - #pragma warning disable 649 - // We assign this in the editor, so we don't need the warning about not being assigned. [Export] - public PackedScene MobScene; - #pragma warning restore 649 + public PackedScene MobScene { get; set; } - public int Score; + private int _score; } .. code-tab:: cpp @@ -219,7 +216,7 @@ new game: public void NewGame() { - Score = 0; + _score = 0; var player = GetNode("Player"); var startPosition = GetNode("StartPosition"); @@ -258,12 +255,12 @@ the other two timers. ``ScoreTimer`` will increment the score by 1. .. code-tab:: csharp - public void OnScoreTimerTimeout() + private void OnScoreTimerTimeout() { - Score++; + _score++; } - public void OnStartTimerTimeout() + private void OnStartTimerTimeout() { GetNode("MobTimer").Start(); GetNode("ScoreTimer").Start(); @@ -332,14 +329,14 @@ Note that a new instance must be added to the scene using ``add_child()``. .. code-tab:: csharp - public void OnMobTimerTimeout() + private void OnMobTimerTimeout() { // Note: Normally it is best to use explicit types rather than the `var` // keyword. However, var is acceptable to use here because the types are // obviously Mob and PathFollow2D, since they appear later on the line. // Create a new instance of the Mob scene. - var mob = MobScene.Instantiate(); + Mob mob = MobScene.Instantiate(); // Choose a random location on Path2D. var mobSpawnLocation = GetNode("MobPath/MobSpawnLocation"); diff --git a/getting_started/first_2d_game/06.heads_up_display.rst b/getting_started/first_2d_game/06.heads_up_display.rst index 75250eb8f22..0266cd4e07d 100644 --- a/getting_started/first_2d_game/06.heads_up_display.rst +++ b/getting_started/first_2d_game/06.heads_up_display.rst @@ -233,13 +233,13 @@ We also need to process what happens when the player loses. The code below will ShowMessage("Game Over"); var messageTimer = GetNode("MessageTimer"); - await ToSignal(messageTimer, "timeout"); + await ToSignal(messageTimer, Timer.SignalName.Timeout); var message = GetNode