Skip to content

Instantly share code, notes, and snippets.

@Richtermeister
Created June 26, 2012 21:55
Show Gist options
  • Save Richtermeister/2999494 to your computer and use it in GitHub Desktop.
Save Richtermeister/2999494 to your computer and use it in GitHub Desktop.
Rendering stuff
function GameDisplay(ctx, renderer)
{
this.objects = new Array();
this.renderer = renderer;
this.addObject = function(object)
{
objects.push(Object);
}
this.updateDisplay= function()
{
for(var i in objects)
{
this.renderer.draw(objects[i]);
}
}
}
function RendererRegistry()
{
this.renderers = {};
this.registerObjectRenderer = function(objectType, renderer){
this.renderers[objectType] = renderer;
};
this.draw = function(object){
if(!this.renderers[typeof(object)]){
throw new Error('no renderer registered for type'+typeof(object));
}
this.renderers[typeof(object)].draw(object);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment