Actionscript制作游戏介绍

时间:2014-04-29 08:10:30

标签: actionscript-3

我在全班制作游戏。所以时间表是空的。但是我想在游戏介绍中使用另一个场景,在介绍之后,它将进入我创建的游戏的主菜单。有人有个主意吗?我从一周前就找不到任何东西......我真的不知道如何从课堂代码中操作场景。请帮忙。谢谢!

这是主要代码:

package
{   
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.MovieClip;

public class Main extends Sprite
{
    public var field:Array;
    //CALL EVERY CLASS
    public var _money:Money = new Money();
    public var _gold:Gold;
    public var _hero:Hero;
    public var _enemy:Enemy;
    private var _pause:MovieClip = new Pause();
    private var pauseLayer:MovieClip = new PauseLayer();
    private var ts:TitleScreen;


    public function Main():void
    {
        ts = new TitleScreen();
        addChild(ts);
    }

    //GAME FUNCTION
    public function onStage():void
    {

        _hero = new Hero(this);
        _enemy = new Enemy(this);
        _gold = new Gold(this);

        setupField();

        _gold.goldSet(stage);
        _money.addText(stage);
        _hero.displayHero(stage);
        _enemy.displayEnemy(stage);
        setPause();
        _pause.addEventListener(MouseEvent.CLICK, pauseGame);
    }


    private function setPause():void
    {
        addChild(_pause);
        _pause.x = 620;
        _pause.y = 50;
        _pause.buttonMode = true;
    }

    private function pauseGame (e:MouseEvent):void
    {
        stage.frameRate = 0;
        addChild(pauseLayer);
        pauseLayer.alpha = 0.5;
        pauseLayer.parent.setChildIndex(pauseLayer,numChildren-1);
    }

    //SET UP FIELD ARRAY
    private function setupField():void 
    {
        var fieldSprite:Sprite=new Sprite();
        addChild(fieldSprite);
        fieldSprite.graphics.lineStyle(4);

        field=new Array();

        for (var a:int=0; a<6; a++) 
        {
            field[a]=new Array();
            for (var b:int=0; b<10; b++) 
            {
                field[a][b]=0;
            }
        }
        //DRAW  FIELD
        for (var i:int=0; i<5; i++) 
        {
            for (var j:int=0; j<9; j++) 
            {
               fieldSprite.graphics.drawRect(75+65*j,50+75*i,65,75);                 
            }
        }
    }

}
}

Titlescreen类:

package  
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.display.Sprite;

public class TitleScreen extends Sprite
{
    private var playBtn:MovieClip = new Resume();


    public function TitleScreen() 
    {
        playBtn.x = 50;
        playBtn.y = 50;
        playBtn.addEventListener(MouseEvent.CLICK, Play);
    }



    private function Play(e:MouseEvent):void
    {

        trace("a");
    }

}

   }

2 个答案:

答案 0 :(得分:1)

最简单的方法是使用包装器Sprite来保存您可能希望整个可用的每组对象,比如主菜单,升级,故事情节等等。然后你只需将它们移入超出显示列表以显示相应的&#34;场景&#34;与您的Main类负责过渡流程。但要做到这一点,您需要将游戏核心功能从Main类转移到说Game类。这就是我在游戏中做同样事情的方式:

public class Main extends MovieClip {
        private var so:SharedObject;
        private var ui:UserInterface;
        private var ts:TitleScreen;
    private function init(e:Event = null):void 
    {
        ui = new UserInterface();
        ts = new TitleScreen();
        ts.newButtonClicked = newGame;
        ts.loadButtonClicked = loadGame;
        ui.gotoMapBehavior = wentToMap;
        addChild(ts);
    }

此处,UserInterface是一个内部具有游戏逻辑的类,TitleScreen是主菜单类。这些函数是Main

中的回调函数
    private function newGame():void {
        removeChild(ts); // hide title
        if (!contains(ui)) addChild(ui);
        SoundManager.playMusic(SoundManager.MUSIC_LEVELSELECT);
    }
    private function loadGame():void {
        newGame();
        ui.loadBattle(); // this should make UI load the battle from shared object (either supplied or received by itself)
    }
    private function wentToMap():void {
        // we have just executed "go to map" from UI
        removeChild(ui);
        addChild(ts);
        checkSO();
        SoundManager.playMusic(SoundManager.MUSIC_INTRO);
    }

实际游戏逻辑根本不与Main交互,除了整个项目常见的共享对象,但通常通过SharedObject.getLocal(someName)接收链接。代码很难看,但可以为初学者做。

答案 1 :(得分:0)

将您的游戏保存为SWF并使用时间轴动画介绍制作另一个项目。当介绍结束时,让您的项目加载您的游戏。 Loader类可以加载其他swf文件。因此,您不需要编辑游戏类。