2016-01-22 57 views
0

我有一個用phaser製作的遊戲,我們正在嘗試爲其添加全屏功能。當我打電話只是在Phaser中重置比例

this.game.scale.startFullScreen(false); 

它使遊戲maxHeight和maxWidth,因爲他們在預置設定要,所以它顯示了一個黑色的全屏幕中心的遊戲,所以我創造了它的包裝,它的工作原理,而不是當用戶點擊逃生而不是「退出全屏按鈕」時。啓動包裝將maxWidth和maxHeight設置爲null,然後允許全屏顯示,停止包裝將它們設置爲默認值,當您按下「退出全屏」按鈕時,它可以正常工作,但是當我打開它時調用我的功能,但不重置屏幕,因此它退出瀏覽器全屏模式,但仍比瀏覽器窗口更高。

這裏是我的全碼:

var startFullscreen = function() { 
    // remove maxwith and maxheight 
    game.scale.maxWidth = null; 
    game.scale.maxHeight = null; 

    // set to fullscreen 
    game.scale.startFullScreen(false); 
} 

var stopFullscreen = function() { 
    // reset maxWidth and maxHeight 
    game.scale.maxWidth = 1000; 
    game.scale.maxHeight = 600; 

    // turn off fullscreen 
    if (game.scale.isFullScreen) { // if the user hit escape, fullscreen is already exited and we only need to reset the scale 
     game.scale.stopFullScreen(); 
    } else { 
     // what goes here? 
    } 
} 

$(document).keyup(function (e) { 
    if (e.keyCode == 27) { // escape key maps to keycode `27` 
     stopFullscreen(); 
    } 
}); 

任何幫助表示讚賞。提前致謝!

+0

你試過這個:http://phaser.io/docs/2.4.4/Phaser.ScaleManager.html#refresh? – jolmos

回答

1

當我們進入全屏後,我將重置設置移動到了全屏後,這樣他們在退出全屏模式時已經設置好了,所以渲染正確,但我仍然樂於提供更好的解決方案。

var startFullscreen = function() { 
    // remove maxwith and maxheight 
    game.scale.maxWidth = null; 
    game.scale.maxHeight = null; 

    // set to fullscreen 
    game.scale.startFullScreen(false); 

    setTimeout(function() { 
     // resets height and width so the game will render correctly when fullscreen exits 
     game.scale.maxWidth = 1000; 
     game.scale.maxHeight = 600; 
    }, 500); 
}