如何使按键不暂停? [英] how to make key press not pause?

查看:100
本文介绍了如何使按键不暂停?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我正在为学校制作2D侧滚动游戏.这几乎和Mario一样(嗯,这是我完成时的希望.)当我按向右箭头键在地图上移动我的玩家时,他会移动一次,暂停,然后开始平稳地移动很多.我认为这是因为按下键时所有Apple笔记本电脑都处于暂停状态,但是我不知道该如何解决我的游戏问题.有什么建议吗?谢谢你.

Okay, so I am making a 2D side scroller game for school. It is pretty much just like Mario (well, that is my hope for when I finish.) When I press the right arrow key to move my player along the map, he moves once, pauses, and then begins to smoothly move a lot. I think this is because of the pause that is in all apple laptops when you hold a key down, but I do not know how to get around this for my game. Any advice? Thank you.

推荐答案

尽管您尚未发送任何代码段,但我可以假设以下内容.我认为您已经实现了按键监听器,该监听器在按下按键时会执行某些操作.如果用户仍然按下该键,则您的程序会在延迟一段时间后获取第二个事件,然后开始更快地获取事件.

Although you have not sent any code snippet I can assume the following. I think that you have implemented key listener that does something when key is pressed. If user remains pressing the key your program gets the second event after some delay and then starts getting the events faster.

这不是您所需要的.您可能应该保留某种应用程序状态keyIsPressed,该状态在第一次按下(未按下)键时仅更改一次.然后仅在按下键时关闭此变量.第一次按下键时,启动后台线程,该线程将移动您的对象并定期检查标志keyIsPressed以知道何时停止.

This is not what you need. You probably should hold some kind of application state keyIsPressed that is changed only once when the key is down (not pressed) first time. Then turn this variable off only when key is up. When key is down first time start background thread that moves your object and checks the flag keyIsPressed periodically to know when to stop.

祝你成为Mario的竞争对手...:)

Good luck to become a competitor of Mario... :)

这篇关于如何使按键不暂停?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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