Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / Trouble with button_down
- - By Jwosty Date 2011-06-24 17:15
I am making a simple game in which you try to destroy the other player (you are a UFO). Player 1 moves with W, A, S, and D, and Player 2 moves with the UP, DOWN, LEFT, and RIGHT arrow keys. Player 1 shoots with 1 and Player 2 shoots with 7. I know, it's not the best controls, but I'll figure that out later. It works for now. xP
The problem:
If both players are shooting at the same time, then neither player can move left. Here is my code:

    def move
      if button_down?(@nk)
        @y -= speed
      end
      if button_down?(@sk)
        @y += speed
      end
      if button_down?(@wk)
        @x -= speed
      end
      if button_down?(@ek)
        @x += speed
      end
    end


@ek = east key (the trouble causing button, moves left)
@nk = north key (moves up)
@sk = south key (moves down)
@wk = west key (moves right)

Two very odd things here:
• It is only with the var @ek (a completely different button for the two players)
• If I move the @ek conditional to the top of the list, I still get the same results.

Help would be much appreciated. :/
Parent - - By jlnr (dev) Date 2011-06-24 17:38
My guess is that it is not Gosu, but a keyboard problem. In usual (more economic?) keyboard hardware, only some keys can be pressed at once. In my experience, special keys like strg, alt, shift are more tolerant. If they problem goes away or changes by using other keys, you know it's that problem.

First link I found on this issue: http://xahlee.org/comp/keyboard_key_ghosting.html

Workaround: Let one player use the keyboard, buy a gamepad for the other one :)
Parent - By Jwosty Date 2011-06-24 22:38
Okay, thanks! That seems to be the answer, I just tried using the trouble-causing key combonation in a text editor, and it didn't print all the keys that were pressed. Thanks a bunch! :D
Up Topic Gosu / Gosu Exchange / Trouble with button_down

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill