-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.js
More file actions
66 lines (56 loc) · 1.82 KB
/
Copy pathGame.js
File metadata and controls
66 lines (56 loc) · 1.82 KB
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
"use strict";
window.requestAnimationFrame = window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function (callback) {
window.setTimeout(callback, 1000 / 60);
};
function Game_Singleton () {
this.size = null;
this.gameWorld = null;
this._spritesStillLoading = 0;
};
Game_Singleton.prototype.start = function (divName, canvasName, x, y) {
this.size = new Vector2(x, y);
Canvas2D.initialize(divName, canvasName);
this.loadAssets();
this.assetLoadingLoop();
};
Game_Singleton.prototype.initialize = function () {
};
Game_Singleton.prototype.loadAssets = function () {
};
Game_Singleton.prototype.loadSprite = function (imageName) {
// console.log("Loading sprite: " + imageName);
var image = new Image();
image.src = imageName;
this._spritesStillLoading += 1;
image.onload = function () {
Game._spritesStillLoading -= 1;
};
return image;
}
Game_Singleton.prototype.loadImage = function (imageName) {
var image = new Image();
image = imageName;
return image;
};
Game_Singleton.prototype.assetLoadingLoop = function () {
if (Game._spritesStillLoading > 0) {
requestAnimationFrame(Game.assetLoadingLoop);
} else {
Game.initialize();
window.requestAnimationFrame(Game.loop)
}
};
Game_Singleton.prototype.loop = function () {
var delta = 1 / 60;
Game.gameWorld.handleInput(delta);
Game.gameWorld.update(delta);
Game.gameWorld.draw();
window.requestAnimationFrame(Game.loop)
// setTimeout(Game.loop, 1000 / 60)
};
var Game = new Game_Singleton();