简体   繁体   English

闪存空间密钥识别失败

[英]Flash Space Key Recognition Failure

I've been working on my platform game and I decided to create an air attack for the character. 我一直在开发平台游戏,因此决定对角色进行空中攻击。 Everything's working fine except for the fact that Flash fails to recognize that space has been pressed after holding down the up and left keys ( UP + LEFT -> SPACE ). 一切正常,除了在按住向上和向左键UP + LEFT- > SPACE )后Flash无法识别已按下空格的事实。 However, this works fine: ( UP + RIGHT -> SPACE ). 但是,这可以正常工作:( UP + RIGHT- > SPACE )。 At first I thought the problem was simply a fault in my code. 起初,我认为问题只是我的代码中的错误。 However, after carefully searching through my code carefully I came to the conclusion that the problem wasn't in the code but rather Flash itself. 但是,在仔细搜索我的代码后,我得出的结论是问题不在代码中,而是Flash本身。

Next I created a separate Flash file to test this to make sure that the fault was not in the code. 接下来,我创建了一个单独的Flash文件进行测试,以确保错误不在代码中。 I created a space bar Movie Clip and a Movie Clip for each of the arrow keys ( with instance names "space", "right", "left" etc ). 我为每个箭头键( 实例名称为“ space”,“ right”,“ left”等 )创建了一个空格键Movie Clip和一个Movie Clip。 Then I added this code to listen for key presses and releases: 然后,我添加了以下代码来监听按键和释放:

var space_pressed:Boolean = false;
var up_pressed:Boolean = false;
var down_pressed:Boolean = false;
var left_pressed:Boolean = false;
var right_pressed:Boolean = false;



stage.addEventListener(KeyboardEvent.KEY_DOWN,key_down);
function key_down(e:KeyboardEvent){
    switch(e.keyCode){
        case (38):
        up_pressed=true;
        break;
        case (40):
        down_pressed=true;
        break;
        case (37):
        left_pressed=true;
        break;
        case (39):
        right_pressed=true;
        break;
        case (32):
        space_pressed=true;
        break;
    }   
}
stage.addEventListener(KeyboardEvent.KEY_UP,key_up);
function key_up(e:KeyboardEvent){
    switch(e.keyCode){
        case (38):
        up_pressed=false;
        break;
        case(40):
        down_pressed=false;
        break;
        case(37):
        left_pressed=false;
        break;
        case(39):
        right_pressed=false;
        break;
        case (32):
        space_pressed=false;
        break;
    }   
}

stage.addEventListener(Event.ENTER_FRAME,update_visual);
function update_visual(e:Event){
    if(space_pressed){
        space.alpha=1;
    }else{
        space.alpha=.5;
    }

    if(up_pressed){
        up.alpha=1;
    }else{
        up.alpha=.5;
    }

    if(down_pressed){
        down.alpha=1;
    }else{
        down.alpha=.5;
    }

    if(left_pressed){
        left.alpha=1;
    }else{
        left.alpha=.5;
    }

    if(right_pressed){
        right.alpha=1;
    }else{
        right.alpha=.5;
    }
}

When a key is pressed the key representing it will have an alpha of 1, otherwise it will have an alpha of 0.5. 按下某个键时,代表该键的键的alpha值为1,否则它的alpha值为0.5。 And, just as I thought, after holding down the up and left keys, space would not show up. 而且,正如我所想,按住向上和向左键之后,空间将不会显示出来。 But space press is recognized after holding down the up and right keys. 但是,按住上,右键后,可以识别出空格键。

My next logical assumption was that this was simply a result of the order of the cases for my press and release key switch blocks. 我的下一个逻辑假设是,这仅仅是我按下和释放键开关块的顺序的结果。 However, after rearranging the order of these cases, I still had the same result. 但是,重新排列这些案例的顺序后,我仍然得到相同的结果。 This is a serious problem for any Flash game developer working with key presses and releases. 对于任何使用按键和释放键的Flash游戏开发人员来说,这都是一个严重的问题。 If anyone knows why this is happening or has any advise on getting around this issue, please help me out! 如果有人知道为什么会这样或对解决此问题有任何建议,请帮助我! Thanks in advance. 提前致谢。

UPDATE: I also just discovered the opposite is also true. 更新:我也刚刚发现相反的事实也是如此。 ( DOWN + RIGHT -> SPACE ) doesn't work while ( DOWN + LEFT -> SPACE ) works fine. DOWN + RIGHT- > SPACE )不起作用,而( DOWN + LEFT- > SPACE )可以正常工作。

Good news, I finally figured out the problem. 好消息,我终于弄清楚了问题所在。 It wasn't because of my code or Flash, it was because of "Keyboard Ghosting" http://www.microsoft.com/appliedsciences/antighostingexplained.mspx . 这不是因为我的代码或Flash,而是因为“键盘虚拟化” http://www.microsoft.com/appliedsciences/antighostingexplained.mspx I'm going to leave this question on the forum in case anyone else is struggling with the same problem. 如果有人遇到同样的问题,我将把这个问题留在论坛上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM