游戏的Silverlight按键事件 [英] Silverlight keydown event for games

查看:103
本文介绍了游戏的Silverlight按键事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Silverlight中的key down事件用于正在开发的游戏.我遇到的问题是Silverlight像Windows一样对待keydown.例如,如果按住左箭头键,则keydown事件将触发一次,然后暂停一会儿,然后再重复触发.

I'm trying to use the key down event in silverlight for a game I'm working on. The problem I'm having is that silverlight treats keydown like windows does. For example if you hold down the left arrow key the keydown event triggers once, then pauses for a short while before triggering repeatedly.

很明显,在游戏中这是不会做的,因为玩家希望能够按住键来重复操作而不会在事件中暂停.

Obviously in a game this won't do since a player expects to be able to hold a key down to repeat an action without a pause in event.

那么如何在第一个按键事件和随后的重复事件之间没有短暂停顿的情况下不断获得按键事件呢?

So how do I get key down events constantly without the brief pause between the first key down event and the following repeated events?

推荐答案

我相信它仅重复KeyDown而不重复KeyUp,因此您需要自己跟踪以前的KeyUp事件的状态以确定该密钥已经/已经被按下.

I believe it only repeats the KeyDown and not the KeyUp, so you would need to track the state of previous KeyUp events yourself to determine if the key was/is already pressed.

Silverlight中的键盘对游戏的支持不是很好(例如,不允许同时使用多个键).您确实希望能够询问是否按下了某些键(例如旧的扫描键码系统),但这不是浏览器友好的功能.

Keyboard support for games in Silverlight is not great (e.g. does not allow for multiple simultaneous keys). You really want the ability to ask if certain keys are pressed (like the old scan-keycode system), but that is not a browser-friendly thing.

这篇关于游戏的Silverlight按键事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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