Jump to content

Phaser and Facebook Instant Games scaling


soupdawgie
 Share

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.setLoadingProgress(50);
  FBInstant.setLoadingProgress(100);

  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;

    console.log(screen.CANVAS_WIDTH);
    console.log(screen.CANVAS_HEIGHT);


    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
    game.state.start('Boot');
  });
});

// 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;

    this.game.scale.refresh();

    this.game.state.start("Preload");
  }
}

Would appreciate any help!

Link to comment
Share on other sites

  • 1 month later...
 Share

  • Recently Browsing   0 members

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