FNA and SDL Events
I've been poking away at the new version of Otter which will be using FNA instead of SFML. At first I thought it would be super easy and cool to use the XNA "state" systems for input. Stuff like KeyboardState, MouseState, etc. The problem with this though is that at lower framerates this way of detecting input can totally miss inputs.
I couldn't find any examples on how to plug into FNA's SDL event loop, but I eventually stumbled into something that worked. All I knew was that I had to use SDL_AddEventWatch. So here's a quick example on how to use SDL events with FNA:
I added this code in the Initialize method of Game, and I'm now getting my own key up and down events. Eventually this will be hooked into my input classes and I should have the same input functionality that SFML Otter has.
I couldn't find any examples on how to plug into FNA's SDL event loop, but I eventually stumbled into something that worked. All I knew was that I had to use SDL_AddEventWatch. So here's a quick example on how to use SDL events with FNA:
SDL_AddEventWatch((data, ev) => {
var sdlEvent = (SDL_Event)System.Runtime.InteropServices.Marshal.PtrToStructure(ev, typeof(SDL_Event));
switch(sdlEvent.type) {
case SDL_EventType.SDL_KEYDOWN:
Console.WriteLine("keydown: {0}", sdlEvent.key.keysym.sym);
break;
case SDL_EventType.SDL_KEYUP:
Console.WriteLine("keyup: {0}", sdlEvent.key.keysym.sym);
break;
}
return 0;
}, IntPtr.Zero);
Post your comment!