Skip to content

Commit 5eee822

Browse files
committed
Added ToJSON Game Object component.
1 parent 929d6fc commit 5eee822

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

v3/src/components/ToJSON.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Default Game Object JSON export
2+
// Is extended further by Game Object specific implementations
3+
4+
var ToJSON = function (gameObject)
5+
{
6+
var out = {
7+
name: gameObject.name,
8+
type: gameObject.type,
9+
position: {
10+
x: gameObject.x,
11+
y: gameObject.y,
12+
z: gameObject.z
13+
},
14+
scale: {
15+
x: gameObject.scaleX,
16+
y: gameObject.scaleY
17+
},
18+
origin: {
19+
x: gameObject.originX,
20+
y: gameObject.originY
21+
},
22+
flip: {
23+
x: gameObject.flipX,
24+
y: gameObject.flipY
25+
},
26+
rotation: gameObject.rotation,
27+
alpha: gameObject.alpha,
28+
visible: gameObject.visible,
29+
scaleMode: gameObject.scaleMode,
30+
blendMode: gameObject.blendMode,
31+
textureKey: '',
32+
frameKey: ''
33+
};
34+
35+
if (gameObject.texture)
36+
{
37+
out.textureKey = gameObject.texture.key;
38+
out.frameKey = gameObject.frame.key;
39+
}
40+
41+
return out;
42+
};
43+
44+
module.exports = ToJSON;

v3/src/components/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports = {
1313
ScaleMode: require('./ScaleMode'),
1414
Size: require('./Size'),
1515
Texture: require('./Texture'),
16+
ToJSON: require('./ToJSON'),
1617
Transform: require('./Transform'),
1718
TransformMatrix: require('./TransformMatrix'),
1819
Visible: require('./Visible')

0 commit comments

Comments
 (0)