Skip to content

Commit ba4b4b9

Browse files
committed
Update SpriteBatch to work properly with Transform
1 parent a814b58 commit ba4b4b9

5 files changed

Lines changed: 29 additions & 25 deletions

File tree

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: '8e926790-de9d-11e6-bab6-b1cd883c1600'
2+
build: '791c9de0-df38-11e6-a5ba-6db6a9dcaab8'
33
};
44
module.exports = CHECKSUM;

v3/src/components/Transform.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -551,20 +551,20 @@ Transform.prototype = {
551551
var vert = this.glVertextData;
552552

553553
// Top Left Vert
554-
vert.x0 = (a * w1) + (c * h1) + tx;
555-
vert.y0 = (d * h1) + (b * w1) + ty;
554+
// vert.x0 = (a * w1) + (c * h1) + tx;
555+
// vert.y0 = (d * h1) + (b * w1) + ty;
556556

557557
// Top Right Vert
558-
vert.x1 = (a * w0) + (c * h1) + tx;
559-
vert.y1 = (d * h1) + (b * w0) + ty;
558+
// vert.x1 = (a * w0) + (c * h1) + tx;
559+
// vert.y1 = (d * h1) + (b * w0) + ty;
560560

561561
// Bottom Right Vert
562-
vert.x2 = (a * w0) + (c * h0) + tx;
563-
vert.y2 = (d * h0) + (b * w0) + ty;
562+
// vert.x2 = (a * w0) + (c * h0) + tx;
563+
// vert.y2 = (d * h0) + (b * w0) + ty;
564564

565565
// Bottom Left Vert
566-
vert.x3 = (a * w1) + (c * h0) + tx;
567-
vert.y3 = (d * h0) + (b * w1) + ty;
566+
// vert.x3 = (a * w1) + (c * h0) + tx;
567+
// vert.y3 = (d * h0) + (b * w1) + ty;
568568

569569
return vert;
570570
},

v3/src/gameobjects/image/ImageWebGLRenderer.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ var ImageWebGLRenderer = function (renderer, src, interpolationPercentage)
2020
var transform = src.transform;
2121

2222
renderer.spriteBatch.add(
23-
0, 0,
24-
frame.cutWidth, frame.cutHeight,
25-
0, 0, 1, 1,
23+
frame,
24+
transform._pivotX, transform._pivotY,
2625
transform.world.tx, transform.world.ty,
2726
transform._worldScaleX, transform._worldScaleY,
2827
transform._worldRotation

v3/src/renderer/webgl/batches/sprite/SpriteBatch.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ SpriteBatch.prototype = {
132132
return (this.vertexDataBuffer.getByteLength() >= this.vertexDataBuffer.getByteCapacity());
133133
},
134134

135-
add: function (x, y, width, height, umin, vmin, umax, vmax, translateX, translateY, scaleX, scaleY, rotation)
135+
add: function (frame, pivotX, pivotY, translateX, translateY, scaleX, scaleY, rotation)
136136
{
137137
this.manager.setBatch(this);
138138

@@ -141,11 +141,16 @@ SpriteBatch.prototype = {
141141
var vertexDataBuffer = this.vertexDataBuffer;
142142
var vertexBuffer = vertexDataBuffer.floatView;
143143
var vertexOffset = vertexDataBuffer.allocate(CONST.SPRITE_VERTEX_COMPONENT_COUNT * CONST.SPRITE_VERTEX_COUNT);
144+
var uvs = frame.uvs;
145+
var x = -pivotX;
146+
var y = -pivotY;
147+
var width = frame.width;
148+
var height = frame.height;
144149

145150
vertexBuffer[vertexOffset++] = x;
146151
vertexBuffer[vertexOffset++] = y;
147-
vertexBuffer[vertexOffset++] = umin;
148-
vertexBuffer[vertexOffset++] = vmin;
152+
vertexBuffer[vertexOffset++] = uvs.x0;
153+
vertexBuffer[vertexOffset++] = uvs.y0;
149154
vertexBuffer[vertexOffset++] = translateX;
150155
vertexBuffer[vertexOffset++] = translateY;
151156
vertexBuffer[vertexOffset++] = scaleX;
@@ -154,8 +159,8 @@ SpriteBatch.prototype = {
154159

155160
vertexBuffer[vertexOffset++] = x;
156161
vertexBuffer[vertexOffset++] = y + height;
157-
vertexBuffer[vertexOffset++] = umin;
158-
vertexBuffer[vertexOffset++] = vmax;
162+
vertexBuffer[vertexOffset++] = uvs.x1;
163+
vertexBuffer[vertexOffset++] = uvs.y1;
159164
vertexBuffer[vertexOffset++] = translateX;
160165
vertexBuffer[vertexOffset++] = translateY;
161166
vertexBuffer[vertexOffset++] = scaleX;
@@ -164,8 +169,8 @@ SpriteBatch.prototype = {
164169

165170
vertexBuffer[vertexOffset++] = x + width;
166171
vertexBuffer[vertexOffset++] = y + height;
167-
vertexBuffer[vertexOffset++] = umax;
168-
vertexBuffer[vertexOffset++] = vmax;
172+
vertexBuffer[vertexOffset++] = uvs.x2;
173+
vertexBuffer[vertexOffset++] = uvs.y2;
169174
vertexBuffer[vertexOffset++] = translateX;
170175
vertexBuffer[vertexOffset++] = translateY;
171176
vertexBuffer[vertexOffset++] = scaleX;
@@ -174,8 +179,8 @@ SpriteBatch.prototype = {
174179

175180
vertexBuffer[vertexOffset++] = x + width;
176181
vertexBuffer[vertexOffset++] = y;
177-
vertexBuffer[vertexOffset++] = umax;
178-
vertexBuffer[vertexOffset++] = vmin;
182+
vertexBuffer[vertexOffset++] = uvs.x3;
183+
vertexBuffer[vertexOffset++] = uvs.y3;
179184
vertexBuffer[vertexOffset++] = translateX;
180185
vertexBuffer[vertexOffset++] = translateY;
181186
vertexBuffer[vertexOffset++] = scaleX;

v3/src/textures/Frame.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,14 @@ Frame.prototype = {
221221
uvs.x0 = this.cutX / tw;
222222
uvs.y0 = this.cutY / th;
223223

224-
uvs.x1 = (this.cutX + this.cutWidth) / tw;
225-
uvs.y1 = this.cutY / th;
224+
uvs.x1 = this.cutX / tw;
225+
uvs.y1 = (this.cutY + this.cutHeight) / th;
226226

227227
uvs.x2 = (this.cutX + this.cutWidth) / tw;
228228
uvs.y2 = (this.cutY + this.cutHeight) / th;
229229

230-
uvs.x3 = this.cutX / tw;
231-
uvs.y3 = (this.cutY + this.cutHeight) / th;
230+
uvs.x3 = (this.cutX + this.cutWidth) / tw;
231+
uvs.y3 = this.cutY / th;
232232

233233
return this;
234234
},

0 commit comments

Comments
 (0)