Jump to content

Scaling pre-existing textures


waltsatan
 Share

Recommended Posts

Hi all,

I have to rework a large Phaser project and slightly adjust the scale on all the loaded pngs to properly display on a monitor that does not have a square pixel aspect ratio.   I could go in and set the scaleX of each sprite, but that would be a chore.  I worked out this possible solution instead: (eventually being applied to all the pngs)

//scale amount
var sx=0.9;
var sy=1;

//get texture and scale
var src = this.textures.get('png').getSourceImage();
var dst = this.textures.createCanvas('png-scaled', src.width * sx, src.height * sy);
var context=dst.getContext('2d');
context.scale(sx, sy);
dst.draw(0, 0, src);

//replace
this.textures.remove('png');
this.textures.renameTexture('png-scaled','png');

Is this the best approach to achieve this?  Are there any performance loses due to the texture now being a canvas and not the original png image?

Thanks!

 

Link to comment
Share on other sites

  • 3 weeks later...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...