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.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值