0
所以我搞砸了,並決定我將添加一個主菜單,我已經在Flash中工作的遊戲。所以我得到了我的背景,並且我已經決定要在背景中添加一個球,它會在屏幕上上下跳動 - 但是到目前爲止,我發現的僅僅是粘在頂角,並沒有更新每一幀。有些反饋意見是我錯誤的地方非常感謝 - 我知道它可能是因爲我在錯誤的地方做着addChild(gameBall)
,但我該如何糾正? main.as基本上是檢查遊戲所處狀態的開關,mainMenu.as是mainMenu本身。他們是我在代碼上面評論過的單獨文件。使用addChild - Flash?
// main.as
package
{
import flash.display.*;
import flash.system.fscommand;
public class main extends MovieClip
{
public function main()
{
changeState(null, "menu");
}
public function changeState (currentState, nextState)
{
if (currentState != null)
{
removeChild(currentState);
}
switch(nextState)
{
case "menu": var mm:mainMenu = new mainMenu(changeState);
addChild(mm);
break;
case "game": var g:theGame = new theGame(changeState);
addChild(g);
break;
case "exit": fscommand("quit");
break;
}
}
}
}
//mainMenu.AS
package
{
import flash.display.*;
import flash.events.*;
public class mainMenu extends MovieClip
{
var theCallBackFunction:Function;
private var ballX:Number = 5; // Declaring a variable known as _vx
private var ballY:Number = 5; // Declaring a variable knwon as _vy
private const GRAVITY:Number = 2; // Declaring a const variable known as gravity
var gameBall:Ball = new Ball();
public function mainMenu(callBack)
{
var btnPlay:mmPlay = new mmPlay();
btnPlay.addEventListener(MouseEvent.MOUSE_DOWN, brnP_Button);
btnPlay.x = width/2;
btnPlay.y = height/2 - btnPlay.height/2;
addChild(btnPlay);
var btnExit:mmExit = new mmExit();
btnExit.addEventListener(MouseEvent.MOUSE_DOWN, brnE_Button);
btnExit.x = width/2;
btnExit.y = height/2 - btnExit.height/2;
btnExit.y += btnExit.height + 4;
addChild(btnExit);
ballY += GRAVITY
if (ballY < 0)
{
ballY += 5;
}
gameBall.x += ballX;
gameBall.y += ballY;
addChild(gameBall);
theCallBackFunction = callBack;
}
public function brnP_Button(e:MouseEvent)
{
theCallBackFunction(this, "game");
return;
}
public function brnE_Button(e:MouseEvent)
{
theCallBackFunction(this, "exit");
return;
}
}
}
如何運行enterFrameHandler方法?如果您完整地發佈菜單類的最新版本,可能會更好。 –