/**
* 键盘控制类
* 把键盘按键动作格式化,一般用于游戏。作者:飞雨影
* 用法:Control.initStage(stage),初始化舞台;Control.addListener(function),添加listener;
* 改变控制设置:Control.changeControl(array);array为设置的keyCode
*/
package
{
import flash.display.Stage;
import flash.events.KeyboardEvent;
import flash.events.EventDispatcher;
import flash.events.Event;
public class Control
{
/**
* state为按钮状态,是否按下 isDown来得到状态
* controlKeyCode 为按钮控制设置数组,
* 默认为 w=上,s=下,a=左,d=下,u,i,j,k为四个动作按钮
*/
static private var state: Array = new Array(),controlKeyCode:Array=new Array(87,83,65,68,85,73,74,75);
static private var controlKey:Array=new Array(),controlName:Array=new Array('上','下','左','右','轻拳','重拳','轻脚','重脚');
static private var eventDispatcher:EventDispatcher=new EventDispatcher();
static public function initStage( stage:Stage ): void
{
var len:uint=controlKeyCode.length;
for(var i:uint=0;i
controlKey[controlKeyCode[i]]=controlName[i];
}
stage.addEventListener( KeyboardEvent.KEY_DOWN, onKeyDown );
stage.addEventListener( KeyboardEvent.KEY_UP, onKeyUp );
}
static public function isDown( code: uint ): Boolean
{
return state[ code ] == true;
}
static public function changeControl(keyCode:Array):void
{
controlKeyCode = keyCode;
}
static public function addListener(listener:Function):void
{
var len:uint=controlKeyCode.length;
for(var i:uint=0;i
eventDispatcher.addEventListener(controlName[i],listener);
eventDispatcher.addEventListener(controlName[i]+'release',listener);
}
}
static private function onKeyDown( event: KeyboardEvent ): void
{
var code:uint=event.keyCode
if(!isDown(code))
{
state[ code ] = true;
//trace( code,"按下");
if(controlKey[code])eventDispatcher.dispatchEvent(new Event(controlKey[code]));
}
}
static private function onKeyUp( event: KeyboardEvent ): void
{
var code:uint=event.keyCode
state[ event.keyCode ] = false;
//trace(event.keyCode,'释放')
if(controlKey[code])eventDispatcher.dispatchEvent(new Event(controlKey[code]+"release"));
}
}
}
我最强舞者 (I, Best Dancer)安卓版v8
我最强舞者(I, Best Dancer)是一款休闲放置类手
迷你世界国服版本2024 v1.43.0
迷你世界国服版本2024是一款自由度非常高的沙盒游戏,玩法和
烹饪乐园 安卓版v1.23.6
烹饪乐园(Cooking Town)是一款非常好玩的餐厅模拟
迷你世界小米服 最新安卓版v1.43.0
迷你世界小米版是由迷你玩科技开发的休闲模拟经营类游戏。此版本
布娃娃Sprunki沙盒 安卓版v0.0.1
布娃娃Sprunki沙盒是一个非常有趣的沙盒游戏,复古简约的