Pixi.js: Resizing canvas behind sprite texture regression in v5

Created on 3 May 2019  路  8Comments  路  Source: pixijs/pixi.js

Expected Behavior

Resizing a PIXI.Sprite to match a PIXI.Texture matching an underlying HTML5 Canvas.

v4.5.3 expected visual output

Current Behavior

In v4, whether intentionally or not, it visually works as expected. In v5 the functionality has regressed and the baseTexture size is not updated causing distortion in the image.

v5.0.0 visual regression

Steps to Reproduce

These are the steps currently in use for resizing; width is protected against being zero otherwise Chrome raises many errors.

let canvas = document.createElement("canvas");
let sprite = new PIXI.Sprite.from(canvas);
...
canvas.width = new_width > 0 ? new_width : 2;
sprite.texture.orig.width = new_width;
sprite.width = new_width;
sprite.texture.update();

The value of new_width may be fractional.

Environment

馃暦 Bug

All 8 comments

Viewing the texture via console.log in v4.5.3, dimensions appear correct,
4.5.3 - console dump
In v5.0.0 the width of baseTexture remains at original setting of 1408.
5.0.0 - console dump

Workaround: try something with sprite.texture.baseTexture.setSize

I'm preparing a fix.

Please try pixijs.download/dev-texture-canvas-update/pixi.js

I'll test it myself in several hours. Your case also allowed to solve another one, #5609

Updated, looks good, although it is emitting errors about the fractional sizes:

pixi.min.js:13520 Uncaught Error: Texture Error: frame does not fit inside the base Texture dimensions: X: 0 + 2827.56005859375 = 2827.56005859375 > 2827 or Y: 0 + 163 = 163 > 163
    at Texture.prototypeAccessors.frame.set (pixi.min.js:13520)
    at Texture.onBaseTextureUpdated (pixi.min.js:13238)
    at BaseTexture.emit (pixi.min.js:1119)
    at BaseTexture.update (pixi.min.js:11319)
    at Runner.emit (pixi.min.js:8991)
    at CanvasResource.update (pixi.min.js:10180)
    at CanvasResource.update (pixi.min.js:10361)
    at Texture.update (pixi.min.js:13217)
    at typr-combo-webgl-ticker.html?v29:485

My workaround is to floor (not round) the original texture size,

sprite.texture.orig.width = Math.floor(new_width);

fixed that too. You can omit setting width now,

Merged!

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ivanpopelyshev picture ivanpopelyshev  路  33Comments

Shadowstep33 picture Shadowstep33  路  23Comments

Lyoko-Jeremie picture Lyoko-Jeremie  路  28Comments

ppoliani picture ppoliani  路  24Comments

SukantPal picture SukantPal  路  27Comments