Skip to content

Commit fa61e4b

Browse files
committed
Set a default frame for sprite sheets and atlases.
1 parent 92beff3 commit fa61e4b

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

v3/src/textures/Texture.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ var Texture = function (manager, key, source)
4848
*/
4949
this.frames = {};
5050

51+
this.firstFrame = '__BASE';
52+
5153
this.frameTotal = 0;
5254

5355
// Load the Sources
@@ -67,16 +69,25 @@ Texture.prototype = {
6769

6870
this.frames[name] = frame;
6971

72+
// Set the first frame of the Texture (other than __BASE)
73+
// This is used to ensure we don't spam the display with entire
74+
// atlases of sprite sheets, but instead just the first frame of them
75+
// should the dev incorrectly specify the frame index
76+
if (this.frameTotal === 1)
77+
{
78+
this.firstFrame = name;
79+
}
80+
7081
this.frameTotal++;
7182

7283
return frame;
7384
},
7485

7586
get: function (name)
7687
{
77-
if (name === undefined || name === null || this.frameTotal === 1)
88+
if (name === undefined || name === null)
7889
{
79-
name = '__BASE';
90+
name = (this.frameTotal === 1) ? '__BASE' : this.firstFrame;
8091
}
8192

8293
var frame = this.frames[name];

0 commit comments

Comments
 (0)