mirror of
https://github.com/stan220/godot-docs.git
synced 2026-09-08 19:29:06 +00:00
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:
co-authored by
Paul Joannon
parent
d6b4fe8ab9
commit
b319da3f07
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user