问题
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.
- 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... - 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