【问题标题】:What is the right size of the area in Facebook instant games to use it with PhaserFacebook 即时游戏中与 Phaser 一起使用的区域的正确大小是多少
【发布时间】:2019-08-25 08:02:46
【问题描述】:

我在 Phaser 2 CE 中编写游戏代码,所以实际代码如下:https://stackoverflow.com/a/50300726/2107253,但是当我在移动设备或桌面上打开游戏时,图像不会显示在中心并且被隐藏

var game = new Phaser.Game(640, 480, Phaser.AUTO, 'game', { preload: preload, create: create, update: update });
var sprite;

function  preload () {
  // This is equivalent to <https://examples.phaser.io/assets/>.
  this.load.image('dude', 'assets/sprites/phaser-dude.png');
}

function create() {
  sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'dude');
  sprite.inputEnabled = true;
  sprite.events.onInputDown.add(myHandler, this);
}

function myHandler() {
  sprite.x += 10;
}

function update() {

}

【问题讨论】:

    标签: facebook phaser-framework facebook-instant-games


    【解决方案1】:

    当您进行搜索时,有一些相关问题https://stackoverflow.com/a/49034911/2107253 所以你可以试试这个代码,它工作得很好,因为你根据设备窗口的内部属性创建了一个游戏,然后你用 SHOW_ALL 缩放它,这很好,根据名为 A Guide to the Phaser Scale Manager你可以在这里很好https://gumroad.com/photonstorm

    //If you use PixelRatio, the sprite will be smaller according to the resolution of the mobile device
    
    PixelW = window.innerWidth;// * window.devicePixelRatio
    PixelH = window.innerHeight;// * window.devicePixelRatio
    var game = new Phaser.Game(PixelW, PixelH, Phaser.AUTO, 'game', { preload: preload, create: create, update: update });
    
    var sprite;
    
    function  preload () {
      // This is equivalent to <https://examples.phaser.io/assets/>.
      this.load.image('dude', 'assets/sprites/phaser-dude.png');
    }
    
    function create() {
      game.stage.backgroundColor = 0x3b5998;
      game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
      sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'dude');
      sprite.inputEnabled = true;
      sprite.events.onInputDown.add(myHandler, this);
    }
    
    function myHandler() {
      sprite.anchor.setTo(0.5, 0.5);
      sprite.x = Math.floor(Math.random() * PixelW);
      sprite.y = Math.floor(Math.random() * PixelH);
    }
    
    function update() {
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-23
      • 2018-10-22
      • 2017-01-05
      • 1970-01-01
      相关资源
      最近更新 更多