我想创建一个侧滚动游戏。其中,我希望玩家能够射击吹飞镖。因为它是现在,如果玩家持有空格键,玩家的(这是一个MovieClip)拍摄动画循环。我希望动画只能在每个空格键上播放一次。Flash Actionscript 3.0动画循环
这里是代码,我使用:已被释放
// Process the pressed key(s)
public function KeyPressed(event:KeyboardEvent):void {
// The Left Key was pressed
if (event.keyCode == Keyboard.LEFT) {
leftKeyPressed = true;
}
// The Right Key was pressed
if (event.keyCode == Keyboard.RIGHT) {
rightKeyPressed = true;
}
// The Up Key was pressed
if (event.keyCode == Keyboard.UP) {
upKeyPressed = true;
}
// The Down Key was pressed
if (event.keyCode == Keyboard.DOWN) {
downKeyPressed = true;
}
// The Space Key was pressed
if (event.keyCode == Keyboard.SPACE) {
spaceKeyPressed = true;
}
} // End of 'KeyPressed()' function
该方法确定哪个键(一个或多个)::
该方法确定哪个键(一个或多个)被按下
public function KeyReleased(event:KeyboardEvent):void {
// The Left Key was released
if (event.keyCode == Keyboard.LEFT) {
leftKeyPressed = false;
}
// The Right Key was released
if (event.keyCode == Keyboard.RIGHT) {
rightKeyPressed = false;
}
// The Up Key was released
if (event.keyCode == Keyboard.UP) {
upKeyPressed = false;
}
// The Down Key was released
if (event.keyCode == Keyboard.DOWN) {
downKeyPressed = false;
}
// The Space Key was released
if (event.keyCode == Keyboard.SPACE) {
spaceKeyPressed = false;
}
} // End of 'KeyReleased()' function
这是播放播放器的一个拍摄动画的代码示例:
if (onGround && !downKeyPressed && spaceKeyPressed) {
player.gotoAndStop(7);
}
我该如何防止第7个播放器帧持续循环?我只想在空格键被按下时动画播放一次。
谢谢!
谢谢!我可以试试这些想法。 :) –