KeyListener vs. Key Bindings

前端 未结 2 560
离开以前
离开以前 2020-11-30 15:25

People here keep suggesting to me to use Key Binding instead of KeyListener in Java 2D games.

What are the advantages and disadvantages of each one? Is

2条回答
  •  伪装坚强ぢ
    2020-11-30 16:03

    Key bindings were introduced later. They map actions to specific keys whereas a listener simply listens for which keys are pressed. To be honest, it doesn't really matter which one you use, but it's always preferable to use key bindings.

    There are many libraries also available which have their advantages/disadvantages. Key bindings should be fine though for a 2D game. However, please note that using the Java API is not recommended for game development. If you ever want to build 3D, or content rich 2D games, it's much better to use OpenGL. Try LWJGL or JOGL (LWJGL is preferred generally) or you can use a game engine such as Slick2D or LibGDX.

提交回复
热议问题