我想創建一個側滾動遊戲。其中,我希望玩家能夠射擊吹飛鏢。因爲它是現在,如果玩家持有空格鍵,玩家的(這是一個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個播放器幀持續循環?我只想在空格鍵被按下時動畫播放一次。
謝謝!
謝謝!我可以試試這些想法。 :) –