`
deepfuture
  • 浏览: 4341530 次
  • 性别: Icon_minigender_1
  • 来自: 湛江
博客专栏
073ec2a9-85b7-3ebf-a3bb-c6361e6c6f64
SQLite源码剖析
浏览量:79518
1591c4b8-62f1-3d3e-9551-25c77465da96
WIN32汇编语言学习应用...
浏览量:68578
F5390db6-59dd-338f-ba18-4e93943ff06a
神奇的perl
浏览量:101725
Dac44363-8a80-3836-99aa-f7b7780fa6e2
lucene等搜索引擎解析...
浏览量:281686
Ec49a563-4109-3c69-9c83-8f6d068ba113
深入lucene3.5源码...
浏览量:14653
9b99bfc2-19c2-3346-9100-7f8879c731ce
VB.NET并行与分布式编...
浏览量:65846
B1db2af3-06b3-35bb-ac08-59ff2d1324b4
silverlight 5...
浏览量:31406
4a56b548-ab3d-35af-a984-e0781d142c23
算法下午茶系列
浏览量:45320
社区版块
存档分类
最新评论

flex游戏引擎(PushButton)-控制输入(1)

阅读更多

InputManager可以完成一些简单的控制,但是当你要完成较复杂的控制时应使用InputMap,虽然InputManager使用较简单如下:

1.if(InputManager.isKeyDown(InputKey.UP))
2.   moveItemUp();

 

当你有第三方设备输入(比如手柄等),当你要控制键盘和鼠标,你可以采用一种一致的方式去处理它们,这种方式就是使用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.      // Normally you would update your position based on this; for simplicity
21.      // we just print the direction we are being indicated to move.
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.         <!-- These correspond to the calls to AddBinding above. -->
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.         <!-- These correspond to the calls to AddBinding above.  Only GoLeft needs to be bound because MOUSE_X gives negative as well as positive results. -->
5.         <GoLeft>MOUSE_X</GoLeft>
6.      </Input>
7.   </component>
8.</entity>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics