Created
June 26, 2012 21:55
-
-
Save Richtermeister/2999494 to your computer and use it in GitHub Desktop.
Rendering stuff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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