多键检测的KeyListener(JAVA) [英] multiple key detection for KeyListener (java)

查看:169
本文介绍了多键检测的KeyListener(JAVA)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何实现的KeyListener让其中一个人使用,我可以创建一个双播放系统'。和/,以控制字符,和其他人可以用箭头键没有它们打断对方?我现在有它的方式是,当一个人按住方向键,他们的个性动作,但你使用其他玩家的控制的瞬间,第一个人的性格停止。

How would one implement KeyListener so that I can create a two-player system where one person uses '.' and '/' to control a character, and the other person can use the arrow keys without them interrupting each other? The way I have it now is that when one person holds down the arrow key, their character moves, but the instant you use the other player's controls, the first person's character stops.

推荐答案

创建一个的HashMap<诠释,布尔> 将标记哪些键是目前pressed /日pressed。

Create a HashMap<Int,Boolean> that marks which keys are currently pressed/depressed.

然后在你的游戏循环,你可以依靠,如果密钥是在这个地图pssed德$ P $移动你的对象。

Then in your game loop, you can move your objects depending on if the keys are depressed in this map.

例如:

if (keyMap.get(VK_COLON) == Boolean.TRUE) //True indicates pressed
   playerAXPos+= 10;

这篇关于多键检测的KeyListener(JAVA)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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