我需要建议。我正在做一个项目 - 一个简单的游戏。它将类似于" Space Invaders"。我只需要迎合船不能离开该地区(舞台)。功能,被称为" 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;
}
}
答案 0 :(得分:0)
好像你只是在构造函数中调用RMimoXY
。你应该在每次移动船只时调用它。因此,将其添加到keyhandler的末尾应该可以正常工作:
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;
}
RMimoXY();
}