简体   繁体   English

键盘输入到movieClip actionScript 3.0

[英]keyboard input to movieClip actionScript 3.0

I have two alternatives to move a space ship movieclip. 我有两种选择来移动太空飞船的动画片段。

First one is adding eventListener(keybordEvent) check which button is pressed and act according to it. 第一个是添加eventListener(keybordEvent)来检查按下了哪个按钮并根据该按钮进行操作。

The second one is again,adding an eventListener(keyboardEvent) and using 4 boolean varaibles,leftArrow,rightArrow,upArrow and downArrow. 第二个也是,添加一个eventListener(keyboardEvent)并使用4个布尔变量,leftArrow,rightArrow,upArrow和downArrow。 keep track of pushed buttons and use eventListener(Event.ENTER_FRAME) and move movieClip in everyframe using these bool variables) 跟踪按下的按钮并使用eventListener(Event.ENTER_FRAME)并使用这些bool变量在每一帧中移动movieClip)

Which one is better or at least does any of them have an advantages ? 哪个更好,或者至少其中一个有优势?

我建议第二种选择,因为您想在游戏循环中而不是在按键事件中处理运动。

I would use the Boolean method as the other method (depending how you implement it) could react to the key repeat that happens when you press a key down - it triggers once, pauses, then continues to fire. 我将使用Boolean方法,因为其他方法(取决于您如何实现)可以对按下按键时发生的按键重复做出反应-触发一次,暂停然后继续触发。

EDIT 编辑

..and, I agree, also for the best practices reason Nambew mentions! ..而且,我同意,也是Nambew提到的最佳做法!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM