Skip to content

Commit 4473af2

Browse files
committed
Frames can now have customData stored in them, as well as the Textures. This is populated by all of the atlas data by default and can be added to, either in the JJSON source files or at run-time. Closes phaserjs#3165.
1 parent 7577f47 commit 4473af2

4 files changed

Lines changed: 64 additions & 0 deletions

File tree

src/textures/Frame.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ var Frame = new Class({
8080
*/
8181
this.centerY = Math.floor(height / 2);
8282

83+
/**
84+
* @property {number} pivotX - The horizontal pivot point of this Frame.
85+
*/
86+
this.pivotX = 0;
87+
88+
/**
89+
* @property {number} height - The vertical pivot point of this Frame.
90+
*/
91+
this.pivotY = 0;
92+
8393
/**
8494
* Is this frame is rotated or not in the Texture?
8595
* Rotation allows you to use rotated frames in texture atlas packing.
@@ -93,6 +103,9 @@ var Frame = new Class({
93103
// Over-rides the Renderer setting? -1 = use Renderer Setting, 0 = No rounding, 1 = Round
94104
this.autoRound = -1;
95105

106+
// Any Frame specific custom data can be stored here
107+
this.customData = {};
108+
96109
/**
97110
* The un-modified source frame, trim and UV data.
98111
*

src/textures/Texture.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ var Texture = new Class({
3636

3737
this.frames = {};
3838

39+
// Any additional data that was set in the source JSON (if any), or any extra data you'd like to store relating to this texture
40+
this.customData = {};
41+
3942
this.firstFrame = '__BASE';
4043

4144
this.frameTotal = 0;

src/textures/parsers/JSONArray.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
var Clone = require('../../utils/object/Clone');
2+
13
var JSONArray = function (texture, sourceIndex, json)
24
{
35
// Malformed?
@@ -9,6 +11,7 @@ var JSONArray = function (texture, sourceIndex, json)
911

1012
// Add in a __BASE entry (for the entire atlas)
1113
var source = texture.source[sourceIndex];
14+
1215
texture.add('__BASE', sourceIndex, 0, 0, source.width, source.height);
1316

1417
// By this stage frames is a fully parsed array
@@ -40,6 +43,27 @@ var JSONArray = function (texture, sourceIndex, json)
4043
newFrame.rotated = true;
4144
newFrame.updateUVsInverted();
4245
}
46+
47+
// Copy over any extra data
48+
newFrame.customData = Clone(src);
49+
}
50+
51+
// Copy over any additional data that was in the JSON to Texture.customData
52+
for (var dataKey in json)
53+
{
54+
if (dataKey === 'frames')
55+
{
56+
continue;
57+
}
58+
59+
if (Array.isArray(json[dataKey]))
60+
{
61+
texture.customData[dataKey] = json[dataKey].slice(0);
62+
}
63+
else
64+
{
65+
texture.customData[dataKey] = json[dataKey];
66+
}
4367
}
4468

4569
return texture;

src/textures/parsers/JSONHash.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
var Clone = require('../../utils/object/Clone');
2+
13
var JSONHash = function (texture, sourceIndex, json)
24
{
35
// Malformed?
@@ -9,6 +11,7 @@ var JSONHash = function (texture, sourceIndex, json)
911

1012
// Add in a __BASE entry (for the entire atlas)
1113
var source = texture.source[sourceIndex];
14+
1215
texture.add('__BASE', sourceIndex, 0, 0, source.width, source.height);
1316

1417
// By this stage frames is a fully parsed Object
@@ -40,6 +43,27 @@ var JSONHash = function (texture, sourceIndex, json)
4043
newFrame.rotated = true;
4144
newFrame.updateUVsInverted();
4245
}
46+
47+
// Copy over any extra data
48+
newFrame.customData = Clone(src);
49+
}
50+
51+
// Copy over any additional data that was in the JSON to Texture.customData
52+
for (var dataKey in json)
53+
{
54+
if (dataKey === 'frames')
55+
{
56+
continue;
57+
}
58+
59+
if (Array.isArray(json[dataKey]))
60+
{
61+
texture.customData[dataKey] = json[dataKey].slice(0);
62+
}
63+
else
64+
{
65+
texture.customData[dataKey] = json[dataKey];
66+
}
4367
}
4468

4569
return texture;

0 commit comments

Comments
 (0)