用键移动BufferedImage [英] Move BufferedImage with Keys

查看:61
本文介绍了用键移动BufferedImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在2D游戏中有一张背景图片,我想知道如何使用按键移动该图片?我正在尝试类似的事情:

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;

但是那不能用,因为getX()不适用于BufferedImages.

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

我该怎么做?

推荐答案

您将需要两件事.

  1. 您将需要知道图像的位置.一个简单的Point对象就足够了.告诉您在哪里绘制图像...
  2. 一些可以捕捉关键董事会事件的地方.为此,我建议键绑定API ,因为它确实如此不会遇到与KeyListener
  3. 相同的问题
  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

这篇关于用键移动BufferedImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆