flex游戏引擎(PushBotton)-资源嵌入
Resource Manager
不需要附加文件的数据运行游戏,比如图像、层、声音,ResourceManager 帮你完成这个愿望
Loading Resources
手动加载资源,定义回调函数
?
?
01.// Example of loading an image:
02.ResourceManager.instance.load("../Assets/Image/testImage.jpg", ImageResource, _OnImageLoaded, _OnImageFailed);
03.??
04.// Callback when the load succeeds.
05.function _OnImageLoaded(resource:ImageResource):void
06.{
07.?? // Store the loaded resource or do other activity.
08.?? Image = resource;
09.}
10.??
11.// Callback when the load fails.
12.function _OnImageFailed(resource:ImageResource):void
13.{
14.?? // Report the error.
15.?? Logger.printError(this, "_OnImageFailed", "Couldn't load the image!");
16.}
Resource types是 com.pblabs.engine.resource.Resource的子类,通常使用XMLResource, ImageResource, and MP3Resource的子类
Embedding Resources
嵌入资源最简单的办法就是使用ResourceBundle类,创建ResourceBundle class的子类,使用[Embed] tag包含swf。
?
?
xml和 pbelevel文件,你必须使用 mimeType='application/octet-stream' 在[Embed()] tag。图像不需要mimeType tags ,但是当下载大小重要时要小心
?
01.public class MyResources extends ResourceBundle
02.{
03.?? // Images and sounds can be embedded directly.
04.?? [Embed(source="../assets/myimage.png")]
05.?? public var resmyimage:Class;
06.?? [Embed(source="../assets/myjpg.jpg")]
07.?? public var resmyjpg:Class;
08.?? [Embed(source = "../assets/sounds/mysound.mp3")]
09.?? public var resmysound:Class;
10.?? // Note that we are specifying mimeType for xml so it is embedded properly.
11.?? [Embed(source = "../assets/levelDescriptions.xml", mimeType = 'application/octet-stream')]
12.?? public var resmyleveldescriptions:Class;
13.?? [Embed(source="../assets/levels/mylevel.pbelevel", mimeType='application/octet-stream')]
14.?? public var resmylevel:Class;
15.}???
在PBE.startup注册资源
1.PBE.startup(this);
2.new MyResources();
加上新的Resource Types
com.pblabs.engine.resource.Resource 子类支持不同的资源类型,看看 XMLResource如何运行,要覆盖_onContentReady ,提供访问需要数据的方式