在Facebook即时游戏中,与Phaser一起使用的区域大小合适吗

在Facebook即时游戏中,与Phaser一起使用的区域大小合适吗,facebook,phaser-framework,facebook-instant-games,Facebook,Phaser Framework,Facebook Instant Games,我正在用Phaser 2 CE对游戏进行编码,因此实际代码如下所示,但当我在移动设备或桌面上打开游戏时,图像不会显示在中间,而是隐藏起来 var game = new Phaser.Game(640, 480, Phaser.AUTO, 'game', { preload: preload, create: create, update: update }); var sprite; function preload () { // This is equivalent to <h

我正在用Phaser 2 CE对游戏进行编码,因此实际代码如下所示,但当我在移动设备或桌面上打开游戏时,图像不会显示在中间,而是隐藏起来

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() {

}
var game=new Phaser.game(640480,Phaser.AUTO,'game',{preload:preload,create:create,update:update});
雪碧;
函数预加载(){
//这相当于。
this.load.image('dude','assets/sprites/phaser dude.png');
}
函数create(){
sprite=game.add.sprite(game.world.centerX,game.world.centerY,'dude');
sprite.inputEnabled=true;
添加(myHandler,this);
}
函数myHandler(){
sprite.x+=10;
}
函数更新(){
}

进行搜索时,会出现一些相关问题 因此,您可以尝试这段代码,它工作正常,因为您根据设备窗口的内部属性创建了一个游戏,并使用SHOW_ALL对其进行缩放,这一切都很好,根据名为《相位器缩放管理器指南》的书,您可以在此处进行缩放

//如果使用PixelRatio,根据移动设备的分辨率,精灵将变小
PixelW=window.innerWidth;//*window.devicePixelRatio
PixelH=窗口的内部高度;//*window.devicePixelRatio
var game=new Phaser.game(PixelW,PixelH,Phaser.AUTO,'game',{preload:preload,create:create,update:update});
雪碧;
函数预加载(){
//这相当于。
this.load.image('dude','assets/sprites/phaser dude.png');
}
函数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;
添加(myHandler,this);
}
函数myHandler(){
sprite.anchor.setTo(0.5,0.5);
sprite.x=Math.floor(Math.random()*PixelW);
sprite.y=Math.floor(Math.random()*像素);
}
函数更新(){
}
//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() {

}