-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlagash_pong.js
70 lines (51 loc) · 1.53 KB
/
lagash_pong.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
"use strict";
var pressedKeys={};
var stage;
var renderer;
var width=800;
var height=500;
var resources;
var bola={};
function mainLoop(t)
{
//Inicializar el timer para que haga el siguiente llamado al
//main loop en el momento correcto
requestAnimationFrame(mainLoop);
//Dibujar en el renderer el estado actual de stage
renderer.render(stage);
}
function initGame()
{
//Creamos la bola
bola.spr=new PIXI.Sprite(resources.bola.texture);
stage.addChild(bola.spr);
//Bindeamos los eventos del teclado para mantener
//un objeto con el estado de las teclas
//http://keycode.info/
document.onkeydown=function(e) {pressedKeys[e.keyCode] = true;};
document.onkeyup=function(e) {delete pressedKeys[e.keyCode];};
}
//For local testing, enable x-requests
//In Chrome: --disable-web-security
function initLoader()
{
PIXI.loader.add('bola', 'img/bola.png');
PIXI.loader.add('paleta', 'img/paleta.png');
PIXI.loader.load(function (loader, res)
{
resources=res;
initGame();
mainLoop();
});
}
function initLagashPong()
{
//Inicializar el renderer (Webgl si es posible, sino fallback a canvas)
renderer = new PIXI.autoDetectRenderer(width, height);
renderer.backgroundColor=0;
//Crear un nuevo "stage" (Nodo root para el arbol de dibujado)
stage = new PIXI.Container();
//Agregar el renderer al DOM del document.
document.body.appendChild(renderer.view);
initLoader();
}