InputManager可以完成一些简单的控制,但是当你要完成较复杂的控制时应使用InputMap,虽然InputManager使用较简单如下:
1.
if
(InputManager.isKeyDown(InputKey.UP))
当你有第三方设备输入(比如手柄等),当你要控制键盘和鼠标,你可以采用一种一致的方式去处理它们,这种方式就是使用InputMap,提供一个回调函数,一个输入名称,一个数字参数, Digital inputs (buttons) will be called back with 0 or 1 based on if the button is up or down.用0和1表示键盘的 起来和按下,Analog inputs (mouse) will be called back with the change in position of the input.鼠标使用位置参数。
01.
public
class
MyInputHandlingComponent
extends
TickedComponent
02.
{
03.
public
function
get input():InputMap
04.
{
05.
return
_inputMap;
06.
}
07.
08.
public
function
set input(value:InputMap):
void
09.
{
10.
_inputMap = value;
11.
12.
if
(_inputMap !=
null
)
13.
{
14.
_inputMap.addBinding(
"GoLeft"
, _onLeft);
15.
_inputMap.addBinding(
"GoRight"
, onRight);
16.
}
17.
}
18.
public
override
function
onTick(tickRate:Number):
void
19.
{
20.
21.
22.
var
direction:Number = right - left;
23.
Logger.print(
this
,
"I am moving "
+ direction);
24.
}
25.
26.
private
function
onLeft(value:Number):
void
27.
{
28.
left = value;
29.
}
30.
private
function
onRight(value:Number):
void
31.
{
32.
right = value;
33.
}
34.
35.
36.
private
var
_inputMap:InputMap;
37.
private
var
_left:Number = 0;
38.
private
var
_right:Number = 0;
39.
}
level XML做为实体一部分被启动,注意:你定义输入做为level一部分,更易于支持多人在同一个输入设备游戏
01.
<
entity
name
=
"InputHandlingEntity"
>
02.
<
component
class
=
"MyInputHandlingComponent"
name
=
"Input"
/>
03.
<
Input
>
04.
05.
<
GoLeft
>LEFT</
GoLeft
>
06.
<
GoRight
>RIGHT</
GoRight
>
07.
</
Input
>
08.
</
component
>
09.
</
entity
>
鼠标绑定:
1.
<
entity
name
=
"MouseInputHandlingEntity"
>
2.
<
component
class
=
"MyInputHandlingComponent"
name
=
"Input"
/>
3.
<
Input
>
4.
5.
<
GoLeft
>MOUSE_X</
GoLeft
>
6.
</
Input
>
7.
</
component
>
8.
</
entity
>
分享到:
相关推荐
NULL 博文链接:https://deepfuture.iteye.com/blog/709512
NULL 博文链接:https://deepfuture.iteye.com/blog/709889
NULL 博文链接:https://deepfuture.iteye.com/blog/709502
NULL 博文链接:https://deepfuture.iteye.com/blog/722156
帮助你快速了解PushButton的结构,尽快熟练应用
pushbutton engine是一个很好的flash游戏开发引擎,包含了常用的游戏组件,让设计师更注重游戏性的开发
PushButton Engine is a free framework for building Flash games. There are lots of great libraries for Flash game development. PushButton Engine makes it easy to bring those libraries together to build...
一款很强大的flash游戏开发引擎,分享下
一键式语音/停止技能 关于 假设有一个连接到Raspberry Pi的按钮,则会编写此Mycroft技能。 短按该按钮与说出唤醒词相同,然后允许用户说出命令。 长按与发出“停止”命令相同,因此将停止播放任何音频。...
舊帖請至 https://www.ilovematlab.cn/thread-86806-1-4.html 查看 該函數應該已經很完善 如果有出現問題可至下方網址的日誌回報 環境及建構方式: 使用R2010a 所建立的M檔案 無法獨立運行,必須配合gui ...
ui->pushButton->setEnabled(false); myCom->setBaudRate(BAUD9600); myCom->setDataBits(DATA_8); myCom->setParity(PAR_NONE); myCom->setStopBits(STOP_1); myCom->setTimeout(500); connect(myCom,...
pushbutton1_Callback.m
通过点击Qt中的pushbutton,可以弹出菜单,菜单选项是QAction,可以连接槽完成相应功能。Qt工程是基于Qt5.10.1 32位,Qt Creator 4.5.1(Community)
带Icon的自绘PushButton示例
Flash2D+3D游戏引擎: Flixel 位图引擎; Pushbutton engine; FlashPunk 引擎; As3isolibj; Away3D; Alternativa3D; Flare3D; CopperCube; Sophie3D;
智能家居自动化:GIRA PUSHBUTTON SENSOR 4,GIRA TASTSENSOR 4.pdf
遗传算法
SW PUSHBUTTON SE PUSHBUTTON SW-PB Switch SW-SPDT SPDT Subminiature Toggle Switch, Right Angle Mounting, Vertical Actuation URF04 Ultrasonic wave distanc measure module VS1003b-Module MP3 module XTAL ...
带Icon的自绘PushButton
SW PUSHBUTTON_5 TP XTAL_1 PCB封装库: Component Count : 17 Component Name ----------------------------------------------- 0603-C 0603-R 0805-C 1206-C 1206-FB Button CE 2.5/5 CE 5/8 DC IN LAN ...