Flex Actionscript 3 flash游戏 键盘 连招 连按 combo 同时按 事件处理
参考了一个外国人的博客,和天地会一个兄弟的代码。http://rss.9ria.com/?p=2905
引用一下原文:
“大家应该玩过KOF(拳王),连招都是高手们的玩意。最近,我参考国外的代码,自己写了这个组合键类库。可以实现组合键的各种要求,例如连招、同时按下几 个键等等。我还添加了一个功能,就是:可以规定按键之间的时间间隔,当玩家连招时,两次按键之间超过了这个时间间隔,就判断该连招无效。”
而我这个方案,不但可以开出连招,还加入了“双击”功能,例如双击右键,角色就可以跑起来~~~
下载代码:连招处理.rar
Demo:
package { import flash.display.Sprite; import flash.events.Event; import flash.events.KeyboardEvent; import flash.text.TextField; import flash.ui.Keyboard; import keyboard.KKeyAction; import keyboard.KSameTimeComboManager; import keyboard.KSequenceComboManager; public class ComboKeyEvent extends Sprite { private var sequenceComboManager:KSequenceComboManager; private var sameTimeComboManager:KSameTimeComboManager; public function ComboKeyEvent() { sequenceComboManager = new KSequenceComboManager(this.stage, 400, KSequenceComboManager.KEY_UP_DOWN_MODE); sameTimeComboManager = new KSameTimeComboManager(this.stage, 200); var a:Vector.<KKeyAction> = new Vector.<KKeyAction>; a.push(new KKeyAction(Keyboard.D, KeyboardEvent.KEY_DOWN)); a.push(new KKeyAction(Keyboard.D, KeyboardEvent.KEY_UP)); a.push(new KKeyAction(Keyboard.D, KeyboardEvent.KEY_DOWN)); a.push(new KKeyAction(Keyboard.D, KeyboardEvent.KEY_UP)); sequenceComboManager.addSequenceCombo(a, run); var b:Vector.<uint> = new Vector.<uint>; b.push(Keyboard.J); b.push(Keyboard.K); sameTimeComboManager.addSameTimeCombo(b, jump); } private function run():void { trace("run run run"); } private function jump():void { trace("jump jump jump jump "); } } }
kenkofox@qq.com
https://github.com/kenkozheng
欢迎投简历给我,一线大厂工作机会