bymafmaf Posted November 16, 2015 Share Posted November 16, 2015 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 More sharing options...
huggybear Posted November 16, 2015 Share Posted November 16, 2015 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 More sharing options...
jmp909 Posted November 17, 2015 Share Posted November 17, 2015 i think he wants to not have to scale every sprite individually that uses 'logo' i don't think that's possible.. well.. you could create extend sprite and have it always set its own scale to (2,2) etc on construction Link to comment Share on other sites More sharing options...
bymafmaf Posted November 17, 2015 Author Share Posted November 17, 2015 @huggybear I want to scale it in the preload step. @jmp909 I have some images that should have fixed size no matter what device. So, extending sprite class wouldn't work for them. Link to comment Share on other sites More sharing options...
drhayes Posted November 17, 2015 Share Posted November 17, 2015 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 More sharing options...
bymafmaf Posted November 17, 2015 Author Share Posted November 17, 2015 Wow, I see a lot of mobile games that are built with Phaser and none of them had scale problem for different device sizes? Or all of them had to go through what you said? Link to comment Share on other sites More sharing options...
drhayes Posted November 17, 2015 Share Posted November 17, 2015 I can't speak to that, and I haven't done any mobile dev with Phaser, so... no idea. Instead of scaling, you could conditionally load different images based on the device playing the game. That's probably more straight-forward anyway. ( = Link to comment Share on other sites More sharing options...
jmp909 Posted November 18, 2015 Share Posted November 18, 2015 @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 More sharing options...
ForgeableSum Posted May 4, 2016 Share Posted May 4, 2016 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 More sharing options...
Recommended Posts