[ts][widget] Added transparent canvas widget support

This commit is contained in:
badlogic 2016-11-02 13:44:31 +01:00
parent 73beae2c15
commit 43efcaf373
9 changed files with 25 additions and 9 deletions

View File

@ -166,6 +166,7 @@ The configuration object has the following fields:
* `x`: optional, the x-coordinate to display the animation at. The origin is in the bottom left corner. Defaults to `0` if omitted. Irrelevant if `data-fit-to-canvas` is `true`. * `x`: optional, the x-coordinate to display the animation at. The origin is in the bottom left corner. Defaults to `0` if omitted. Irrelevant if `data-fit-to-canvas` is `true`.
* `y`: optional, the y-coordinate to display the animation at. The origin is in the bottom left corner with the y-axis pointing upwards. Defaults to `0` if omitted. Irrelevant if `data-fit-to-canvas` is `true`. * `y`: optional, the y-coordinate to display the animation at. The origin is in the bottom left corner with the y-axis pointing upwards. Defaults to `0` if omitted. Irrelevant if `data-fit-to-canvas` is `true`.
* `fitToCanvas`: optional, whether to fit the animation to the canvas size or not. Defaults to `true` if omitted, in which case `data-scale`, `data-x` and `data-y` are irrelevant. This setting calculates the setup pose bounding box using the specified skin to center and scale the animation on the canvas. * `fitToCanvas`: optional, whether to fit the animation to the canvas size or not. Defaults to `true` if omitted, in which case `data-scale`, `data-x` and `data-y` are irrelevant. This setting calculates the setup pose bounding box using the specified skin to center and scale the animation on the canvas.
* `alpha`: optional, whether to allow the canvas to be transparent. Defaults to `true`. Set the alpha channel in ``backgroundColor` to 0 as well, e.g. `#00000000`.
* `backgroundColor`: optional, the background color to use. Defaults to `#000000` if omitted. * `backgroundColor`: optional, the background color to use. Defaults to `#000000` if omitted.
* `premultipliedAlpha`: optional, whether the atlas pages use premultiplied alpha or not. Defaults to `false` if omitted. * `premultipliedAlpha`: optional, whether the atlas pages use premultiplied alpha or not. Defaults to `false` if omitted.
* `debug`: optional, whether to show debug information such as bones, attachments, etc. Defaults to `false` if omitted. * `debug`: optional, whether to show debug information such as bones, attachments, etc. Defaults to `false` if omitted.

View File

@ -1548,6 +1548,7 @@ declare module spine {
scale: number; scale: number;
x: number; x: number;
y: number; y: number;
alpha: boolean;
fitToCanvas: boolean; fitToCanvas: boolean;
backgroundColor: string; backgroundColor: string;
premultipliedAlpha: boolean; premultipliedAlpha: boolean;

View File

@ -7819,7 +7819,7 @@ var spine;
element.appendChild(canvas); element.appendChild(canvas);
canvas.width = element.clientWidth; canvas.width = element.clientWidth;
canvas.height = element.clientHeight; canvas.height = element.clientHeight;
var webglConfig = { alpha: false }; var webglConfig = { alpha: config.alpha };
var gl = this.gl = (canvas.getContext("webgl", webglConfig) || canvas.getContext("experimental-webgl", webglConfig)); var gl = this.gl = (canvas.getContext("webgl", webglConfig) || canvas.getContext("experimental-webgl", webglConfig));
this.shader = spine.webgl.Shader.newColoredTextured(gl); this.shader = spine.webgl.Shader.newColoredTextured(gl);
this.batcher = new spine.webgl.PolygonBatcher(gl); this.batcher = new spine.webgl.PolygonBatcher(gl);
@ -7868,6 +7868,8 @@ var spine;
config.premultipliedAlpha = false; config.premultipliedAlpha = false;
if (!config.debug === undefined) if (!config.debug === undefined)
config.debug = false; config.debug = false;
if (!config.alpha === undefined)
config.alpha = true;
this.backgroundColor.setFromString(config.backgroundColor); this.backgroundColor.setFromString(config.backgroundColor);
this.config = config; this.config = config;
}; };
@ -8030,6 +8032,8 @@ var spine;
config.premultipliedAlpha = widget.getAttribute("data-premultiplied-alpha") === "true"; config.premultipliedAlpha = widget.getAttribute("data-premultiplied-alpha") === "true";
if (widget.getAttribute("data-debug")) if (widget.getAttribute("data-debug"))
config.debug = widget.getAttribute("data-debug") === "true"; config.debug = widget.getAttribute("data-debug") === "true";
if (widget.getAttribute("data-alpha"))
config.alpha = widget.getAttribute("data-alpha") === "true";
new spine.SpineWidget(widget, config); new spine.SpineWidget(widget, config);
}; };
SpineWidget.ready = function () { SpineWidget.ready = function () {
@ -8062,6 +8066,7 @@ var spine;
this.scale = 1.0; this.scale = 1.0;
this.x = 0; this.x = 0;
this.y = 0; this.y = 0;
this.alpha = true;
this.fitToCanvas = true; this.fitToCanvas = true;
this.backgroundColor = "#555555"; this.backgroundColor = "#555555";
this.premultipliedAlpha = false; this.premultipliedAlpha = false;

File diff suppressed because one or more lines are too long

View File

@ -1478,6 +1478,7 @@ declare module spine {
scale: number; scale: number;
x: number; x: number;
y: number; y: number;
alpha: boolean;
fitToCanvas: boolean; fitToCanvas: boolean;
backgroundColor: string; backgroundColor: string;
premultipliedAlpha: boolean; premultipliedAlpha: boolean;

View File

@ -7398,7 +7398,7 @@ var spine;
element.appendChild(canvas); element.appendChild(canvas);
canvas.width = element.clientWidth; canvas.width = element.clientWidth;
canvas.height = element.clientHeight; canvas.height = element.clientHeight;
var webglConfig = { alpha: false }; var webglConfig = { alpha: config.alpha };
var gl = this.gl = (canvas.getContext("webgl", webglConfig) || canvas.getContext("experimental-webgl", webglConfig)); var gl = this.gl = (canvas.getContext("webgl", webglConfig) || canvas.getContext("experimental-webgl", webglConfig));
this.shader = spine.webgl.Shader.newColoredTextured(gl); this.shader = spine.webgl.Shader.newColoredTextured(gl);
this.batcher = new spine.webgl.PolygonBatcher(gl); this.batcher = new spine.webgl.PolygonBatcher(gl);
@ -7447,6 +7447,8 @@ var spine;
config.premultipliedAlpha = false; config.premultipliedAlpha = false;
if (!config.debug === undefined) if (!config.debug === undefined)
config.debug = false; config.debug = false;
if (!config.alpha === undefined)
config.alpha = true;
this.backgroundColor.setFromString(config.backgroundColor); this.backgroundColor.setFromString(config.backgroundColor);
this.config = config; this.config = config;
}; };
@ -7609,6 +7611,8 @@ var spine;
config.premultipliedAlpha = widget.getAttribute("data-premultiplied-alpha") === "true"; config.premultipliedAlpha = widget.getAttribute("data-premultiplied-alpha") === "true";
if (widget.getAttribute("data-debug")) if (widget.getAttribute("data-debug"))
config.debug = widget.getAttribute("data-debug") === "true"; config.debug = widget.getAttribute("data-debug") === "true";
if (widget.getAttribute("data-alpha"))
config.alpha = widget.getAttribute("data-alpha") === "true";
new spine.SpineWidget(widget, config); new spine.SpineWidget(widget, config);
}; };
SpineWidget.ready = function () { SpineWidget.ready = function () {
@ -7641,6 +7645,7 @@ var spine;
this.scale = 1.0; this.scale = 1.0;
this.x = 0; this.x = 0;
this.y = 0; this.y = 0;
this.alpha = true;
this.fitToCanvas = true; this.fitToCanvas = true;
this.backgroundColor = "#555555"; this.backgroundColor = "#555555";
this.premultipliedAlpha = false; this.premultipliedAlpha = false;

File diff suppressed because one or more lines are too long

View File

@ -14,13 +14,13 @@
<script> <script>
new spine.SpineWidget("spine-widget", { new spine.SpineWidget("spine-widget", {
json: "assets/spineboy.json", json: "assets/spineboy.json",
atlas: "assets/spineboy.atlas", atlas: "assets/spineboy.atlas",
animation: "run", animation: "run",
backgroundColor: "#000000", backgroundColor: "#00000000",
debug: true, debug: true,
success: function (widget) { success: function (widget) {
var animIndex = 0; var animIndex = 0;
widget.canvas.onclick = function () { widget.canvas.onclick = function () {
animIndex++; animIndex++;
let animations = widget.skeleton.data.animations; let animations = widget.skeleton.data.animations;
if (animIndex >= animations.length) animIndex = 0; if (animIndex >= animations.length) animIndex = 0;

View File

@ -66,7 +66,7 @@ module spine {
(<HTMLElement> element).appendChild(canvas); (<HTMLElement> element).appendChild(canvas);
canvas.width = (<HTMLElement>element).clientWidth; canvas.width = (<HTMLElement>element).clientWidth;
canvas.height = (<HTMLElement>element).clientHeight; canvas.height = (<HTMLElement>element).clientHeight;
var webglConfig = { alpha: false }; var webglConfig = { alpha: config.alpha };
let gl = this.gl = <WebGLRenderingContext> (canvas.getContext("webgl", webglConfig) || canvas.getContext("experimental-webgl", webglConfig)); let gl = this.gl = <WebGLRenderingContext> (canvas.getContext("webgl", webglConfig) || canvas.getContext("experimental-webgl", webglConfig));
this.shader = spine.webgl.Shader.newColoredTextured(gl); this.shader = spine.webgl.Shader.newColoredTextured(gl);
@ -106,6 +106,7 @@ module spine {
} }
if (!config.premultipliedAlpha === undefined) config.premultipliedAlpha = false; if (!config.premultipliedAlpha === undefined) config.premultipliedAlpha = false;
if (!config.debug === undefined) config.debug = false; if (!config.debug === undefined) config.debug = false;
if (!config.alpha === undefined) config.alpha = true;
this.backgroundColor.setFromString(config.backgroundColor); this.backgroundColor.setFromString(config.backgroundColor);
this.config = config; this.config = config;
} }
@ -272,6 +273,7 @@ module spine {
if (widget.getAttribute("data-background-color")) config.backgroundColor = widget.getAttribute("data-background-color"); if (widget.getAttribute("data-background-color")) config.backgroundColor = widget.getAttribute("data-background-color");
if (widget.getAttribute("data-premultiplied-alpha")) config.premultipliedAlpha = widget.getAttribute("data-premultiplied-alpha") === "true"; if (widget.getAttribute("data-premultiplied-alpha")) config.premultipliedAlpha = widget.getAttribute("data-premultiplied-alpha") === "true";
if (widget.getAttribute("data-debug")) config.debug = widget.getAttribute("data-debug") === "true"; if (widget.getAttribute("data-debug")) config.debug = widget.getAttribute("data-debug") === "true";
if (widget.getAttribute("data-alpha")) config.alpha = widget.getAttribute("data-alpha") === "true";
new spine.SpineWidget(widget, config); new spine.SpineWidget(widget, config);
} }
@ -306,6 +308,7 @@ module spine {
scale = 1.0; scale = 1.0;
x = 0; x = 0;
y = 0; y = 0;
alpha = true;
fitToCanvas = true; fitToCanvas = true;
backgroundColor = "#555555"; backgroundColor = "#555555";
premultipliedAlpha = false; premultipliedAlpha = false;