Jump to content

SCALING PHASER GAME TO DIFFERENT MOBILE DEVICES


craidencool
 Share

Recommended Posts

Hey guys can you help me? How do you scale a phaser game through different android or ios devices. I tried the scale manage and used only the one game size which is 720x1024 and it has a part that is not included and I read that using the device aspect ratio could help this be done but I dont know how to implement this.. I am still new so hope you can have the time to help me thank you! 

Link to comment
Share on other sites

var configuration = {
'canvas_width_max' : 2048,					
'canvas_width' : 1000,						
'canvas_height_max' : 2048,				
'canvas_height' : 650,						
'scale_ratio' : 1,							
'aspect_ratio' : 1,							
};

configuration.canvas_width = window.screen.availWidth * window.devicePixelRatio;
configuration.canvas_height = window.screen.availHeight * window.devicePixelRatio;
configuration.aspect_ratio = configuration.canvas_width / configuration.canvas_height;
if (configuration.aspect_ratio < 1) configuration.scale_ratio = configuration.canvas_height / configuration.canvas_height_max;
else configuration.scale_ratio = configuration.canvas_width / configuration.canvas_width_max;

game = new Phaser.Game(configuration.canvas_width, configuration.canvas_height, options.render, 'gamewindow');

this.game.scale.fullScreenScaleMode = Phaser.ScaleManager.SHOW_ALL;
this.game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
this.game.scale.refresh();

sprite.scale.set(configuration.scale_ratio);

 

Link to comment
Share on other sites

13 hours ago, VitaZheltyakov said:

var configuration = {
'canvas_width_max' : 2048,					
'canvas_width' : 1000,						
'canvas_height_max' : 2048,				
'canvas_height' : 650,						
'scale_ratio' : 1,							
'aspect_ratio' : 1,							
};

configuration.canvas_width = window.screen.availWidth * window.devicePixelRatio;
configuration.canvas_height = window.screen.availHeight * window.devicePixelRatio;
configuration.aspect_ratio = configuration.canvas_width / configuration.canvas_height;
if (configuration.aspect_ratio < 1) configuration.scale_ratio = configuration.canvas_height / configuration.canvas_height_max;
else configuration.scale_ratio = configuration.canvas_width / configuration.canvas_width_max;

game = new Phaser.Game(configuration.canvas_width, configuration.canvas_height, options.render, 'gamewindow');

this.game.scale.fullScreenScaleMode = Phaser.ScaleManager.SHOW_ALL;
this.game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
this.game.scale.refresh();

sprite.scale.set(configuration.scale_ratio);

 

Sir Im using tiled maps,  will this affect the output of your code? It is sort of running horizontally. thank you!

Link to comment
Share on other sites

  • 8 months later...
On 6/25/2016 at 5:31 AM, VitaZheltyakov said:

var configuration = {
'canvas_width_max' : 2048,					
'canvas_width' : 1000,						
'canvas_height_max' : 2048,				
'canvas_height' : 650,						
'scale_ratio' : 1,							
'aspect_ratio' : 1,							
};

configuration.canvas_width = window.screen.availWidth * window.devicePixelRatio;
configuration.canvas_height = window.screen.availHeight * window.devicePixelRatio;
configuration.aspect_ratio = configuration.canvas_width / configuration.canvas_height;
if (configuration.aspect_ratio < 1) configuration.scale_ratio = configuration.canvas_height / configuration.canvas_height_max;
else configuration.scale_ratio = configuration.canvas_width / configuration.canvas_width_max;

game = new Phaser.Game(configuration.canvas_width, configuration.canvas_height, options.render, 'gamewindow');

this.game.scale.fullScreenScaleMode = Phaser.ScaleManager.SHOW_ALL;
this.game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
this.game.scale.refresh();

sprite.scale.set(configuration.scale_ratio);

 

I work out the scale on my phones and Mac based on this. Thank you so much.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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