Move BufferedImage with Keys

柔情痞子 提交于 2019-12-14 03:15:11

问题


I have a background image on my 2D game, and I would like to know how I could move this image around with keys? I was trying things like:

background.getX() + 3;

But that wouldn't work as getX() isn't applicable for BufferedImages.

How can I do this?


回答1:


You're going to need two things.

  1. You're going to need to know the position of the image. A simple Point object should suffice. This tells you where to draw the image...
  2. Some where to catch key board events. For this I would suggest the key bindings API, as it does not suffer from the same issues and KeyListener


来源:https://stackoverflow.com/questions/17006929/move-bufferedimage-with-keys

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!