我使用HTML5/CSS/JS製作遊戲。現在我有一個問題,我無法解決。 如何將遊戲縮放到任何屏幕分辨率?也許這很簡單,但不適合我。如何縮放遊戲視窗?
解決
var RATIO = 480/800; // Original ratio.
function resize() {
var DEVICE_WIDTH = window.innerWidth,
DEVICE_HEIGHT = window.innerHeight,
ratio = DEVICE_WIDTH/DEVICE_HEIGHT,
scale = 1;
// If window changes by height we calculate scale parameter fo width
if (ratio > RATIO) {
scale = DEVICE_HEIGHT/800; // Devide by original viewport height
} else { // If window changes by width we calculate scale parameter for height
scale = DEVICE_WIDTH/480; // Devide by original viewport width
}
}
// So, now you can continue make your game, but in draw method you have to multiply
// everything by this scale parameter (x and y coords, width and height)
希望它會幫助你這樣的人我:)
請仔細閱讀[如何創建一個最小的,完整的,並且可驗證的示例](http://stackoverflow.com/help/mcve) – choz