Add GameWindow.cameraPosition
@@ -19,6 +19,7 @@ var GameInput =
19
19
g_middleMouseDown: false,
20
20
g_middleMouseDownThisFrame: false,
21
21
22
trueMousePosition: new vector(0, 0),
22
23
mousePosition: new vector(0, 0),
23
24
24
25
MouseButtons: {
@@ -46,17 +47,29 @@ var GameInput =
46
47
47
48
document.onmouseup = function(e)
48
49
{
49
GameInput.g_mouseDownThisFrame = false;
50
GameInput.g_mouseDown = false;
50
switch(e.button)
51
{
52
case GameInput.MouseButtons.Left:
53
GameInput.g_mouseDownThisFrame = false;
54
GameInput.g_mouseDown = false;
55
break;
56
case GameInput.MouseButtons.Middle:
57
GameInput.g_middleMouseDownThisFrame = false;
58
GameInput.g_middleMouseDown = false;
59
break;
60
case GameInput.MouseButtons.Right:
61
GameInput.g_altMouseDownThisFrame = false;
62
GameInput.g_altMouseDown = false;
63
break;
64
}
51
65
}
52
66
53
67
document.onmousemove = function(e)
54
68
{
55
GameInput.mousePosition.x = e.x + GameWindow.x;
56
GameInput.mousePosition.y = e.y + GameWindow.y;
69
GameInput.trueMousePosition.x = e.x + GameWindow.x;
70
GameInput.trueMousePosition.y = e.y + GameWindow.y;
57
71
}
58
72
59
60
73
var el = document.getElementsByTagName("canvas")[0];
61
74
el.addEventListener("touchstart", function(){GameInput.g_mouseDownThisFrame = true;}, false);
62
75
el.addEventListener("touchend", function(){GameInput.g_mouseDownThisFrame = false;GameInput.g_mouseDown = false;}, false);
@@ -76,6 +89,8 @@ var GameInput =
76
89
77
90
g_updateKeys: function()
78
91
{
92
GameInput.mousePosition = GameInput.trueMousePosition.subtract(GameWindow.cameraPosition);
93
79
94
GameInput.g_pKeyStatus = GameInput.g_keyStatus;
80
95
GameInput.g_ppressKeyStatus = GameInput.g_pressKeyStatus;
81
96
GameInput.g_pressKeyStatus = [];
@@ -19,6 +19,7 @@ var GameInput =19
g_middleMouseDown: false,19
g_middleMouseDown: false,20
g_middleMouseDownThisFrame: false,20
g_middleMouseDownThisFrame: false,21
21
22
trueMousePosition: new vector(0, 0),22
mousePosition: new vector(0, 0),23
mousePosition: new vector(0, 0),23
24
24
MouseButtons: {25
MouseButtons: {@@ -46,17 +47,29 @@ var GameInput =46
47
47
document.onmouseup = function(e)48
document.onmouseup = function(e)48
{49
{49
GameInput.g_mouseDownThisFrame = false;50
switch(e.button)50
GameInput.g_mouseDown = false;51
{52
case GameInput.MouseButtons.Left: 53
GameInput.g_mouseDownThisFrame = false; 54
GameInput.g_mouseDown = false;55
break;56
case GameInput.MouseButtons.Middle: 57
GameInput.g_middleMouseDownThisFrame = false; 58
GameInput.g_middleMouseDown = false;59
break;60
case GameInput.MouseButtons.Right: 61
GameInput.g_altMouseDownThisFrame = false; 62
GameInput.g_altMouseDown = false;63
break;64
}51
}65
}52
66
53
document.onmousemove = function(e)67
document.onmousemove = function(e)54
{68
{55
GameInput.mousePosition.x = e.x + GameWindow.x;69
GameInput.trueMousePosition.x = e.x + GameWindow.x;56
GameInput.mousePosition.y = e.y + GameWindow.y;70
GameInput.trueMousePosition.y = e.y + GameWindow.y;57
}71
}58
72
59
60
var el = document.getElementsByTagName("canvas")[0];73
var el = document.getElementsByTagName("canvas")[0];61
el.addEventListener("touchstart", function(){GameInput.g_mouseDownThisFrame = true;}, false);74
el.addEventListener("touchstart", function(){GameInput.g_mouseDownThisFrame = true;}, false);62
el.addEventListener("touchend", function(){GameInput.g_mouseDownThisFrame = false;GameInput.g_mouseDown = false;}, false);75
el.addEventListener("touchend", function(){GameInput.g_mouseDownThisFrame = false;GameInput.g_mouseDown = false;}, false);@@ -76,6 +89,8 @@ var GameInput =76
89
77
g_updateKeys: function()90
g_updateKeys: function()78
{91
{92
GameInput.mousePosition = GameInput.trueMousePosition.subtract(GameWindow.cameraPosition);93
79
GameInput.g_pKeyStatus = GameInput.g_keyStatus;94
GameInput.g_pKeyStatus = GameInput.g_keyStatus;80
GameInput.g_ppressKeyStatus = GameInput.g_pressKeyStatus;95
GameInput.g_ppressKeyStatus = GameInput.g_pressKeyStatus;81
GameInput.g_pressKeyStatus = [];96
GameInput.g_pressKeyStatus = [];@@ -191,7 +191,10 @@ var GameObject =
191
191
{
192
192
if(this.renderer.image)
193
193
{
194
this.renderer.draw(this.transform.position.x, this.transform.position.y,
194
var offX = GameWindow.cameraPosition.x;
195
var offY = GameWindow.cameraPosition.y;
196
197
this.renderer.draw(this.transform.position.x + offX, this.transform.position.y + offY,
195
198
this.transform.width * this.transform.scale.x,
196
199
this.transform.height * this.transform.scale.y,
197
200
this.transform.rotation);
@@ -204,7 +207,6 @@ var GameObject =
204
207
{
205
208
if(this.draw)
206
209
{
207
208
210
this.draw();
209
211
}
210
212
else
@@ -191,7 +191,10 @@ var GameObject =191
{191
{192
if(this.renderer.image)192
if(this.renderer.image)193
{193
{194
this.renderer.draw(this.transform.position.x, this.transform.position.y, 194
var offX = GameWindow.cameraPosition.x;195
var offY = GameWindow.cameraPosition.y;196
197
this.renderer.draw(this.transform.position.x + offX, this.transform.position.y + offY, 195
this.transform.width * this.transform.scale.x, 198
this.transform.width * this.transform.scale.x, 196
this.transform.height * this.transform.scale.y, 199
this.transform.height * this.transform.scale.y, 197
this.transform.rotation);200
this.transform.rotation);@@ -204,7 +207,6 @@ var GameObject =204
{207
{205
if(this.draw)208
if(this.draw)206
{209
{207
208
this.draw();210
this.draw();209
}211
}210
else212
else@@ -9,6 +9,8 @@ var GameWindow =
9
9
10
10
g_width: 0,
11
11
g_height: 0,
12
13
cameraPosition: new vector(0, 0),
12
14
13
15
fullscreen: false,
14
16
@@ -40,10 +42,8 @@ var GameWindow =
40
42
//$("body").append('<div id="' + GameWindow.elementID + '" style="position: absolute; left: ' + x + 'px; top: ' + y + 'px; width: ' + GameWindow.width + 'px; height: ' + GameWindow.height + 'px; overflow: hidden; border: 1px solid black;"></div>');
41
43
GameWindow.windowElement = document.getElementById(GameWindow.elementID);
42
44
43
44
45
GameWindow.canvas = document.getElementById(GameWindow.elementID);
45
46
46
47
47
GameWindow.canvasContext = GameWindow.canvas.getContext('2d');
48
48
49
49
console.log("GAME: Window initialized: [" + width + ", " + height + "]");
@@ -9,6 +9,8 @@ var GameWindow =9
9
10
g_width: 0,10
g_width: 0,11
g_height: 0,11
g_height: 0,12
13
cameraPosition: new vector(0, 0),12
14
13
fullscreen: false,15
fullscreen: false,14
16
@@ -40,10 +42,8 @@ var GameWindow =40
//$("body").append('<div id="' + GameWindow.elementID + '" style="position: absolute; left: ' + x + 'px; top: ' + y + 'px; width: ' + GameWindow.width + 'px; height: ' + GameWindow.height + 'px; overflow: hidden; border: 1px solid black;"></div>');42
//$("body").append('<div id="' + GameWindow.elementID + '" style="position: absolute; left: ' + x + 'px; top: ' + y + 'px; width: ' + GameWindow.width + 'px; height: ' + GameWindow.height + 'px; overflow: hidden; border: 1px solid black;"></div>');41
GameWindow.windowElement = document.getElementById(GameWindow.elementID);43
GameWindow.windowElement = document.getElementById(GameWindow.elementID);42
44
43
44
GameWindow.canvas = document.getElementById(GameWindow.elementID);45
GameWindow.canvas = document.getElementById(GameWindow.elementID);45
46
46
47
GameWindow.canvasContext = GameWindow.canvas.getContext('2d');47
GameWindow.canvasContext = GameWindow.canvas.getContext('2d');48
48
49
console.log("GAME: Window initialized: [" + width + ", " + height + "]");49
console.log("GAME: Window initialized: [" + width + ", " + height + "]");