Export Templates
Overview
Using templates (requires v2+) to export your data allows for a much more flexible way to structure the data in a format that suits your needs.
For instance the built-in exporter in Level Director only supports the Corona SDK but you may want the data in a format that supports a different SDK.
Level Director provides some example templates in the ‘Template’ folder.
When using the CoronaTemplate you can use the Utility Modules to help do all the work for you.
Limitations
The template processor does not currently support ‘IF’ statements but it does support conditional section tokens e.g. <%?OBJECT_TEXT%> </%?OBJECT_TEXT%> only properties for text objects will be exported.
Options
In tools->options you can specify the template that you wish to use.
When using a template you also have the flexibility to split each level (if you have multiples) into seperate files.
The filenames are determined by the name in which you call your level.
You can also specifiy the export folder for your levels.
Once configured the export will become seamless.
Structure
The basic structure is as follows and note you must include the parent node before being able to access a child node;
- Levels
- Level
- SpriteSheets
- SpriteSheet
- Frames
- SpriteSheet
- Assets
- Asset
- User Properties (asset)
- Asset
- Layers
- Layer
- Objects
- User Properties (object)
- User Properties (layer)
- Objects
- Layer
- User Properties (level)
- SpriteSheets
- Level
Tokens
To identify the structure within a template, tokens are used .
There are two types of tokens, group (or loop) tokens and property tokens.
A group token represents a group of entities e.g. levels or layers and the section within the group will be repeated per entity.
A property token represents a property of the entity instance eg. layer.name or object.x.
The format of the tokens are as follows;
Group Token
<%GroupName%> – this denotes the start of a group section e.g. <%Layers%>
</%GroupName%> – this denotes the end of a group section e.g. </%Layers%>
Property Token
%Entity%.PropertyName – this token will be replaced by the property value e.g. %Layer%.Name
Token List
%SYSTEM%.Version (Level Director Version)
%SYSTEM%.DateTime (current Date and time)
<%LEVELS%>
- %LEVEL%.Name
- %LEVEL%.GravityX
- %LEVEL%.GravityY
- %LEVEL%.CanvasWidth
- %LEVEL%.CanvasHeight
- %LEVEL%.TargetWidth
- %LEVEL%.CanvasHeight
- %LEVEL%.ParallaxEnabled
- %LEVEL%.ParallaxInfinite
- %LEVEL%.BackColorR (red)
- %LEVEL%.BackColorG (green)
- %LEVEL%.BackColorB (blue)
- %LEVEL%.BackColorA (Alpha)
- %LEVEL%.WireFrame
- %LEVEL%.DebugMode
- %LEVEL%.PositionIterations
- %LEVEL%.VelocityIterations
- <%USERPROPS%>
- %USERPROP%.Key
- %USERPROP%.Value
- </%USERPROPS%>
-
<%SPRITESHEETS%>
- %SPRITESHEET%.Name
- %SPRITESHEET%.Width
- %SPRITESHEET%.Height
- %SPRITESHEET%.Image
-
<%FRAMES%>
- %FRAME%.X
- %FRAME%.Y
- %FRAME%.Width
- %FRAME%.Height
- %FRAME%.Name (spritesheet name)
- %FRAME%.File
- %FRAME%.FrameName (unique frame name)
- %FRAME%.FrameCount
- %FRAME%.Frame (frame number)
- %FRAME%.OX (x offset when trimming used)
- %FRAME%.OY
- %FRAME%.OWidth
- %FRAME%.OHeight
-
</%FRAMES%>
-
</%SPRITESHEETS%>
-
<%ASSETS%>
- %ASSET%.File
- %ASSET%.Name
- %ASSET%.Width
- %ASSET%.FrameCount
- %ASSET%.Frame (frame no. if part of spritesheet)
- %ASSET%.SpriteSheetName
- %ASSET%.AnimationSequences (exports table of animation sequences)
- %ASSET%.Physics.IsEnabled
- %ASSET%.Physics.IsBullet
- %ASSET%.Physics.BodyType (Static, Dynamic or Kinematic)
- %ASSET%.Physics.AngularDamping
- %ASSET%.Physics.BodyShape (Rectangle, Round or Polygon)
- %ASSET%.Physics.Bounce
- %ASSET%.Physics.Friction
- %ASSET%.Physics.Density
- %ASSET%.Physics.CategoryBits
- %ASSET%.Physics.FixedRotation
- %ASSET%.Physics.GravityScale
- %ASSET%.Physics.GroupIndex
- %ASSET%.Physics.IsSensor
- %ASSET%.Physics.IsSleepingAllowed
- %ASSET%.Physics.LinearDamping
- %ASSET%.Physics.MaskBits
- %ASSET%.Physics.Radius
- %ASSET%.Physics.ReferencePoint
- %ASSET%.Physics.Shape (list of x,y points for polygon shapes)
- <%USERPROPS%>
- %USERPROP%.Key
- %USERPROP%.Value
- </%USERPROPS%>
-
</%ASSETS%>
-
<%LAYERS%>
- %LAYER%.Name
- %LAYER%.ParallaxSpeedX
- %LAYER%.ParallaxSpeedY
- %LAYER%.ParallaxRepeat (does the layer repeat, only works in Infinite mode)
- <%USERPROPS%>
- %USERPROP%.Key
- %USERPROP%.Value
- </%USERPROPS%>
-
<%OBJECTS%>
- %OBJECT%.Name
- %OBJECT%.Width
- %OBJECT%.Height
- %OBJECT%.X
- %OBJECT%.Y
- %OBJECT%.xScale
- %OBJECT%.yScale
- %OBJECT%.xFlip
- %OBJECT%.yFlip
- %OBJECT%.Alpha
- %OBJECT%.Rotation
- %OBJECT%.Class
- %OBJECT%.File (if part of an asset)
- %OBJECT%.AssetName
- %OBJECT%.EnableDrag (adds drag event)
- %OBJECT%.Physics.xxx (as per Asset.physics)
- %OBJECT%.Type (LDObjectImage, LDObjectText, LDObjectRectangle, LDObjectEllipse, LDObjectBezier, LDObjectPath, LDObjectJoint)
- %OBJECT%.xPoints (refers to Bezier or Path points)
- %OBJECT%.yPoints (refers to Bezier or Path points)
- %OBJECT%.OutputType (refers to Bezier or Path, Display or DataOnly )
- %OBJECT%.StrokeWidth
- %OBJECT%.StrokeColorR (stroke color is used for text, ellipse, rectangle, bezier and path)
- %OBJECT%.StrokeColorG
- %OBJECT%.StrokeColorB
- %OBJECT%.StrokeColorA
- %OBJECT%.FillColorR (fill color is used for ellipse and rectangle objects)
- %OBJECT%.FillColorG
- %OBJECT%.FillColorB
- %OBJECT%.FillColorA
- %OBJECT%.CornerRadius (rectangle corner radius)
- %OBJECT%.Text (Text from LDObjectText)
- %OBJECT%.FontName
- %OBJECT%.FontSize
- %OBJECT%.MotorSpeed (joints)
- %OBJECT%.JointType
- %OBJECT%.DampingRatio
- %OBJECT%.Frequency
- %OBJECT%.ParamA
- %OBJECT%.ParamB
- %OBJECT%.Limit1
- %OBJECT%.Limit2
- %OBJECT%.SrcObjectName
- %OBJECT%.AnchorAX
- %OBJECT%.AnchorAY
- %OBJECT%.DstObjectName
- %OBJECT%.AnchorBX
- %OBJECT%.AnchorBY
- <%USERPROPS%
- %USERPROP%.Key
- %USERPROP%.Value
- </%USERPROPS%>
-
</%OBJECTS%>
-
</%LAYERS%>
</%LEVELS%>
Conditional Tokens
These tokens make the section conditional depending on the object type, so for example it will exclude properties related to a Text Box if the current object being exported is an Image.
- <%?OBJECT_TEXT%>
- <%?OBJECT_PHYSICS%>
- <%?OBJECT_JOINT%>
- <%?OBJECT_STYLE%>
- <%?OBJECT_POINT%>
- <%?OBJECT_FOLLOWPATH%>
Basic Example
local levels = {
<%LEVELS%>
level = {
name = %LEVEL%.Name,
width = %LEVEL%.CanvasWidth,
height = %LEVEL%.CanvasHeight,
<%LAYERS%>
layer {
name = '%LAYER%.Name',
<%OBJECTS%>
objects ={
file = '%OBJECT%.File',
name = '%OBJECT%.Name',
width = %OBJECT%.Width,
height = %OBJECT%.Height,
physics = { isEnabled = %OBJECT%.Physics.IsEnabled,
bodyType = '%OBJECT%.Physics.BodyType',
bodyShape = '%OBJECT%.Physics.BodyShape',
shape = {%OBJECT%.Physics.Shape},
bounce = %OBJECT%.Physics.Bounce,
friction = %OBJECT%.Physics.Friction,
density = %OBJECT%.Physics.Density,
radius = %OBJECT%.Physics.Radius,
categoryBits = %OBJECT%.Physics.CategoryBits,
maskBits = %OBJECT%.Physics.MaskBits,
groupIndex = %OBJECT%.Physics.GroupIndex
}
},
},
},
}

