get pixel data, get runtime
parent
5316925a41
commit
22955eefab
|
@ -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 {*}
|
||||
|
|
|
@ -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 );
|
||||
|
||||
|
|
|
@ -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');
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue