Threads with Key Bindings

前端 未结 2 1179
名媛妹妹
名媛妹妹 2020-11-22 16:29

I\'m new to Java graphics and threads, and I\'m trying to make a game (specifically, Pong). The idea is that two people can play on the same keyboard (i.e. there are two pad

2条回答
  •  抹茶落季
    2020-11-22 17:27

    This may be a legitimate use case for the low-level access afforded to a KeyListener. See How to Write a Key Listener and KeyEventDemo; don't forget to requestFocusInWindow(). Also consider offering keyboard control for one player and mouse control for the other.

    Addendum: @David Kroukamp has adduced an appealing counter-example using key bindings. For reference, the example cited here illustrates one approach to managing key preferences.

提交回复
热议问题