diff --git a/src/Layer.js b/src/Layer.js index b9a8a5fc..2c546829 100644 --- a/src/Layer.js +++ b/src/Layer.js @@ -39,9 +39,7 @@ Kinetic.Layer.prototype = { this.afterDrawFunc = undefined; this.canvas = new Kinetic.Canvas(); this.canvas.getElement().style.position = 'absolute'; - this.canvas.getContext().type = 'scene'; - this.bufferCanvas = new Kinetic.Canvas(); - this.bufferCanvas.getContext().type = 'buffer'; + this.bufferCanvas = new Kinetic.Canvas(0, 0, true); // call super constructor Kinetic.Container.call(this, config); diff --git a/src/Node.js b/src/Node.js index a06485d5..5c40aa90 100644 --- a/src/Node.js +++ b/src/Node.js @@ -732,7 +732,7 @@ Kinetic.Node.prototype = { canvas = new Kinetic.Canvas(config.width, config.height); } else { - canvas = this.getStage().bufferCanvas; + canvas = this.getStage().canvas; canvas.clear(); } diff --git a/src/Stage.js b/src/Stage.js index b0934aba..745ff2a4 100644 --- a/src/Stage.js +++ b/src/Stage.js @@ -563,9 +563,7 @@ Kinetic.Stage.prototype = { this.attrs.container.appendChild(this.content); this.canvas = new Kinetic.Canvas(); - this.canvas.getContext().type = 'scene'; - this.bufferCanvas = new Kinetic.Canvas(); - this.bufferCanvas.getContext().type = 'buffer'; + this.bufferCanvas = new Kinetic.Canvas(0, 0, true); this._resizeDOM(); }, diff --git a/src/util/Canvas.js b/src/util/Canvas.js index c1012db8..b622697a 100644 --- a/src/util/Canvas.js +++ b/src/util/Canvas.js @@ -4,13 +4,16 @@ * @param {Number} width * @param {Number} height */ -Kinetic.Canvas = function(width, height) { +Kinetic.Canvas = function(width, height, isBuffer) { this.element = document.createElement('canvas'); this.context = this.element.getContext('2d'); // set dimensions this.element.width = width || 0; this.element.height = height || 0; + + // set type + this.context.type = isBuffer ? 'buffer' : 'scene'; }; Kinetic.Canvas.prototype = { diff --git a/tests/js/Test.js b/tests/js/Test.js index 89758f79..047444f5 100644 --- a/tests/js/Test.js +++ b/tests/js/Test.js @@ -72,8 +72,6 @@ Test.prototype = { // loop through modules for(var mod in modules) { - console.log('=================== ' + mod + ' TESTS ==================='); - var tests = modules[mod]; /* * if a test key has a star in front of it, then @@ -86,6 +84,13 @@ Test.prototype = { break; } } + }; + + // loop through modules + for(var mod in modules) { + console.log('=================== ' + mod + ' TESTS ==================='); + + var tests = modules[mod]; // loop through tests for(var key in tests) { diff --git a/tests/js/unit/nodeTests.js b/tests/js/unit/nodeTests.js index 73f331c2..8ceac0ef 100644 --- a/tests/js/unit/nodeTests.js +++ b/tests/js/unit/nodeTests.js @@ -622,7 +622,7 @@ Test.Modules.NODE = { clone.start(); }; imageObj.src = '../assets/scorpion-sprite.png'; - }, + }, 'node caching': function(containerId) { var stage = new Kinetic.Stage({ container: containerId, @@ -668,6 +668,8 @@ Test.Modules.NODE = { width: 500, height: 300, callback: function(imageObj) { + + //document.body.appendChild(imageObj) test(Kinetic.Type._isElement(imageObj), 'shape toImage() should be an image object'); var cachedShape = new Kinetic.Image({ @@ -694,6 +696,7 @@ Test.Modules.NODE = { } }); + /* group.toImage({ callback: function(imageObj) { test(Kinetic.Type._isElement(imageObj), 'group toImage() should be an image object'); @@ -709,6 +712,7 @@ Test.Modules.NODE = { test(Kinetic.Type._isElement(imageObj), 'stage toImage() should be an image object'); } }); + */ //document.body.appendChild(layer.bufferCanvas.element) },