HaxeFlixel / flixel

Free, cross-platform 2D game engine powered by Haxe and OpenFL
https://haxeflixel.com/
MIT License
1.98k stars 439 forks source link

FlxG.Keys not registering after first #275

Closed igrowbeards closed 11 years ago

igrowbeards commented 11 years ago

I'm using a macbook pro and FlxG.keys.pressed("A") work exactly one time but will not work again. This is without pressing any other keys at all so i don't think it's an example of keyboard locking. I've been able to duplicate this behavior on my machine on both the official relase and the dev branch of haxeflixel. I unfortunately don't have access to any other hardware to see if it's unique to my setup somehow.

Since the A key is char code 65 i am thinking it might be an off by one error somewhere in https://github.com/Beeblerox/HaxeFlixel/blob/flixelNME/src/org/flixel/system/input/FlxKeyboard.hx but so far i've been unable to track it down.

Beeblerox commented 11 years ago

@igrowbeards can you post your project? i'm asking about this since i don't have such problem on windows. and by the way, on which target do you have this issue?

Beeblerox commented 11 years ago

@igrowbeards and i forgot to ask you about your NME and HXCPP versions

AndreiRegiani commented 11 years ago

Same problem on Linux (haven't tested on win or mac)

Letters ("A"..."Z") doesn't work at all, but special keys does. ("UP", "DOWN", "SPACE", ...)

On Flash it all works fine.

On Mar 25, 2013, at 12:31 AM, Justin Edwards notifications@github.com wrote:

I'm using a macbook pro and FlxG.keys.pressed("A") work exactly one time but will not work again. This is without pressing any other keys at all so i don't think it's an example of keyboard locking. I've been able to duplicate this behavior on my machine on both the official relase and the dev branch of haxeflixel. I unfortunately don't have access to any other hardware to see if it's unique to my setup somehow.

Since the A key is char code 65 i am thinking it might be an off by one error somewhere in https://github.com/Beeblerox/HaxeFlixel/blob/flixelNME/src/org/flixel/system/input/FlxKeyboard.hx but so far i've been unable to track it down.

— Reply to this email directly or view it on GitHub.

Beeblerox commented 11 years ago

@AndreiRegiani what versions of NME, HXCPP and HaxeFlixel do you use?

igrowbeards commented 11 years ago

I've uploaded a demo here https://github.com/igrowbeards/flixel_keys_issue

I'm having trouble on both flash (A key only) and cpp (no keys work at all not even once). I normally only build for flash so i didn't realize there were extra problems for CPP until this morning.

I'm using NME Command-Line Tools (3.5.5), and hxcpp version 3.0.0.

AndreiRegiani commented 11 years ago

I just tested this issue more deeply. Demo: https://dl.dropbox.com/u/8217321/TilemapDemoMove.zip

How it handles input: (arrows and wasd)

right = FlxG.keys.pressed("D") || FlxG.keys.pressed("RIGHT"); left = FlxG.keys.pressed("A") || FlxG.keys.pressed("LEFT"); up = FlxG.keys.pressed("W") || FlxG.keys.pressed("UP"); down = FlxG.keys.pressed("S") || FlxG.keys.pressed("DOWN");

HaxeFlixel: dev branch (also tested with release version and same results) HXCPP: 2.10.3 NME: 3.5.5


Platform: Flash Player 11.2 (Linux) both input WORKS.

Platform: Linux 32-bit (Ubuntu 12.10 / lastest) ONLY arrow keys works. "WASD" not even once.

Platform: Mac OS X - Lion (10.7.4) ONLY arrow keys works. "WASD" not even once.

igrowbeards commented 11 years ago

Also, after a bit more testing i can confirm that most keys don't work on mac target, special keys seem to be OK. During my testing (i.e. mashing buttons), i discovered a weird quirk - FlxG.keys.pressed("R") returns true when i press the Q key on mac. Something Fishy is going on.

Beeblerox commented 11 years ago

@igrowbeards @AndreiRegiani that is very strange. i'm on windows and using HXCPP 2.10.3, NME 3.5.5 and HaxeFlixel 1.09 (from haxelib) and don't have such problems. Maybe this is NME specific bug? I'll try to ask guys on forum.

AndreiRegiani commented 11 years ago

There are no problem on Windows and Flash, this issue only occurs on Mac and Linux. I will leave this reference of another Keyboard class made for NME, the current implementation seems to be very similar anyways: http://www.willhawthorne.com/tutorials/haxe/haxeKeyboard.php

Just in case somebody can notice any difference. (yet I haven't tested that implementation)

AndreiRegiani commented 11 years ago

UPDATE: That another implementation also DOESN'T work... it's also based on Flixel. I'm not sure if the problem is with NME or how Flixel is implementing this.

Beeblerox commented 11 years ago

@AndreiRegiani i think that this issue is connected with changes in last official version of NME - they told that they've fixed keycodes for all platforms (keys should return the same keycodes across all platforms). but as i can see now they did it only for windows. or maybe i'm wrong. anyway, i'll post here class with old keycodes and will ask you to test it on mac and linux. ok?

AndreiRegiani commented 11 years ago

Okay! Waiting for it.

On Mar 25, 2013, at 3:44 PM, Zaphod notifications@github.com wrote:

@AndreiRegiani i think that this issue is connected with changes in last official version of NME - they told that they've fixed keycodes for all platforms (keys should return the same keycodes across all platforms). but as i can see now they did it only for windows. or maybe i'm wrong. anyway, i'll post here class with old keycodes and will ask you to test it on mac and linux. ok?

— Reply to this email directly or view it on GitHub.

bradparks commented 11 years ago

hey! just to let you know, I tested the demo above on my MacBook pro, and noticed that it works for NEKO, but doesn't work for CPP builds on my mac. So WASD work on Neko, but not on a Mac build, for what it's worth....

PS: I'm using the following: nme: [3.5.5] hxcpp: [3.0.0] flixel: [dev:/Users/Brad/haxedemos/HaxeFlixel/src]

Beeblerox commented 11 years ago

here is the link to modified FlxKeyboard class: https://dl.dropbox.com/u/17106142/FlxKeyboard.hx copy it over in your haxelib folder and add these two lines to your nmml-file:

<set name="mac" if="mac" />
<set name="linux" if="linux" />

Please try it and tell me if it work for you

bradparks commented 11 years ago

hey! i tested this and it doesn't seem to fix it.... i added a trace to the FlxKeyboard.hx on where it does the "addKey" stuff for letters, and here's what it dumped out.

FlxKeyboard.hx:118: i:65, i+32:97, key:A FlxKeyboard.hx:118: i:66, i+32:98, key:B FlxKeyboard.hx:118: i:67, i+32:99, key:C FlxKeyboard.hx:118: i:68, i+32:100, key:D FlxKeyboard.hx:118: i:69, i+32:101, key:E FlxKeyboard.hx:118: i:70, i+32:102, key:F FlxKeyboard.hx:118: i:71, i+32:103, key:G FlxKeyboard.hx:118: i:72, i+32:104, key:H FlxKeyboard.hx:118: i:73, i+32:105, key:I FlxKeyboard.hx:118: i:74, i+32:106, key:J FlxKeyboard.hx:118: i:75, i+32:107, key:K FlxKeyboard.hx:118: i:76, i+32:108, key:L FlxKeyboard.hx:118: i:77, i+32:109, key:M FlxKeyboard.hx:118: i:78, i+32:110, key:N FlxKeyboard.hx:118: i:79, i+32:111, key:O FlxKeyboard.hx:118: i:80, i+32:112, key:P FlxKeyboard.hx:118: i:81, i+32:113, key:Q FlxKeyboard.hx:118: i:82, i+32:114, key:R FlxKeyboard.hx:118: i:83, i+32:115, key:S FlxKeyboard.hx:118: i:84, i+32:116, key:T FlxKeyboard.hx:118: i:85, i+32:117, key:U FlxKeyboard.hx:118: i:86, i+32:118, key:V FlxKeyboard.hx:118: i:87, i+32:119, key:W FlxKeyboard.hx:118: i:88, i+32:120, key:X FlxKeyboard.hx:118: i:89, i+32:121, key:Y FlxKeyboard.hx:118: i:90, i+32:122, key:Z

igrowbeards commented 11 years ago

Same results as @bradparks

AndreiRegiani commented 11 years ago

@Beeblerox @bradparks It's working for me now: https://dl.dropbox.com/u/21553459/FlxKeyboard.hx

Changes:

//LETTERS i = 65; while (i <= 90) {

if (mac || linux)

addKey(String.fromCharCode(i - 1), i - 1);
i++;
#else
addKey(String.fromCharCode(i), i++);
#end

}

I've tested on Linux, Mac and Flash. @bradparks can you test it?

Beeblerox commented 11 years ago

@AndreiRegiani so you want to tell that on mac and linux keycodes and charcodes for letters are shifted by 1?

AndreiRegiani commented 11 years ago

@Beeblerox Don't ask me why! it's very strange.

'A' is returning '65' on Mac/Linux, same as Windows/Flash, so it's not actually shifted by 1, but I don't know why I had to decrease by one each code..

Maybe we're fixing a NME bug that will soon be fixed by them, then HaxeFlixel won't work.

Beeblerox commented 11 years ago

@AndreiRegiani I think that it should be posted about on NME forum. Will you do that?

AndreiRegiani commented 11 years ago

@Beeblerox I will, before I'm trying to understand what's going on, because adding keys manually like this, also works: addKey("A", 65);

So, theoretically there are not problem with NME, the keycodes are correct. It's something with that while loop...

Beeblerox commented 11 years ago

@AndreiRegiani and what about other letters, for example "C": addKey("C", 67) ?

bradparks commented 11 years ago

The problem is just that i++ is screwing it up. This works for me for both Neko and Mac on my MacBook Pro:

while (i <= 90)
  {
    addKey(String.fromCharCode(i), i);
    i=i+1;
  }
Beeblerox commented 11 years ago

@bradparks ok. i'll change it. So, probably problem is in hxcpp or in compilers

AndreiRegiani commented 11 years ago

@Beeblerox All keys work when added manually. So, it's definitively not a NME bug.

Where should this issue be reported? I also think it's hxcpp/compiler bug with ++ increment, if so this is huge, it affects all Haxe projects running on Linux/Mac.

Beeblerox commented 11 years ago

@AndreiRegiani I think that it should be reported on NME forum in Bugs section. But we need to write the most simple test which would show the problem. Maybe something like this:

var i:Int = 65;
while (i <= 90)
{
    traceValues(String.fromCharCode(i), i++);
}

private function traceValues(char:String, i:Int):Void
{
    trace("code for " + char + " is " + i);
}
igrowbeards commented 11 years ago

Hey guys great work on the general keys bug - working like a charm!

However the original issue I reported is still unresolved.

Namely on flash + mac the "A" key (specifically this key and as far as i can tell ONLY this key) only registers as pressed the first time. After the first release it will not register as pressed again. Using the code from ccf6f01 it works fine on mac now but still has the same problem in flash.

I'm on mac OSX 10.8.2 with NME 3.5.5 and hxcpp 3.0.0.

The original demo i posted still illustrates this problem with the newest code: https://github.com/igrowbeards/flixel_keys_issue

AndreiRegiani commented 11 years ago

@igrowbeards I tested your own .swf you compiled in that demo, and the 'A' key is responding as many times as I pressed, this means nothing is wrong with your compiler/binary. The problem seems to be with your Flash Player. I'm also on OSX, Flash Player 11.6. What version do you have installed?

EDIT: solved, no need to test If anyone else can test his SWF (inform OS and Flash version): https://github.com/igrowbeards/flixel_keys_issue/raw/master/export/flash/bin/keys-bug.swf (press ~ to open console and test 'A' key)

igrowbeards commented 11 years ago

@AndreiRegiani you are totally right. I normally test in flash pro cs5 just because that's what the comiler launches - when i open the swf in flash player it works as expected. Still strange but at least not a crippling problem for publishing :)

Thanks for the help!

AndreiRegiani commented 11 years ago

@igrowbeards Ahh you were using Flash CS5 Player? Just check "Control -> Disable Keyboard Shortcuts" in the player window, it have some shortcuts assigned to keys like 'A', this is what was preventing your keys to work. Your CS5 embed player is perfectly normal.

igrowbeards commented 11 years ago

Hey guys thanks for the help, and glad my "bug" that wasn't really a bug helped to fix another that actually was. I just noticed this issue is still open so i guess i am supposed to close it? Trying to see.