mirror of
https://github.com/photonstorm/phaser
synced 2024-11-27 07:01:20 +00:00
Added more toJSON GameObject functions.
This commit is contained in:
parent
5eee8225bf
commit
81c6124a4d
6 changed files with 65 additions and 12 deletions
|
@ -1,4 +1,4 @@
|
|||
var CHECKSUM = {
|
||||
build: 'd62d2ed0-1f8b-11e7-b52d-db08b948d03e'
|
||||
build: 'dd446940-1fd6-11e7-b0f6-9b5f5f41e111'
|
||||
};
|
||||
module.exports = CHECKSUM;
|
|
@ -6,11 +6,9 @@ var ToJSON = function (gameObject)
|
|||
var out = {
|
||||
name: gameObject.name,
|
||||
type: gameObject.type,
|
||||
position: {
|
||||
x: gameObject.x,
|
||||
y: gameObject.y,
|
||||
z: gameObject.z
|
||||
},
|
||||
x: gameObject.x,
|
||||
y: gameObject.y,
|
||||
z: gameObject.z,
|
||||
scale: {
|
||||
x: gameObject.scaleX,
|
||||
y: gameObject.scaleY
|
||||
|
@ -19,23 +17,22 @@ var ToJSON = function (gameObject)
|
|||
x: gameObject.originX,
|
||||
y: gameObject.originY
|
||||
},
|
||||
flip: {
|
||||
x: gameObject.flipX,
|
||||
y: gameObject.flipY
|
||||
},
|
||||
flipX: gameObject.flipX,
|
||||
flipY: gameObject.flipY,
|
||||
rotation: gameObject.rotation,
|
||||
alpha: gameObject.alpha,
|
||||
visible: gameObject.visible,
|
||||
scaleMode: gameObject.scaleMode,
|
||||
blendMode: gameObject.blendMode,
|
||||
textureKey: '',
|
||||
frameKey: ''
|
||||
frameKey: '',
|
||||
data: {}
|
||||
};
|
||||
|
||||
if (gameObject.texture)
|
||||
{
|
||||
out.textureKey = gameObject.texture.key;
|
||||
out.frameKey = gameObject.frame.key;
|
||||
out.frameKey = gameObject.frame.name;
|
||||
}
|
||||
|
||||
return out;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
var Class = require('../utils/Class');
|
||||
var Components = require('../components');
|
||||
|
||||
/**
|
||||
* This is the base Game Object class that you can use when creating your own extended Game Objects.
|
||||
|
@ -37,6 +38,12 @@ var GameObject = new Class({
|
|||
{
|
||||
},
|
||||
|
||||
// Can be overridden by custom Game Objects, but provides default export functionality
|
||||
toJSON: function ()
|
||||
{
|
||||
return Components.ToJSON(this);
|
||||
},
|
||||
|
||||
destroy: function ()
|
||||
{
|
||||
this.parent.remove(this);
|
||||
|
|
|
@ -30,6 +30,7 @@ var BitmapText = new Class({
|
|||
|
||||
GameObject.call(this, state, 'BitmapText');
|
||||
|
||||
this.font = font;
|
||||
this.fontData = this.state.sys.cache.bitmapFont.get(font);
|
||||
|
||||
this.text = text;
|
||||
|
@ -76,6 +77,23 @@ var BitmapText = new Class({
|
|||
// global = the BitmapText, taking into account scale and world position
|
||||
|
||||
return GetBitmapTextSize(this);
|
||||
},
|
||||
|
||||
toJSON: function ()
|
||||
{
|
||||
var out = Components.ToJSON(this);
|
||||
|
||||
// Extra data is added here
|
||||
|
||||
var data = {
|
||||
font: this.font,
|
||||
text: this.text,
|
||||
fontSize: this.fontSize
|
||||
};
|
||||
|
||||
out.data = data;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -45,6 +45,15 @@ var Sprite = new Class({
|
|||
play: function (key, startFrame)
|
||||
{
|
||||
return this.anims.play(key, startFrame);
|
||||
},
|
||||
|
||||
toJSON: function ()
|
||||
{
|
||||
var data = Components.ToJSON(this);
|
||||
|
||||
// Extra Sprite data is added here
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -265,6 +265,28 @@ var Text = new Class({
|
|||
this.dirty = true;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
toJSON: function ()
|
||||
{
|
||||
var out = Components.ToJSON(this);
|
||||
|
||||
// Extra Text data is added here
|
||||
// TODO: TextStyle.toJSON
|
||||
|
||||
var data = {
|
||||
autoRound: this.autoRound,
|
||||
text: this.text,
|
||||
resolution: this.resolution,
|
||||
padding: {
|
||||
x: this.padding.x,
|
||||
y: this.padding.y
|
||||
}
|
||||
};
|
||||
|
||||
out.data = data;
|
||||
|
||||
return out;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue