From 19fccc0bd5ca5a16dfa95bd5db9a8f86fa68c911 Mon Sep 17 00:00:00 2001 From: Raul Santos Date: Wed, 12 Jul 2023 16:02:45 +0200 Subject: [PATCH 1/2] C#: Fix instancing_with_signals tutorial --- tutorials/scripting/instancing_with_signals.rst | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tutorials/scripting/instancing_with_signals.rst b/tutorials/scripting/instancing_with_signals.rst index c28f1d01fab..fe24a304df3 100644 --- a/tutorials/scripting/instancing_with_signals.rst +++ b/tutorials/scripting/instancing_with_signals.rst @@ -41,7 +41,7 @@ given velocity: public partial class Bullet : Area2D { - Vector2 Velocity = new Vector2(); + public Vector2 Velocity { get; set; } = Vector2.Zero; public override void _PhysicsProcess(double delta) { @@ -111,7 +111,7 @@ Here is the code for the player using signals to emit the bullet: public partial class Player : Sprite2D { [Signal] - delegate void ShootEventHandler(PackedScene bullet, Vector2 direction, Vector2 location); + public delegate void ShootEventHandler(PackedScene bullet, float direction, Vector2 location); private PackedScene _bullet = GD.Load("res://bullet.tscn"); @@ -147,13 +147,13 @@ In the main scene, we then connect the player's signal (it will appear in the .. code-tab:: csharp - public void OnPlayerShoot(PackedScene bullet, Vector2 direction, Vector2 location) + private void OnPlayerShoot(PackedScene bullet, float direction, Vector2 location) { - var bulletInstance = (Bullet)bullet.Instantiate(); - AddChild(bulletInstance); - bulletInstance.Rotation = direction; - bulletInstance.Position = location; - bulletInstance.Velocity = bulletInstance.Velocity.Rotated(direction); + var spawnedBullet = (Bullet)bullet.Instantiate(); + AddChild(spawnedBullet); + spawnedBullet.Rotation = direction; + spawnedBullet.Position = location; + spawnedBullet.Velocity = spawnedBullet.Velocity.Rotated(direction); } Now the bullets will maintain their own movement independent of the player's From d9e888744ec51194fa0545dcab6a138d00d53860 Mon Sep 17 00:00:00 2001 From: Raul Santos Date: Thu, 13 Jul 2023 12:17:19 +0200 Subject: [PATCH 2/2] Update tutorials/scripting/instancing_with_signals.rst Co-authored-by: Paul Joannon <437025+paulloz@users.noreply.github.com> --- tutorials/scripting/instancing_with_signals.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/scripting/instancing_with_signals.rst b/tutorials/scripting/instancing_with_signals.rst index fe24a304df3..40054f2d684 100644 --- a/tutorials/scripting/instancing_with_signals.rst +++ b/tutorials/scripting/instancing_with_signals.rst @@ -149,7 +149,7 @@ In the main scene, we then connect the player's signal (it will appear in the private void OnPlayerShoot(PackedScene bullet, float direction, Vector2 location) { - var spawnedBullet = (Bullet)bullet.Instantiate(); + var spawnedBullet = bullet.Instantiate(); AddChild(spawnedBullet); spawnedBullet.Rotation = direction; spawnedBullet.Position = location;