快速业务通道

[更新]键位设置组件和连招组件[KeyMapper & ComboInput]

作者 佚名技术 来源 服务器技术 浏览 发布时间 2012-07-11


解决了有时不能更改按钮名的bug。Flash的类型转换的问题。
更改了使用的方法,现在不需要在场景中添加km和ci的组件了,只需在库中保留km_ci组件,然后在代码中new出KeyMapper或者ComboInput的对象即可。 使用方法:
点击浏览该文件
组件:
点击浏览该文件
/**
system required:
flash mx 2k4 or later
flash player 6 or later
AS 2
*/

///////////////// KeyMapper class ////////////////
/*
class xp.gameLib.input.KeyMapper extends MovieClip implements xp.events.EventDispatcher_itf
{
public function KeyMapper(b:Object, m:Array);
public function addEventListener(event:String, handler):Void;
public function addMap(m:Array):Number;
public function dispatchEvent(eventObj:Object):Void;
public function dispatchQueue(queueObj:Object, eventObj:Object):Void;
function set enabled(e:Boolean);
function get enabled():Boolean;
public function getButtons():Array;
public function getMap(i:Number):Array;
public function getMappedKey(q:String):Number;
public function removeEventListener(event:String, handler):Void;
public function setButtons(b:Object);
public function switchMap(i:Number);
};
*/

//initialize and set buttons and corresponding key codes
//the keys used here are: w,a,s,d,u,i,j,k;
//**the last 4 keys are not used ’cause there are only 4 buttons defined.
var km:xp.gameLib.input.KeyMapper=new xp.gameLib.input.KeyMapper(["up","down","front","back"],[87, 83, 68, 65, 85, 73, 74, 75]);
/**
OR:
var km:KeyMapper=new KeyMapper("up,down,front,back",[87, 83, 68, 65, 85, 73, 74, 75]);
var km:KeyMapper=new KeyMapper();
*/
//add another button_to_key map
//return an ID for this map
var id=km.addMap([87, 83, 68, 65, 85, 73, 74, 75]);
//enable or disable key mapper.
km.enabled=true;//=false
//get all buttons
var buttons:Array=km.getButtons();
trace(buttons);
//get a map or as default get the current map
var mapA:Array=km.getMap(id);
trace(mapA);
/*
OR:
km.getMap();//to return current
*/
//get key code for a specific button
trace(km.getMappedKey("up"));
//reset buttons,
km.setButtons(["up","down","front","back"]);
//or: km.setButtons("up,down,front,back");
//choose another map
km.switchMap(id);

//make some Object to receive buttons event:
km.addEventListener("button",_root);
_root.button=function(eo){
var re=""
for (i in eo.btn) re+=i+"--"+eo.btn[i]+" ";
trace(re);
}
/*
there are some global value for buttons state
_global._KD = 1;
_global._KU = 2;
_global._KH = 3;
_global._KR = 4;
you can use these value to determine the button states:
KD:key just pressed down
KU:key just released up
KH:key is holding down
KR:key is free
*/
/*
////////////////////////// output: ///////////////////////////////
INFO: buttons set to up,down,front,back
up,down,front,back
87,83,68,65,85,73,74,75
87
INFO: buttons set to up,down,front,back
back--4 front--4 down--4 up--3
back--4 front--4 down--4 up--4
back--4 front--1 down--4 up--4
back--4 front--3 down--4 up--4
back--4 front--3 down--4 up--4
back--4 front--3 down--4 up--4
*/
////////////////

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号