帆布的InputMap [英] Canvas and InputMap

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

问题描述

我要建在Java中的2D游戏,我决定使用画布上,我将​​显示相关的当前帧图像。我使用的画布,因为我听说它是​​在时间超过的JPanel方面会更有效率。是真的吗?

I'm building a 2d game in Java and I decided to use Canvas on which I would display the images relevant to the current frame. I'm using Canvas because I've heard it is more efficient in terms of time than JPanel. Is it true?

另外,我想通过键绑定,因为关键的听众可能导致重点问题和较低级别的结构在一定的输入加入到游戏中:<一href=\"http://stackoverflow.com/questions/8074316/keylistener-not-working-after-clicking-button\">keylistener点击按钮后没有工作(见的答案)。
有没有办法使用的键绑定用帆布的方法吗?或者,我会简单地使用的KeyListener。

Also, I would like to add some input to the game through key bindings since key listeners could cause focus issues and are lower level construct: keylistener not working after clicking button (see answer). Is there a way to use key bindings with a Canvas? Or I would simply use KeyListener.

推荐答案


  • 您不能添加键盘绑定awt.Canvas,没有在API实现的方法

  • you can't add KeyBindings to awt.Canvas, there isn't method implemented in API

    您可以只添加的KeyListener

    you can to add only KeyListener

    改变你的决定,使用的JPanel / JComponent的

    change your decision and to use JPanel/JComponent

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

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