我正在Flash中制作游戏,我遇到的问题是有两个类,一个名为Menu的类,用于欢迎屏幕,它有一个开始游戏按钮,以及引擎类,当我第一次运行游戏时,我设置菜单以自动显示以下代码:
public var state:int;
public const MENU:int = 0;
public const GAME:int = 1;
// create the variable for the menu
private var _menu:Menu;
public var sBg1:ScrollBg;
public var sBg2:ScrollBg;
public function Engine(menu:Menu)
{
_menu = menu;
//we add event listener when the engine is added to the stage
addEventListener(Event.ADDED_TO_STAGE, onAdded);
}
private function onAdded(e:Event):void {
//then we remove the event listener and initiate the init function
removeEventListener(Event.ADDED_TO_STAGE, onAdded);
init();
}
private function init():void {
//the init function set the game state at first to menu and run the drawUI function
state = MENU;
drawUI();
}
public function drawUI():void
{
//the drawUI function draw the needed elements on stage according to the state of the game
switch(state){
case MENU:
_menu = new Menu();
addChild(_menu);
break;
case GAME:
sBg1= new ScrollBg();
addChild(sBg1);
sBg1.x = 0;
sBg1.y = 0;
//if(contains(_menu)){
//removeChild(_menu);}
trace('this the game');
break;
}
}
我在 Menu 类中使用以下代码将状态从菜单更改为实际游戏:
public var start_btn:MovieClip;
private var _engine:Engine;
public function Menu()
{
addEventListener(Event.ADDED_TO_STAGE, displayMenu);
}
private function displayMenu(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, displayMenu);
start_btn = new startBtn();
start_btn.x = 100;
start_btn.y = 200;
addChild(start_btn);
start_btn.addEventListener(MouseEvent.CLICK, startGame);
}
private function startGame(e:MouseEvent):void
{
start_btn.removeEventListener(MouseEvent.CLICK, startGame);
_engine = new Engine(this);
_engine.state = 1;
_engine.drawUI();
}
我每次为菜单使用 drawUI 函数,例如它放置开始按钮,对于游戏,它放置背景,但由于某种原因,我只得到跟踪语句说(这是游戏),但背景没有显示任何线索。
我花了 4 个多小时试图找出问题所在,如果有人可以帮助我,我仍然无法做到这一点。
谢谢
如果您在屏幕上看到跟踪但没有看到任何内容,则很可能是因为 ScrollBg 类没有任何要显示的内容。确保该类中有一些精灵或图像。