在单个类或多个场景中的Actionscript? [英] Actionscript in a single class or in multiple scenes?

查看:210
本文介绍了在单个类或多个场景中的Actionscript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Actionscript和Adobe Flash CS6完全陌生,为了一点乐趣,我决定尝试做一个小游戏。我有一些新的问题要问一个一般的实现方法。



我一直在读的文档建议创建一个新的闪存项目,然后创建一个文档类:

 包{

import flash.display.MovieClip;

public class MyMainClass extends MovieClip {


public function MyMainClass(){

}

}

}

我想知道我是否使用MainClass整个游戏或在一个场景中包含动作脚本,并具有多个场景,或两者的某种组合。



我说我在游戏中有一个想要的5个级别,例如:

 包{

import flash.display.MovieClip;

public class MyMainClass extends MovieClip {


public function MyMainClass(){
StartLevel1();
StartLevel2();
StartLevel3();
StartLevel4();
StartLevel5();
}

public function StartLevel1(){
//做某事
}
public function StartLevel2(){
//做某事
}
public function StartLevel3(){
//做某事
}
public function StartLevel4(){
//做某事
}
public function StartLevel5(){
// Do something
}

}

}

或在每个场景中创建5个带有actionscript的场景?
任何人都可以给我一个起点?
感谢

解决方案

我不知道有什么好说的场景。

然而,根据直觉,时间轴本身是一个用于管理Flash资产状态的好工具。如果你使用它,你还得到隐藏的优势,你不必下载100%的文件,以便能够使用它(所以你可以减少甚至消除对预加载器的需要,通过取消选中Export in frame N 对你的图书馆符号。



Lars已经非常正确地指出,很少有开发人员了解这种技术,我知道一个人能够并将帮助人谁有兴趣探索这种技术,那个人正在帮助你现在,所以如果你选择这样的方式,记住,你大多是自己,除非如果我偶然注意到你的帖子并回应它。 >

我不是 赞成时间轴脚本,很少例外。我建议的是 both和方法,其中使用文档类



您的文档类可能如下所示:

 
pubic类游戏扩展MovieClip {
protected var _level:ILevel; //接口你的级别MovieClips将实现
protected var levelController:LevelController = new LevelControler();
protected var currentLevel:int;
protected var maxLevels:int = 5;

public function Game(){
levelController.addEventListener(LevelEventKind.LEVEL_COMPLETE,nextLevel);
levelController.addEventListener(LevelEventKind.LEVEL_FAILED,gameOver);
startLevel(currentLevel);
}

public function startLevel(levelNumber:int):void {
goToLabel('Level'+ String(levelNumber));
}
public function get level():ILevel {
return _level;
}
public function set level(value:ILevel):void {
_level = value;
//内部,这应该释放所有监听器到最后
// level对象(如果有),所以你不会得到内存泄漏
levelController.level = _level;
}
protected function nextLevel(e:Event):void {
if(currentLevel< maxLevels){
startLevel(++ currentLevel);
} else {
//你赢了逻辑
}
}
protected function gameOver(e:Event):void {
// do bombed out logic here
}
protected function goToLabel(label:String):void {
for each(var frameLabel:FrameLabel in currentLabels){
if(frameLabel.name ==标签){
//如果你的swf是media-heavy,可能想检查框架
//如果你选择减少/消除preloader
goToAndStop(label);
return;
}
}
trace('no such label as',label);
}
}

这是一个游戏,你可以改变不同级别的外观,一行ActionScript,您可以通过分配实现ILevel的不同基类稍有不同来更改它们的工作方式。你也可以通过换出不同类型的LevelController来改变你的功能,但是你的主文档类(在这个例子中的游戏)会意识到这个变化(wheras其他的变化可以不改变游戏)。


I am completely new to Actionscript and Adobe Flash CS6 and for a little bit of fun I have decided to try and make a little game. I had a few newbie (or noob-y) questions to ask about a general implementation approach.

The documentation I've been reading so far suggests creating a new flash project, and then create a document class so:

package  {

    import flash.display.MovieClip;

    public class MyMainClass extends MovieClip {


        public function MyMainClass() {

        }

    }

}

and I am wondering if I use this MainClass to code the whole game or include actionscript within a scene and have multiple scenes, or some combination of both.

Lets say I had a wanted 5 Levels in my game, would I do something like:

package  {

    import flash.display.MovieClip;

    public class MyMainClass extends MovieClip {


        public function MyMainClass() {
            StartLevel1();
            StartLevel2();
            StartLevel3();
            StartLevel4();
            StartLevel5();
        }

        public function StartLevel1() {
            // Do something
        }
        public function StartLevel2() {
            // Do something
        }
        public function StartLevel3() {
            // Do something
        }
        public function StartLevel4() {
            // Do something
        }
        public function StartLevel5() {
            // Do something
        }

    }

}

or create 5 scenes with actionscript in each scene? Can anyone provide me with a bit of a starting point? Thanks

解决方案

I don't know of anyone who has anything good to say about scenes.

However, as you intuit, the timeline itself is a wonderful tool for managing the state of your Flash assets over time. If you use it, you also get the hidden advantage that you don't have to download 100% of your file to be able to use it (so you can reduce or even eliminate the need for a preloader by unchecking "Export in frame N" on your library symbols.

Lars has quite rightly pointed out that there are very few developers who understand this technique, and I know of exactly one who can and will help people who are interested in exploring this technique. That person is helping you right now. So if you choose to go that way, keep in mind you are mostly on your own except if I happen to notice your post and respond to it.

I am not in favor of timeline scripts, with a very few exceptions. What I suggest is a "both and" approach, where you use a Document Class to control timeline instances.

Your document Class might look something like this:

    pubic class Game extends MovieClip {
        protected var _level:ILevel;//Interface your Level MovieClips will implement
        protected var levelController:LevelController = new LevelControler();
        protected var currentLevel:int;
        protected var maxLevels:int = 5;

        public function Game() {
            levelController.addEventListener(LevelEventKind.LEVEL_COMPLETE, nextLevel);
            levelController.addEventListener(LevelEventKind.LEVEL_FAILED, gameOver);
            startLevel(currentLevel);
        }

        public function startLevel(levelNumber:int):void {
            goToLabel('Level' + String(levelNumber));
        }
        public function get level():ILevel {
            return _level;
        }
        public function set level(value:ILevel):void {
           _level = value;
           //internally, this should release all listeners to the last 
           //level object (if any) so you don't get a memory leak
           levelController.level = _level;
        }
        protected function nextLevel(e:Event):void {
            if (currentLevel < maxLevels) {
                startLevel(++currentLevel);
            } else {
                //do you won logic here
            }
        }
        protected function gameOver(e:Event):void {
            //do bombed out logic here
        }
        protected function goToLabel(label:String):void {
            for each (var frameLabel:FrameLabel in currentLabels) {
                if (frameLabel.name==label) {    
                    //if your swf is media-heavy, may want to check that frame
                    //is loaded if you chose to reduce/eliminate preloader
                    goToAndStop(label);
                    return;
                }
            }
            trace('no such label as', label);
        }
    }

What this gets you is a game where you can change how the different levels look without changing a single line of ActionScript, and you can change how they work by assigning different Base Classes that implement ILevel slightly differently. You can also change your functionality by swapping out different flavors of LevelController, but your Main Document Class (Game in this instance) would be aware of this change (wheras the other changes could be made without altering Game at all).

这篇关于在单个类或多个场景中的Actionscript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆