0
我需要建議。我正在研究一個項目 - 一個簡單的遊戲。它會像「太空侵略者」一樣。我只需要迎合船隻不能離開該地區(舞臺)。函數,被稱爲「RMimoXY」不起作用。有人可以看看我在程序中丟失了什麼嗎?如何在舞臺上創建邊框
在此先感謝您的建議。
import flash.events.KeyboardEvent;
import flash.display.Sprite;
import flash.display.DisplayObject;
import flash.media.Sound;
import flash.display.Stage;
var let: Boolean = false;
var pozadi: Stage;
var vx:Number = 0;
var vy:Number = 0;
function mezernik(){
var mySound: Sound = new laserFire();
mySound.play();
RMimoXY();
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, klavesnice);
function klavesnice(e: KeyboardEvent){
switch(e.keyCode){
case Keyboard.LEFT: lod.x += -5; break;
case Keyboard.RIGHT: lod.x += 5; break;
case Keyboard.UP: lod.y += -5; break;
case Keyboard.DOWN: lod.y += 5; break;
case Keyboard.SPACE: mezernik(); break;
}
}
function RMimoXY(){
if (lod.x > stage.stageWidth){
lod.x = 0 - lod.width;
}
else if (lod.x < 0 - lod.width){
lod.x = stage.stageWidth;
}
if (lod.y > stage.stageHeight){
lod.y = 0 - lod.height;
}
else if (lod.y < 0 - lod.height){
lod.y = stage.stageHeight;
}
}
嘗試在每一幀運行此方法,如:'stage.addEventListener(Event.ENTER_FRAME,RMimoXY);',並改變它的定義,比如'功能RMimoXY(e:Event):無效' – Cherniv
感謝您的回答,但不要運行它。 – user3134756