I have started new project in VS2017 sfml.net with simple test of subscribing for MouseMove and MouseButtonPressed. Here are key files:
using SFML.Graphics;using SFML.Window;using System;using UnforgottenRealms.Core.Input;using UnforgottenRealms.Window;namespace UnforgottenRealms
{ class Program
{ static void Main
(string[] args
) { var settings
= new ContextSettings
{ AntialiasingLevel
= 8 }; var window
= new GameWindow
(new VideoMode
(640,
480), settings
); var inputProcessor
= new InputProcessor
(window,
1); inputProcessor
.Layers[0].Handles.Add(new Test
(0,
100)); inputProcessor
.Layers[0].Handles.Add(new Test
(500,
600)); while (window
.IsOpen()) { window
.DispatchEvents(); window
.Clear(new Color
(100,
100,
200)); window
.Display(); } } class Test
: InputHandle
{ private int x, y
; public Test
(int x,
int y
) { this.x = x
; this.y = y
; } public override bool ContainsMouse
(int x,
int y
) { return (x
> this.x && x
< this.y); } public override void Trigger
() { Console
.WriteLine("Triggered!"); } } }} using SFML.Graphics;using SFML.Window;using System.Threading.Tasks;namespace UnforgottenRealms
.Core.Input{ public class InputProcessor
{ public LayerCollection Layers
{ get; } private RenderWindow window
; public InputProcessor
(RenderWindow window,
int layersCount
= 0) { this.window = window
; Layers
= new LayerCollection
(layersCount
); window
.MouseButtonPressed += ProcessMouseButtonPress
; window
.MouseMoved += ProcessMouseMovement
; } private void ProcessMouseButtonPress
(object sender, MouseButtonEventArgs e
) { } private void ProcessMouseMovement
(object sender, MouseMoveEventArgs e
) { var h
= Layers
.MatchHandle(e
.X, e
.Y); if (h
!= null) { h
.Trigger(); } } }} GameWindow derives from RenderWindow and there is nothing special about it.
I noticed that my Console.WriteLines does not trigger, after debugging with breakpoint I found out that `ProcessMouseMovement` is triggered on mouse button release and `ProcessMouseButtonPress` on mouse wheel movement. Moreover property `MouseMoveEventArgs.X` is always equal to zero.
It confuses me because I have already done some stuff in SFML.Net and I am rather familiar with it.
What do I do?
SFML.Net downloaded from NuGet and CSFML from website.