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
parent d6b4fe8ab9
commit b319da3f07
30 changed files with 236 additions and 219 deletions

View File

@@ -104,7 +104,9 @@ way:
.. code-tab:: csharp
var localPos = new Vector2(10,20); // local to Control/Node2D
var ie = new InputEventMouseButton();
ie.ButtonIndex = (int)ButtonList.Left;
ie.Position = (GetViewportTransform() * GetGlobalTransform()).Xform(localPos);
var ie = new InputEventMouseButton()
{
ButtonIndex = MouseButton.Left,
Position = GetViewportTransform() * (GetGlobalTransform() * localPos),
};
GetTree().InputEvent(ie);

View File

@@ -84,7 +84,7 @@ redrawn if modified:
using Godot;
public partial class CustomNode2D : Node2D
public partial class MyNode2D : Node2D
{
private Texture _texture;
public Texture Texture
@@ -133,7 +133,7 @@ call ``queue_redraw()`` from the ``_process()`` callback, like this:
// Your draw commands here
}
public override void _Process(float delta)
public override void _Process(double delta)
{
QueueRedraw();
}
@@ -387,7 +387,7 @@ using ``get_node()``.
using Godot;
public partial class CustomNode2D : Node2D
public partial class MyNode2D : Node2D
{
private float _rotationAngle = 50;
private float _angleFrom = 75;
@@ -421,7 +421,7 @@ calls ``_draw()``. This way, you can control when you want to refresh the frame.
.. code-tab:: csharp
public override void _Process(float delta)
public override void _Process(double delta)
{
_angleFrom += _rotationAngle;
_angleTo += _rotationAngle;
@@ -490,10 +490,10 @@ smaller value, which directly depends on the rendering speed.
.. code-tab:: csharp
public override void _Process(float delta)
public override void _Process(double delta)
{
_angleFrom += _rotationAngle * delta;
_angleTo += _rotationAngle * delta;
_angleFrom += _rotationAngle * (float)delta;
_angleTo += _rotationAngle * (float)delta;
// We only wrap angles when both of them are bigger than 360.
if (_angleFrom > 360 && _angleTo > 360)