Home
Blog
Tutorials
Work
Resume
Blog
Keyboard Class  William Hawthorne - February 28th, 2012

Got a lot done in programming my game framework today. Working from Flixel as an example, I created several classes for keeping track of Keyboard states. The code does not translate directly from Actionscript 3 to HaXe. I had to use a Hash table, and the syntax for that is different in HaXe. There was also a part where Flixel uses an implied class. I think the same would have been possible in HaXe, but I opted to create an extra class instead. HaXe is more geared toward strict typing, and I felt the extra clarification was called for.

I ran into some significant bugs when I started compiling the code using NME. The flash target was working fine, but I kept running into issues when I compiled for Windows. In particular, the letter keys wouldn't seem to respond as expected. After a little trial-and-error, I discovered that the Keyboard EventListener for the Windows target was returning different integer key codes for the letter keys than the flash target. Also, I found that the key codes for the letter keys in the Windows target overlapped with the key codes for the function keys and number pad keys. For the time being, I've disabled the function and number pad keys, and added conditionals so that the Windows and flash targets behave identically. There's nothing much I can do about the disparity in the key codes for now. It probably has something to do with how NME uses SDL for it's C++ rendering back-end.

Despite some of the problems that I ran into, I'm quite pleased with getting the Keyboard class working. As it's based on an open-source project, and fairly modular in nature, I'll probably cook up a programming tutorial for it tomorrow. It would be a good start for my Tutorials section.

EMail
Google+
LinkedIn
Facebook
© 2008 - 2017 William Hawthorne