Merge remote-tracking branch 'origin/master'

This commit is contained in:
Pavle Goloskokovic 2018-01-07 23:06:05 +01:00
commit 4be5209d8a
5 changed files with 79 additions and 20 deletions

View file

@ -216,8 +216,10 @@ var Group = new Class({
}
},
add: function (child)
add: function (child, addToScene)
{
if (addToScene === undefined) { addToScene = false; }
this.children.set(child);
if (this.createCallback)
@ -225,31 +227,72 @@ var Group = new Class({
this.createCallback.call(this, child);
}
return this;
},
addMultiple: function (children)
{
if (Array.isArray(children))
if (addToScene)
{
for (var i = 0; i < children.length; i++)
this.scene.sys.displayList.add(child);
if (child.preUpdate)
{
this.add(children[i]);
this.scene.sys.updateList.add(child);
}
}
return this;
},
remove: function (child)
addMultiple: function (children, addToScene)
{
this.children.delete(child);
if (addToScene === undefined) { addToScene = false; }
if (Array.isArray(children))
{
for (var i = 0; i < children.length; i++)
{
this.add(children[i], addToScene);
}
}
return this;
},
clear: function ()
remove: function (child, removeFromScene)
{
if (removeFromScene === undefined) { removeFromScene = false; }
this.children.delete(child);
if (removeFromScene)
{
this.scene.sys.displayList.remove(child);
if (child.preUpdate)
{
this.scene.sys.updateList.remove(child);
}
}
return this;
},
clear: function (removeFromScene)
{
if (removeFromScene === undefined) { removeFromScene = false; }
if (removeFromScene)
{
for (var i = 0; i < children.length; i++)
{
gameObject = children[i];
this.scene.sys.displayList.remove(gameObject);
if (gameObject.preUpdate)
{
this.scene.sys.updateList.remove(gameObject);
}
}
}
this.children.clear();
return this;

View file

@ -60,6 +60,10 @@ var CanvasRenderer = new Class({
// this.tintMethod = this.tintWithPerPixel;
this.snapshotCallback = null;
this.snapshotType = null;
this.snapshotEncoder = null;
this.init();
},
@ -278,16 +282,18 @@ var CanvasRenderer = new Class({
if (this.snapshotCallback)
{
this.snapshotCallback(CanvasSnapshot(this.gameCanvas));
this.snapshotCallback(CanvasSnapshot(this.gameCanvas, this.snapshotType, this.snapshotEncoder));
this.snapshotCallback = null;
}
// Add Post-render hook
},
snapshot: function (callback)
snapshot: function (callback, type, encoderOptions)
{
this.snapshotCallback = callback;
this.snapshotType = type;
this.snapshotEncoder = encoderOptions;
},
/**

View file

@ -1,6 +1,9 @@
var CanvasSnapshot = function (canvas)
var CanvasSnapshot = function (canvas, type, encoderOptions)
{
var src = canvas.toDataURL();
if (type === undefined) { type = 'image/png'; }
if (encoderOptions === undefined) { encoderOptions = 0.92; }
var src = canvas.toDataURL(type, encoderOptions);
var image = new Image();

View file

@ -1,5 +1,8 @@
var WebGLSnapshot = function (sourceCanvas)
var WebGLSnapshot = function (sourceCanvas, type, encoderOptions)
{
if (type === undefined) { type = 'image/png'; }
if (encoderOptions === undefined) { encoderOptions = 0.92; }
var gl = sourceCanvas.getContext('experimental-webgl');
var pixels = new Uint8Array(gl.drawingBufferWidth * gl.drawingBufferHeight * 4);
gl.readPixels(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
@ -31,7 +34,7 @@ var WebGLSnapshot = function (sourceCanvas)
ctx.putImageData(imageData, 0, 0);
var src = canvas.toDataURL();
var src = canvas.toDataURL(type, encoderOptions);
var image = new Image();
image.src = src;

View file

@ -109,6 +109,8 @@ var WebGLRenderer = new Class({
this.resourceManager = null;
this.currentRenderTarget = null;
this.snapshotCallback = null;
this.snapshotType = null;
this.snapshotEncoder = null;
this.scissor = {
enabled: false,
@ -536,7 +538,7 @@ var WebGLRenderer = new Class({
if (this.snapshotCallback)
{
this.snapshotCallback(WebGLSnapshot(this.view));
this.snapshotCallback(WebGLSnapshot(this.view, this.snapshotType, this.snapshotEncoder));
this.snapshotCallback = null;
}
@ -545,9 +547,11 @@ var WebGLRenderer = new Class({
// console.log('%c render end ', 'color: #ffffff; background: #ff0000;');
},
snapshot: function (callback)
snapshot: function (callback, type, encoderOptions)
{
this.snapshotCallback = callback;
this.snapshotType = type;
this.snapshotEncoder = encoderOptions;
},
createFBO: function () {},