new b5.Xoml(app){b5.Xoml}
The Xoml class loads XOML format JSON (exported from the Booty5 game editor) and turns it into Booty5 compatible objects
Xoml format data looks as follows:
b5.data.globals = [
{
"RT": "Geometry",
"N": "rect3762",
"GT": "Poly",
"A": false,
"V": [-126.336,-106.399, -42.018,-90.992, 153.614,46.411, -66.468,106.4, -153.614,-7.28]
},
{
"RT": "Shape",
"N": "rect3761",
"ST": "Polygon",
"W": 0,
"H": 0,
"A": false,
"V": [-126.336,-106.399, -42.018,-90.992, 153.614,46.411, -66.468,106.4, -153.614,-7.28]
}
];
Examples
Example showing code that loads JSON and converts it to Booty5 objects:
// Create XOML loader
var xoml = new b5.Xoml(app);
// Parse and create global resources placing them into the app
xoml.parseResources(app, xoml_globals);
Example showing how to dynamically create an actor from XOML template
var app = b5.app;
// This scene will receive a copy of ball object
var game_scene = app.findScene("gamescene");
// Search Xoml gamescene for ball icon actor resource
var ball_template = b5.Xoml.findResource(b5.data.gamescene, "ball", "icon");
// Create ball from the Xoml template and add it to game_scene
var xoml = new b5.Xoml(app);
xoml.current_scene = game_scene; // Xoml system needs to know current scene so it knows where to look for dependent resources
var ball = xoml.parseResource(game_scene, ball_template);
ball.setPosition(0, -350);
ball.vx = 4;
ball.fill_style = "rgb(" + ((Math.random() * 255) << 0) + "," + ((Math.random() * 255) << 0) + "," + ((Math.random() * 255) << 0) + ")";
For a complete overview of XOML see Booty5 XOML Overview
Name | Type | Description |
---|---|---|
app |
(b5.App) The main app |
Returns:
Type | Description |
---|---|
b5.Xoml | The created Xoml parser |
Methods
-
staticb5.Xoml.findResource(objects, name, type){object}
core/xoml.js, line 855 -
Searches the XOML resource collection to find a specific resource
Name Type Description objects
object The XOML JSON object
name
string The namke of the resource / object to find
type
string Type of resource / object (Scene, Brush, Image, Sound, Shape, Material, Icon, label)
Returns:
Type Description object The found object or null if not found -
parseResource(parent, resource){object}
core/xoml.js, line 824 -
Parses a specific XOML JSON resource and instantiates all Booty5 objects that it contains
Name Type Description parent
object Object that will receive the created objects, for example the app or a scene
resource
object XOML JSON object to parse
Returns:
Type Description object Created object (may also contain sub objects / resources) -
parseResources(parent, resource)
core/xoml.js, line 811 -
Recursively parses all XOML JSON resource instantiating all Booty5 objects that it contains
Name Type Description parent
object Object that will receive the created objects, for example the app or a scene
resource
object XOML JSON object to parse