Skip to content

Commit e9b2250

Browse files
authored
Merge pull request phaserjs#4097 from Cirras/atlas-to-spritesheet-trimming
Improved trim handling for Spritesheets created from trimmed Texture Atlas Frames
2 parents 8a58cee + 82da94b commit e9b2250

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

src/textures/parsers/SpriteSheetFromAtlas.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,27 +117,33 @@ var SpriteSheetFromAtlas = function (texture, frame, config)
117117
{
118118
var destX = (leftRow) ? leftPad : 0;
119119
var destY = (topRow) ? topPad : 0;
120-
var destWidth = frameWidth;
121-
var destHeight = frameHeight;
120+
121+
var trimWidth = 0;
122+
var trimHeight = 0;
122123

123124
if (leftRow)
124125
{
125-
destWidth = leftWidth;
126+
trimWidth += (frameWidth - leftWidth);
126127
}
127-
else if (rightRow)
128+
129+
if (rightRow)
128130
{
129-
destWidth = rightWidth;
131+
trimWidth += (frameWidth - rightWidth);
130132
}
131133

132134
if (topRow)
133135
{
134-
destHeight = topHeight;
136+
trimHeight += (frameHeight - topHeight);
135137
}
136-
else if (bottomRow)
138+
139+
if (bottomRow)
137140
{
138-
destHeight = bottomHeight;
141+
trimHeight += (frameHeight - bottomHeight);
139142
}
140143

144+
var destWidth = frameWidth - trimWidth;
145+
var destHeight = frameHeight - trimHeight;
146+
141147
sheetFrame.cutWidth = destWidth;
142148
sheetFrame.cutHeight = destHeight;
143149

@@ -152,7 +158,7 @@ var SpriteSheetFromAtlas = function (texture, frame, config)
152158
}
153159
else if (rightRow)
154160
{
155-
frameX += rightRow;
161+
frameX += rightWidth;
156162
}
157163
else
158164
{

0 commit comments

Comments
 (0)