`
deepfuture
  • 浏览: 4333348 次
  • 性别: Icon_minigender_1
  • 来自: 湛江
博客专栏
073ec2a9-85b7-3ebf-a3bb-c6361e6c6f64
SQLite源码剖析
浏览量:79428
1591c4b8-62f1-3d3e-9551-25c77465da96
WIN32汇编语言学习应用...
浏览量:68376
F5390db6-59dd-338f-ba18-4e93943ff06a
神奇的perl
浏览量:101498
Dac44363-8a80-3836-99aa-f7b7780fa6e2
lucene等搜索引擎解析...
浏览量:281206
Ec49a563-4109-3c69-9c83-8f6d068ba113
深入lucene3.5源码...
浏览量:14608
9b99bfc2-19c2-3346-9100-7f8879c731ce
VB.NET并行与分布式编...
浏览量:65559
B1db2af3-06b3-35bb-ac08-59ff2d1324b4
silverlight 5...
浏览量:31320
4a56b548-ab3d-35af-a984-e0781d142c23
算法下午茶系列
浏览量:45206
社区版块
存档分类
最新评论

flex游戏引擎(PushButton)-使用XML层格式存储游戏对象-3

阅读更多

 

加载level文件

使用LevelManager加载文件, 并管理它,提供接口加载和卸载level文件,你可以覆盖一些接口。

 

通过MXML加载

 

 

1.<mx:Canvas xmlns:mx="http://www.adobe.com.2006/mxml" xmlns:pb="PBLabs.Engine.MXML.*">
2.   <pb:LevelFileReference filename="..Assets/Levels/level.pbelevel" level="0" id="myLevelReference" />
3.   <pb:GroupReference name="Managers" level="0" id="managerGroup" />
4.   <pb:GroupReference name="SpriteSheets" level="0" id="spriteSheetsGroup" />
5.   <pb:GroupReference name="Objects" level="0" id="objectsGroup" />
6.   <pb:GroupReference name="Everything" level="0" id="everythingGroup" />
7.</mx:Canvas>
LevelManager加载层,4个组获得对象,被LevelFileReferenceGroupReference2个类共享的level属性不过是索引定义加载的文件或层的编号

 

1.// 加载0层启动GAME

2.LevelManager.Instance.LoadLevel(0);
3.LevelManager.Instance.Start();
 
 
当0层加载后,对象创建,游戏启动, LevelManager 分发基于加载和卸载level文件的事件

01.// Add a listener to respond to level loaded event

02.LevelManager.Instance.addEventListener(LevelEvent.LEVEL_LOADED_EVENT, levelLoadedHandler, false, 0, true);
03.// Load level 0 and start game.
04.LevelManager.Instance.LoadLevel(0);
05.LevelManager.Instance.Start();
06.private function levelLoadedHandler(event:LevelEvent):void
07.{
08.   // level is loaded!
09.}

通过ActionScript加载

与通过MXML相似

 

01.// Add file and group references

02.LevelManager.Instance.AddFileReference(0, "../Assets/Levels/level.pbelevel");
03.LevelManager.Instance.AddGroupReference(0, "Managers");
04.LevelManager.Instance.AddGroupReference(0, "SpriteSheets");
05.LevelManager.Instance.AddGroupReference(0, "Objects");
06.LevelManager.Instance.AddGroupReference(0, "Everything");
07.// Load level 0 and start game.
08.LoadManager.Instance.LoadLevel(0);
09.LoadManager.Instance.Start();
 

 

对XML的其他使用 

level文件和TemplateManager用来加载和实例XML数据,Serialization类可从XML中实例化,但建议使用TemplateManager

 

完整TAG列表

  • things: The root tag.
  • template: A child of the root tag, specifying that the contained XML is a template definition.
  • entity: A child of the root tag, specifying that the contained XML is an entity definition.
  • group: A child of the root tag, specifying that the contained XML is a group definition.
  • component: A child of the template or entity tag, specifying that the contained XML is a component definition.
  • objectReference: A child of the group tag, specifying the name of a template or object to instantiate with the group.
  • groupReference: A child of the group tag, specifying the name of a group to instantiate with the parent group.

完整属性列表

  • name:
    • On template tags, it specifies the name of the template.
    • On entity tags, it specifies both the name of the entity in XML, and the name of the object that is instantiated from it.
    • On group tags, it specifies the name of the group.
    • On component tags, it specifies the name of the component once registered with its owning IEntity.
    • On objectReference tags, it specifies the name of the template or entity to reference.
    • On groupReference tags, it specifies the name of the group to reference.
  • template: Exists on a template or entity tag and specifies the name of a template to inherit component definitions from.
  • nameReference: Specifies the name of an entity to lookup and set on the tag.
  • objectReference: Specifies the name of a template or entity to instantiate and set on the tag.
  • entityName: Specifies the name of a template or entity to lookup and search for a compatible component to set on the tag.
  • w: Specifies the name of a component to reference. If used without a componentReference attribute, the component is looked up on the same entity that this attribute is a part of.
  • type:
    • On a component, specifies the fully qualified type to use to instantiate the component.
    • On a field, specifies the type to use when instantiating the field for the parent tag.
  • childType: Specifies the type to use when instantiating objects to add to an array or dictionary.
  • filename: For fields that hold resources, this lets you specify a file path. The field must be of a compatible type to the type of the resource as specified to the resource manager. The resource will be loaded and assigned to the field.
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics