Diagonal movement of a sprite

后端 未结 2 1502
太阳男子
太阳男子 2021-01-17 00:15

How can I implement diagonal movement to a sprite? I created a movable sprite (a rectangle), which moves in four directions.

To animate the rectangle, a timer objec

2条回答
  •  醉梦人生
    2021-01-17 00:44

    Don't use a KeyListener. Swing was designed to be used with Key Bindings.

    Check out Motion Using the Keyboard for more information and a complete solution that uses Key Bindings.

提交回复
热议问题