get pixel data, get runtime

beta.r3js.org
-=yb4f310 2018-03-13 11:10:36 +01:00
parent 5316925a41
commit 22955eefab
4 changed files with 42 additions and 9 deletions

View File

@ -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 {*}

View File

@ -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 );

View File

@ -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');
};

View File

@ -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);
};