What brings us to NTU to teach HTML5?
Why are we all using Mac?
Ask us more! ntu.question.gmail.com
function singleStepOfGameLoop() {
updateGameState();
drawEverything();
requestAnimationFrame(singleStepOfGameLoop);
}
// kick us off
singleStepOfGameLoop();
function singleStepOfGameLoop() {
var delta = getMsSinceLastUpdate()
while (delta > 16) {
updateGameState();
delta = delta - 16
}
drawEverything();
requestAnimationFrame(singleStepOfGameLoop);
}
// kick us off
singleStepOfGameLoop();
function emitParticle(x, y) {
var p = new Particle();
p.x = x;
p.y = y;
p.animate();
}
funtion ParticlePool() {
this.particles = []
for (var i = 0; i < 100; i++) {
particles[i] = new Particle();
}
}
ParticlePool.prototype.get = function() {
return this.particles.pop();
}
ParticlePool.prototype.release = function(particle) {
this.particles.push(particle);
}
function emitParticle(pool, x, y) {
var p = pool.get();
p.x = x;
p.y = y;
p.animate();
// return so we can release it later
return p;
}
// then sometime later
function onParticleComplete(pool, particle) {
pool.release(particle);
}
var img = new Image();
img.onload = function() { console.log('yay?'); }
img.src = 'http://fake.image.url/cats.png'
startGame();
function loadNextImage() {
if (count === waitingFor) {
startGame();
return;
}
var img = new Image();
img.src = getAnotherImageUrl();
img.onload = loadNextImage;
count++;
updateProgressBar(count);
}
// kick it off
loadNextImage();
function onLoadComplete() {
count++;
updateProgressBar(count);
if (count === waitingFor) {
startGame();
}
}
function loadImages() {
for (var i = 0; i < total; i++) {
var img = new Image();
img.src = getAnotherImageUrl();
img.onload = onLoadComplete;
}
}
Code: https://github.com/Mozilla-NTU/gamedev-2014-demos/tree/master/basic-lecture/basics