Skip to content

Instantly share code, notes, and snippets.

@fritzy
Last active August 29, 2015 14:02
Show Gist options
  • Save fritzy/488162754a58e13443b4 to your computer and use it in GitHub Desktop.
Save fritzy/488162754a58e13443b4 to your computer and use it in GitHub Desktop.
A basic start to a pixi game.
function Game(somediv) {
this.stage = new PIXI.Stage(0xFFFFFF);
this.renderer = PIXI.autoDetectRenderer(800, 600);
somediv.appendChild(this.renderer.view);
this.lastframe = Date.now();
this.rocket = new Rocket(this);
this.update();
}
Game.protototype.update = function () {
requestAnimationFrame(this.update.bind(this));
var now = Date.now();
var frameMS = now - this.lastframe;
this.lastframe = now;
this.rocket.update(frameMS);
//loop through and update any other objects to deal with their
//individual logic and update their sprites positions
this.renderer.render(this.stage);
}
function Rocket(game) {
this.game = game;
this.sprite = PIXI.Sprite.fromImage("rocket.png");
this.game.stage.addChild(this.sprite);
}
Rocket.prototype.update = function (frameMS) {
//Some update to this.sprite.position scaled with frameMS
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment