diff --git a/src/game-lib-a-2-utils.js b/src/game-lib-a-2-utils.js index 2d6b6e9..3af61c7 100644 --- a/src/game-lib-a-2-utils.js +++ b/src/game-lib-a-2-utils.js @@ -131,6 +131,21 @@ GameLib.Utils.ObjectPropertiesAsBoolean = function(object) { ); }; +GameLib.Utils.GetRuntime = function() { + + var result = null; + + GameLib.Event.Emit( + GameLib.Event.GET_RUNTIME, + null, + function(runtime) { + result = runtime; + } + ); + + return result; +}; + /** * Returns the window size or null * @returns {*} diff --git a/src/game-lib-image.js b/src/game-lib-image.js index 24234c3..615492e 100644 --- a/src/game-lib-image.js +++ b/src/game-lib-image.js @@ -149,6 +149,21 @@ GameLib.Image.prototype.updateFromInstance = function() { this.height = this.instance.height || 0; }; +GameLib.Image.prototype.getPixelData = function() { + + var canvas = document.createElement( 'canvas' ); + canvas.width = this.width; + canvas.height = this.height; + var context = canvas.getContext( '2d' ); + + context.drawImage(this.instance, 0, 0, canvas.width, canvas.height); + + var imageData = context.getImageData(0, 0, this.width, this.height); + var pixels = imageData.data; + + return pixels; +}; + /** * Returns an array of Height Data for this image * @returns {Float32Array | null} @@ -160,15 +175,7 @@ GameLib.Image.prototype.getHeightData = function() { return null; } - var canvas = document.createElement( 'canvas' ); - canvas.width = this.width; - canvas.height = this.height; - var context = canvas.getContext( '2d' ); - - context.drawImage(this.instance, 0, 0, canvas.width, canvas.height); - - var imageData = context.getImageData(0, 0, this.width, this.height); - var pixels = imageData.data; + var pixels = this.getPixelData(); var data = new Float32Array( this.width * this.height ); diff --git a/src/game-lib-renderer-a.js b/src/game-lib-renderer-a.js index 1466100..20e487f 100644 --- a/src/game-lib-renderer-a.js +++ b/src/game-lib-renderer-a.js @@ -150,3 +150,7 @@ GameLib.Renderer.prototype.toApiObject = function() { return apiRenderer; }; + +GameLib.Renderer.prototype.setSize = function(width, height) { + console.warn('please implement me in child class'); +}; diff --git a/src/game-lib-renderer-d2.js b/src/game-lib-renderer-d2.js index 79b7533..955b3fe 100644 --- a/src/game-lib-renderer-d2.js +++ b/src/game-lib-renderer-d2.js @@ -85,3 +85,10 @@ GameLib.Renderer.D2.prototype.toApiObject = function() { return apiRendererD2; }; + +/** + * set size + */ +GameLib.Renderer.D2.prototype.setSize = function(width, height) { + GameLib.Renderer.prototype.setSize.call(this); +};