Game Development Reference
In-Depth Information
erencing some DOM element, along with its accompanying context reference, we
encapsulate the canvas element, the JavaScript reference to it, and the reference to
the rendering context all inside a single object.
// Namespace the canvas abstraction
var Packt = Packt || {};
// Construct a canvas of an arbitrary size
Packt.Canvas = function(w, h) {
var width = w;
var height = h;
var canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
var ctx = canvas.getContext("2d");
this.getCanvas = function() {
return canvas;
};
this.getContext = function() {
return ctx;
};
this.getWidth = function() {
return width;
};
this.getHeight = function() {
return height;
};
// Allow the client to clear the entire
rendering buffer without
// needing to know how things are done under
the hood, andwithout
Search WWH ::




Custom Search