Jump to content

How to scale image, not sprite


bymafmaf
 Share

Recommended Posts

I'm making a game for mobile platforms and you know every phone and tablet has different screen area.

 

Scaling an image is only available for sprite as far as I'm concerned. Is there a way we can scale the image right after loaded, so that all sprites that use this image will use scaled version.

 

I want to scale it in this point:

this.load.image('logo', 'images/logo.png');
Link to comment
Share on other sites

Did you know you can display a preloaded Image as a sprite?

this.load.image('logo', 'images/logo.png);var logo = this.game.add.sprite(x , y, 'logo');logo.scale.setTo(1 , 1); // here is where you can scale your image. 1 , 1 is original size so you can make it twice as big with 2 , 2 or half the size with 0.5, 0.5
Link to comment
Share on other sites

Nothing like that is built-in to Phaser.

 

Have you tried adding a method to the Loader class that handles your case? "Phaser.Loader.prototype.scaledImage = function()..." or something similar? You'd probably also have to modify Loader#loadFile to handle the new type and run your scaling method.

Link to comment
Share on other sites

@jmp909 I have some images that should have fixed size no matter what device. So, extending sprite class wouldn't work for them.

surely you could implement the device/resolution check into your extended constructor, and therefore whenever you create a new sprite it does all the work behind the scenes to set it up correctly

Link to comment
Share on other sites

  • 5 months later...

Downscaling images before they are loaded into the cache would be incredibly useful, not just for dealing with mobile devices. If you are able to downscale images, you don't need to manually resize each of your (potentially) hundreds of assets whenever you want to change the scale of your game. Sure you could rescale the render to the same effect, but that has a huge impact on performance. Scaling the image before it makes it into the cache is the way to go. Unfortunately, I don't see a way to do this in phaser.  

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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