Skip to content
This repository was archived by the owner on Sep 15, 2024. It is now read-only.

Commit afbe879

Browse files
make use of Godot.Timer
1 parent ebf5ffc commit afbe879

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

Scripts/Scenes/Game/ClientPlayer.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
using Timer = System.Timers.Timer;
2-
31
using ENet;
42
using Godot;
53
using GodotModules;
64
using GodotModules.Netcode;
75
using GodotModules.Netcode.Client;
8-
using System.Timers;
96
using System.Threading.Tasks;
107

118
namespace Game
@@ -16,7 +13,6 @@ public class ClientPlayer : OtherPlayer
1613
private Label LabelPosition { get; set; }
1714

1815
private float Speed = 250f;
19-
public static Timer EmitPosition { get; set; }
2016

2117
public override void _Ready()
2218
{
@@ -26,14 +22,15 @@ public override void _Ready()
2622

2723
if (GameClient.Running)
2824
{
29-
EmitPosition = new(1000);
30-
EmitPosition.Elapsed += EmitPositionCallback;
31-
EmitPosition.AutoReset = true;
32-
EmitPosition.Enabled = true;
25+
var timer = new Timer();
26+
timer.Connect("timeout", this, nameof(EmitPosition));
27+
timer.OneShot = false;
28+
timer.Autostart = true;
29+
AddChild(timer);
3330
}
3431
}
3532

36-
public async void EmitPositionCallback(System.Object source, ElapsedEventArgs args)
33+
public async void EmitPosition()
3734
{
3835
await GameClient.Send(ClientPacketOpcode.PlayerPosition, new CPacketPlayerPosition {
3936
Position = Position

0 commit comments

Comments
 (0)