Jump to content

Phaser and Facebook Instant Games scaling


Recommended Posts

Hi there.

Does anyone had a pleasure to build a Facebook Instant Game?

I've spent two days trying to scale my Phaser game in the Facebook for Android. Currently scaling works nicely on desktop, in a responsive viewport of the dev console, in the mobile Chrome -- namely everywhere, except the Facebook app. Seems like it just ignores my settings, sprites are displayed at full width, despite the canvas (and game) dimensions are correct.

Here are my init and boot scripts, the scaling logic is copypasted from a random gist:

// init code

FBInstant.initializeAsync().then(function() {

  FBInstant.startGameAsync().then(function() {
    /** Config part */
    var FIXED_SIZE    = 720;
    var FIXED_MEASURE = 'Width';

    /** Name mapping */
    var fixedName  = FIXED_MEASURE;
    var resName    = fixedName === 'Height' ? 'Width' : 'Height';
    var FIXED_NAME = fixedName.toUpperCase();
    var RES_NAME   = resName.toUpperCase();

    /** Measures of document */
    var documentElement = document.documentElement;
    var documentFixed   = window['inner' + fixedName];
    var documentRes     = window['inner' + resName];
    var ratio           = documentRes / documentFixed;

    /** Canvas measures */
    var canvasFixed = FIXED_SIZE;
    var canvasRes   = FIXED_SIZE * ratio;

    var screen = {};
    screen['CANVAS_' + FIXED_NAME] = canvasFixed;
    screen['CANVAS_' + RES_NAME] = canvasRes;


    game = new Phaser.Game(screen.CANVAS_WIDTH, screen.CANVAS_HEIGHT, Phaser.CANVAS);

    game.state.add('Boot', Boot);
    game.state.add('Preload', Preload);
    game.state.add('GameTitle', GameTitle);
    game.state.add('Main', Main);
    game.state.add('GameOver', GameOver);

    //Start the first state

// boot code
var Boot = function(game) {};

Boot.prototype = {
  preload: function() {

  create: function() {
    this.scale.scaleMode = Phaser.ScaleManager.EXACT_FIT;

    this.scale.pageAlignHorizontally = true;
    this.scale.pageAlignVertically = true;



Would appreciate any help!

Link to comment
Share on other sites

  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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