所以我一直在做一个简单的游戏,我想添加从舞台右侧到左侧移动的简单敌人。当他们到达舞台结束时,他们会继续走出舞台。
但是我的公共类应用程序已经创建,并且每个人似乎都将它放在另一个公共类中,但我只能有一个.as文件。有没有办法在不创建第二个.as文件的情况下创建敌人?这是我尝试过的,温柔的,我是一个完整的菜鸟。
package {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.DisplayObject;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.ui.Keyboard;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.display.Loader;
import flash.net.URLRequest;
import ClipBouton;
import FenetreMsg;
import flash.utils.Timer;
public class Application extends Sprite {
public var _menu: Sprite; //Fenêtre
public var _fenetreMsg: FenetreMsg; //Loader
public var _fond: Loader; //URLRequest
public var _lienImage: URLRequest;
public var _Right: Boolean;
public var _Left: Boolean;
public var _up: Boolean;
public var gravity: int;
public var _enSaut: Boolean;
public var _space: Boolean;
public var enemyShipTimer:Timer;
public var _pacman: MovieClip;
public var _canard: MovieClip;
以下是我试图制作的敌人(它们是在之前的代码之后放置的):
public function Application() {
var speed:Number;
function canard(){
this.x = 600;
this.y = Math.random()*200;
speed = Math.random()*5 + 5;
addEventListener("enterFrame", enterFrame);
}
function enterFrame(e:Event){
this.x -= speed;
if(this.x < -100){
removeEventListener("enterFrame", enterFrame);
stage.removeChild(this);
}
}
这是游戏开始的代码
public function initialiserJeu(): void {
this._lienImage.url = "images/dojo1.png";
this._fond.load(this._lienImage);
_pacman = new pacman;
this.addChild(this._pacman);
this._pacman.vitesseY = 0;
_pacman.y = stage.stageHeight;
_pacman.x = 160;
enemyShipTimer = new Timer(1000);
enemyShipTimer.addEventListener("timer", sendEnemy);
enemyShipTimer.start();
trace(this.enemyShipTimer);
this._Right = false;
this._Left = false;
this._up = false;
this._space = false;
this.gravity = 1;
stage.addEventListener(KeyboardEvent.KEY_UP, released);
stage.addEventListener(KeyboardEvent.KEY_DOWN, pressed);
stage.focus = stage;
addEventListener(Event.ENTER_FRAME, loop);
}
function sendEnemy(pEvt:Event){
_canard = new canard;
stage.addChild(_canard);
}
对不起,如果有些东西是法语,我的敌人就是&#34; canard&#34;。
感谢您的帮助。