Skip to content

Instantly share code, notes, and snippets.

@osbulbul
Last active February 2, 2022 16:10
Show Gist options
  • Select an option

  • Save osbulbul/7727ed4ac99044cc12ad1c8c3157e11c to your computer and use it in GitHub Desktop.

Select an option

Save osbulbul/7727ed4ac99044cc12ad1c8c3157e11c to your computer and use it in GitHub Desktop.
//Lib
import Phaser from "phaser";
//Scenes
import playGame from "./playGame";
//Find the perfect ratio
let width = 720;
let height = 1280;
let perfectRatio = width / height;
//Find the current screen ratio
let innerWidth = window.innerWidth;
let innerHeight = window.innerHeight;
let actualRatio = innerWidth / innerHeight;
//Find the final width
width = Math.min(width*actualRatio/perfectRatio, 1280);
let gameConfig = {
type: Phaser.AUTO,
scale: {
mode: Phaser.Scale.FIT,
autoCenter: Phaser.Scale.CENTER_BOTH,
parent: 'jumpingbox',
width: width,
height: height
},
physics: {
default: 'arcade',
matter: {
gravity: {x:0, y:500},
debug: true
}
},
scene: playGame
};
let game = new Phaser.Game(gameConfig);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment