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.

你可能感兴趣的:(游戏,xml,Flex,Adobe,actionscript)