-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathengine.js
76 lines (55 loc) · 1.56 KB
/
engine.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
67
68
69
70
71
72
73
74
75
76
var ctx;
var canvas;
var player1;
var loopRunning = true;
//cargamos
function cargar(){
canvas = $("#myCanvas")[0];
ctx = canvas.getContext('2d');
canvas.addEventListener('mousemove', function(evt) {
var rect = canvas.getBoundingClientRect();
Key._mousePosition = {
x: evt.clientX - rect.left,
y: evt.clientY - rect.top
}
}, false);
canvas.addEventListener('mousedown',function(event){ Key.onMousedown(event, canvas.getBoundingClientRect()); }, false);
canvas.addEventListener('mouseup',function(event) { Key.onMouseup(event, canvas.getBoundingClientRect()); }, false);
//addListenerToObject(canvas);
sceneManager.addScene(scene1);
sceneManager.addScene(scene0);
sceneManager.activeScene(scene0.id);
sceneManager.currentScene.init();
//scene1.init();
//scene0.init();
player1 = new Player("inicial",96,216);
animloop();
}
function updateGame(){
//scene1.update();
sceneManager.currentScene.update();
// scene0.update();
// player1.update();
}
function drawGame(){
canvas.width = canvas.width;
//scene0.draw();
//scene1.draw();
sceneManager.currentScene.draw();
// player1.draw();
}
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function( callback ){
window.setTimeout(callback, 1000 / 60);
};
})();
function animloop(){
if(loopRunning){
requestAnimFrame(animloop);
updateGame();
drawGame();
}
}