Hi all,
I would like to move shape objects within the window. Events in SFML .NET are substantially different than using C++, e.g.:
...
window.Closed += OnWindowClosed;
...
private static void OnWindowClosed(object sender, EventArgs e)
{
(sender as RenderWindow).Close();
}
That is possible since the sender object is the window itself, so you can do something with the window if you want. However, if you create a shape and you want to modify some properties when the keyboard is pressed, I don't see a clear way of doing it.
Of course, if the shape is accessible (e.g., "MyShape" as a property in the class), you can make changes in any arbitrary function:
private static void OnKeyPressed
(object sender, KeyEventArgs e
) { if (e
.Code == Keyboard
.Key.Escape) { (sender
as RenderWindow
).Close(); } if (e
.Code == Keyboard
.Key.Left) { MyShape
.Position = new Vector2f
(MyShape
.Position.X - 10, MyShape
.Position.Y); } } However, I don't like to access external variables from an event function, I would prefer to pass them as a parameter. Or you may have another suggestion.