Skip to content

Commit 685a1da

Browse files
author
Andrew Start
committed
Fixed resolution issues with sprites.
1 parent e450702 commit 685a1da

File tree

8 files changed

+178
-142
lines changed

8 files changed

+178
-142
lines changed

bin/pixi.js

Lines changed: 117 additions & 88 deletions
Large diffs are not rendered by default.

bin/pixi.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/pixi.min.js

Lines changed: 9 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/pixi.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/sprites/Sprite.js

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ Object.defineProperties(Sprite.prototype, {
108108
width: {
109109
get: function ()
110110
{
111-
return this.scale.x * this.texture._frame.width;
111+
return this.scale.x * this.texture.width;
112112
},
113113
set: function (value)
114114
{
115-
this.scale.x = value / this.texture._frame.width;
115+
this.scale.x = value / this.texture.width;
116116
this._width = value;
117117
}
118118
},
@@ -126,11 +126,11 @@ Object.defineProperties(Sprite.prototype, {
126126
height: {
127127
get: function ()
128128
{
129-
return this.scale.y * this.texture._frame.height;
129+
return this.scale.y * this.texture.height;
130130
},
131131
set: function (value)
132132
{
133-
this.scale.y = value / this.texture._frame.height;
133+
this.scale.y = value / this.texture.height;
134134
this._height = value;
135135
}
136136
},
@@ -182,12 +182,12 @@ Sprite.prototype._onTextureUpdate = function ()
182182
// so if _width is 0 then width was not set..
183183
if (this._width)
184184
{
185-
this.scale.x = this._width / this.texture.frame.width;
185+
this.scale.x = this._width / this.texture.width;
186186
}
187187

188188
if (this._height)
189189
{
190-
this.scale.y = this._height / this.texture.frame.height;
190+
this.scale.y = this._height / this.texture.height;
191191
}
192192
};
193193

@@ -215,8 +215,8 @@ Sprite.prototype.getBounds = function (matrix)
215215
if(!this._currentBounds)
216216
{
217217

218-
var width = this._texture._frame.width;
219-
var height = this._texture._frame.height;
218+
var width = this._texture.width;
219+
var height = this._texture.height;
220220

221221
var w0 = width * (1-this.anchor.x);
222222
var w1 = width * -this.anchor.x;
@@ -430,16 +430,16 @@ Sprite.prototype._renderCanvas = function (renderer)
430430
dy = (texture.trim) ? texture.trim.y - this.anchor.y * texture.trim.height : this.anchor.y * -texture._frame.height;
431431
}
432432

433-
433+
var resolution = texture.baseTexture.resolution;
434434

435435
// Allow for pixel rounding
436436
if (renderer.roundPixels)
437437
{
438438
renderer.context.setTransform(
439-
wt.a,
440-
wt.b,
441-
wt.c,
442-
wt.d,
439+
wt.a / resolution,
440+
wt.b / resolution,
441+
wt.c / resolution,
442+
wt.d / resolution,
443443
(wt.tx * renderer.resolution) | 0,
444444
(wt.ty * renderer.resolution) | 0
445445
);
@@ -451,19 +451,17 @@ Sprite.prototype._renderCanvas = function (renderer)
451451
{
452452

453453
renderer.context.setTransform(
454-
wt.a,
455-
wt.b,
456-
wt.c,
457-
wt.d,
454+
wt.a / resolution,
455+
wt.b / resolution,
456+
wt.c / resolution,
457+
wt.d / resolution,
458458
wt.tx * renderer.resolution,
459459
wt.ty * renderer.resolution
460460
);
461461

462462

463463
}
464464

465-
var resolution = texture.baseTexture.resolution;
466-
467465
if (this.tint !== 0xFFFFFF)
468466
{
469467
if (this.cachedTint !== this.tint)
@@ -478,8 +476,8 @@ Sprite.prototype._renderCanvas = function (renderer)
478476
this.tintedTexture,
479477
0,
480478
0,
481-
width * resolution,
482-
height * resolution,
479+
width,
480+
height,
483481
dx * renderer.resolution,
484482
dy * renderer.resolution,
485483
width * renderer.resolution,
@@ -490,10 +488,10 @@ Sprite.prototype._renderCanvas = function (renderer)
490488
{
491489
renderer.context.drawImage(
492490
texture.baseTexture.source,
493-
texture.crop.x * resolution,
494-
texture.crop.y * resolution,
495-
width * resolution,
496-
height * resolution,
491+
texture.crop.x,
492+
texture.crop.y,
493+
width,
494+
height,
497495
dx * renderer.resolution,
498496
dy * renderer.resolution,
499497
width * renderer.resolution,

src/core/sprites/webgl/SpriteRenderer.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,13 @@ SpriteRenderer.prototype.render = function (sprite)
203203
var index = this.currentBatchSize * this.vertByteSize;
204204

205205
var worldTransform = sprite.worldTransform;
206+
207+
var resolution = texture.baseTexture.resolution;
206208

207-
var a = worldTransform.a;
208-
var b = worldTransform.b;
209-
var c = worldTransform.c;
210-
var d = worldTransform.d;
209+
var a = worldTransform.a / resolution;
210+
var b = worldTransform.b / resolution;
211+
var c = worldTransform.c / resolution;
212+
var d = worldTransform.d / resolution;
211213
var tx = worldTransform.tx;
212214
var ty = worldTransform.ty;
213215

src/core/textures/Texture.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,16 @@ function Texture(baseTexture, frame, crop, trim, rotate)
127127
{
128128
if (this.noFrame)
129129
{
130-
frame = new math.Rectangle(0, 0, baseTexture.width, baseTexture.height);
131-
132-
// if there is no frame we should monitor for any base texture changes..
133-
baseTexture.on('update', this.onBaseTextureUpdated, this);
130+
frame = new math.Rectangle(0, 0, baseTexture.realWidth, baseTexture.realHeight);
134131
}
135132
this.frame = frame;
136133
}
137134
else
138135
{
139136
baseTexture.once('loaded', this.onBaseTextureLoaded, this);
140137
}
138+
//we should monitor for any base texture changes in case the resolution is changed, etc.
139+
baseTexture.on('update', this.onBaseTextureUpdated, this);
141140

142141
/**
143142
* Fired when the texture is updated. This happens if the frame or the baseTexture is updated.
@@ -164,8 +163,10 @@ Object.defineProperties(Texture.prototype, {
164163

165164
this.noFrame = false;
166165

167-
this.width = frame.width;
168-
this.height = frame.height;
166+
var resolution = this.baseTexture.resolution;
167+
168+
this.width = frame.width / resolution;
169+
this.height = frame.height / resolution;
169170

170171

171172

@@ -180,8 +181,8 @@ Object.defineProperties(Texture.prototype, {
180181
if (this.trim)
181182
{
182183

183-
this.width = this.trim.width;
184-
this.height = this.trim.height;
184+
this.width = this.trim.width / resolution;
185+
this.height = this.trim.height / resolution;
185186
this._frame.width = this.trim.width;
186187
this._frame.height = this.trim.height;
187188
}
@@ -217,7 +218,7 @@ Texture.prototype.onBaseTextureLoaded = function (baseTexture)
217218
// TODO this code looks confusing.. boo to abusing getters and setterss!
218219
if (this.noFrame)
219220
{
220-
this.frame = new math.Rectangle(0, 0, baseTexture.width, baseTexture.height);
221+
this.frame = new math.Rectangle(0, 0, baseTexture.realWidth, baseTexture.realHeight);
221222
}
222223
else
223224
{
@@ -229,8 +230,15 @@ Texture.prototype.onBaseTextureLoaded = function (baseTexture)
229230

230231
Texture.prototype.onBaseTextureUpdated = function (baseTexture)
231232
{
232-
this._frame.width = baseTexture.width;
233-
this._frame.height = baseTexture.height;
233+
if(this.noFrame)
234+
{
235+
this._frame.width = baseTexture.realWidth;
236+
this._frame.height = baseTexture.realHeight;
237+
}
238+
else
239+
{
240+
this.frame = this._frame;
241+
}
234242

235243
this.emit('update', this);
236244
};

src/core/textures/TextureUvs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ module.exports = TextureUvs;
3131
*/
3232
TextureUvs.prototype.set = function (frame, baseFrame, rotate)
3333
{
34-
var tw = baseFrame.width;
35-
var th = baseFrame.height;
34+
var tw = baseFrame.realWidth;
35+
var th = baseFrame.realHeight;
3636

3737
if(rotate)
3838
{

0 commit comments

Comments
 (0)