简体   繁体   English

如何为Flash游戏创建预加载器

[英]How To Create a Preloader to a Flash Game

I'm just beginning to get into flash game programming. 我刚刚开始涉足Flash游戏编程。 I know enough to make a functioning project, but not how to make it efficient or do specific tasks, in this case how to add a preloader. 我知道足够制作一个正常运行的项目,但是不知道如何使它高效或执行特定任务,在这种情况下,如何添加预加载器。 I've found several tutorials online, but none that go along with how I've seen is the best method to program. 我在网上找到了几本教程,但是与我所看到的方式相伴而生的是最好的编程方法。 From what I've seen, it is best to program all of my code into one .as file and link this file to the main document. 从我所看到的,最好是将我的所有代码编程到一个.as文件中,并将该文件链接到主文档。 This makes it easy for me to make all of my variables global in scope, which lets me addChild/removeChild in various different functions. 这使我可以轻松地将所有变量设置为全局范围,这使我可以在各种不同的函数中使用addChild / removeChild。 The only problem is that I can't find a tutorial on creating a preloader with this method in mind. 唯一的问题是我找不到考虑到使用此方法创建预加载器的教程。 All tutorials that I've found generally have two frames in the timeline, one with the preloader and one with the content, but I've been told this is not a good way to program. 我发现的所有教程通常在时间轴上都有两帧,一个带有预加载器,另一个带有内容,但有人告诉我这不是编程的好方法。 If anyone could help I'd appreciate it a lot. 如果有人可以帮助我,我将非常感激。 I can paste the source code of one of my learning projects if it would help to provide an answer to my question. 如果可以帮助回答我的问题,则可以粘贴我的一个学习项目的源代码。

I wouldn't go with the 2 Frame approach. 我不会采用2帧方法。 Instead just make your game with your Document Class, like you said you would like to do. 而是像您说的那样,使用文档类制作游戏。
Then when your done, load your compiled game swf into a loader swf. 然后,完成后,将已编译的游戏swf加载到加载器swf中。

Here is a simple example on how your loaderSwf should look like: 这是一个关于loaderSwf外观的简单示例:

import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
import flash.events.ProgressEvent;

function startLoad()
{
   var mLoader:Loader = new Loader();//Or use ProLoader
   var mRequest:URLRequest = new URLRequest(“Game.swf”);
   mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
   mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
   mLoader.load(mRequest);
}

function onCompleteHandler(loadEvent:Event)
{
   addChild(loadEvent.currentTarget.content);
}
function onProgressHandler(mProgress:ProgressEvent)
{
   var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
   trace(percent);
}
startLoad();

(needs to be wraped in a package and Class if you are using it as Document Class) (如果将其用作文档类,则需要包装在包和类中)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM