Skip to content

Commit 379b54b

Browse files
committed
Added TextureManager.addSpriteSheetFromAtlas and removed it from the Texture class.
1 parent a2ac0a2 commit 379b54b

2 files changed

Lines changed: 28 additions & 16 deletions

File tree

src/textures/Texture.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,6 @@ Phaser.Texture.prototype = {
8787

8888
},
8989

90-
getSpriteSheet: function (key, frame, frameWidth, frameHeight, startFrame, endFrame, margin, spacing)
91-
{
92-
var sheet = this.get(frame);
93-
94-
if (sheet)
95-
{
96-
var texture = this.manager.create(key, sheet.source.image);
97-
98-
this.manager.parsers.SpriteSheet(texture, 0, sheet.cutX, sheet.cutY, sheet.cutWidth, sheet.cutHeight, frameWidth, frameHeight, startFrame, endFrame, margin, spacing);
99-
100-
return texture;
101-
}
102-
},
103-
10490
/**
10591
* Destroys this base texture
10692
*

src/textures/TextureManager.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,21 @@ Phaser.TextureManager.prototype = {
110110
return texture;
111111
},
112112

113+
addSpriteSheetFromAtlas: function (key, atlasKey, atlasFrame, frameWidth, frameHeight, startFrame, endFrame, margin, spacing)
114+
{
115+
var atlas = this.get(atlasKey);
116+
var sheet = atlas.get(atlasFrame);
117+
118+
if (sheet)
119+
{
120+
var texture = this.create(key, sheet.source.image);
121+
122+
this.parsers.SpriteSheet(texture, 0, sheet.cutX, sheet.cutY, sheet.cutWidth, sheet.cutHeight, frameWidth, frameHeight, startFrame, endFrame, margin, spacing);
123+
124+
return texture;
125+
}
126+
},
127+
113128
/*
114129
addAtlasStarlingXML: function (key, source, data)
115130
{
@@ -159,6 +174,17 @@ Phaser.TextureManager.prototype = {
159174

160175
},
161176

177+
setTexture: function (gameObject, key, frame)
178+
{
179+
if (this.list[key])
180+
{
181+
gameObject.texture = this.list[key];
182+
gameObject.frame = gameObject.texture.get(frame);
183+
}
184+
185+
return gameObject;
186+
},
187+
162188
/**
163189
* Passes all Textures to the given callback.
164190
*
@@ -185,8 +211,8 @@ Phaser.TextureManager.prototype = {
185211
},
186212

187213
/**
188-
* TODO: This should move to the WebGL Renderer class.
189-
*
214+
* TODO: This should move to the WebGL Renderer class.
215+
*
190216
* Removes the base texture from the GPU, useful for managing resources on the GPU.
191217
* A texture is still 100% usable and will simply be re-uploaded if there is a sprite on screen that is using it.
192218
*

0 commit comments

Comments
 (0)