-
Notifications
You must be signed in to change notification settings - Fork 2
/
game.js
67 lines (53 loc) · 1.58 KB
/
game.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var game;
window.onload = function () {
var gameconfig = {
width: 1924,
height: 973,
scene: [bootGame, playGame]
}
game = new Phaser.Game(gameconfig);
this.window.focus();
resizeGame();
window.addEventListener("resize", resizeGame);
}
function resizeGame() {
var canvas = document.querySelector("canvas");
var windowWidth = window.innerWidth;
var windowHeight = window.innerHeight;
var windowRatio = windowWidth / windowHeight;
var gameRatio = game.config.width / game.config.height;
if (windowRatio < gameRatio) {
canvas.style.width = windowWidth + "px";
canvas.style.height = (windowWidth / gameRatio) + "px";
}
else {
canvas.style.width = (windowHeight * gameRatio) + "px";
canvas.style.height = windowHeight + "px";
}
}
/*******Classes to Control Scenes ********/
class playGame extends Phaser.Scene{
constructor(){
super("PlayGame")
}
create(){
console.log("this is great!");
var background = this.add.sprite(980, 485, 'background', 'background.png');
var donut = this.add.image(800, 600, 'donut', 'Donut.png');
donut;
background;
}
}
class bootGame extends Phaser.Scene{
constructor(){
super("BootGame");
}
preload(){
this.load.image('background', 'assets/background/background.png');
this.load.image('donut', 'assets/images/Donut.png');
}
create(){
console.log("Game is being loaded...");
this.scene.start("PlayGame");
}
}