Update some C# examples for 4.0 (#6693)

* Update some C# examples

- Rename members that have been renamed in Godot's C# API for 4.0.
- Change `delta` parameter type to `double`.
- Ensure parameters match base declaration.
- Other minor code fixes.

---------

Co-authored-by: Paul Joannon <437025+paulloz@users.noreply.github.com>
This commit is contained in:
Raul Santos
2023-02-04 17:03:03 +01:00
committed by GitHub
co-authored by Paul Joannon
parent d6b4fe8ab9
commit b319da3f07
30 changed files with 236 additions and 219 deletions
@@ -90,7 +90,7 @@ Here is how a ``_process()`` function might look for you:
.. code-tab:: csharp
public override void _Process(float delta)
public override void _Process(double delta)
{
if (Engine.IsEditorHint())
{
@@ -133,9 +133,9 @@ and open a script, and change it to this:
[Tool]
public partial class MySprite : Sprite2D
{
public override void _Process(float delta)
public override void _Process(double delta)
{
Rotation += Mathf.Pi * delta;
Rotation += Mathf.Pi * (float)delta;
}
}
@@ -162,15 +162,15 @@ look like this:
.. code-tab:: csharp
public override void _Process(float delta)
public override void _Process(double delta)
{
if (Engine.IsEditorHint())
{
Rotation += Mathf.Pi * delta;
Rotation += Mathf.Pi * (float)delta;
}
else
{
Rotation -= Mathf.Pi * delta;
Rotation -= Mathf.Pi * (float)delta;
}
}
@@ -208,24 +208,23 @@ Add and export a variable speed to the script. The function set_speed after
[Tool]
public partial class MySprite : Sprite2D
{
private float speed = 1;
private float _speed = 1;
[Export]
public float Speed {
get => speed;
set => SetSpeed(value);
public float Speed
{
get => _speed;
set
{
// Update speed and reset the rotation.
_speed = value;
Rotation = 0;
}
}
// Update speed and reset the rotation.
private void SetSpeed(float newSpeed)
public override void _Process(double delta)
{
speed = newSpeed;
Rotation = 0;
}
public override void _Process(float delta)
{
Rotation += Mathf.Pi * delta * speed;
Rotation += Mathf.Pi * (float)delta * speed;
}
}