diff --git a/spine-ts/widget/src/Widget.ts b/spine-ts/widget/src/Widget.ts index 22d0fff58..4fe34f603 100644 --- a/spine-ts/widget/src/Widget.ts +++ b/spine-ts/widget/src/Widget.ts @@ -60,10 +60,14 @@ module spine { this.validateConfig(config); - let canvas = this.canvas = document.createElement("canvas"); + let existingCanvas = element.children[0]; + let canvas = this.canvas = existingCanvas || document.createElement("canvas"); canvas.style.width = "100%"; canvas.style.height = "100%"; - ( element).appendChild(canvas); + // only create a new canvas when one doesn't already exist + if (!existingCanvas) { + (element).appendChild(canvas); + } canvas.width = (element).clientWidth; canvas.height = (element).clientHeight; var webglConfig = { alpha: config.alpha }; @@ -235,10 +239,12 @@ module spine { private resize () { let canvas = this.canvas; - let w = canvas.clientWidth; - let h = canvas.clientHeight; let bounds = this.bounds; - if (canvas.width != w || canvas.height != h) { + let w = bounds.size.x; + let h = bounds.size.y; + // set canvas drawingBuffer equal to skeleton bounds (enables retina quality graphics) + // Math.floor is for matching how browsers round canvas size + if (canvas.width != Math.floor(w) || canvas.height != Math.floor(h)) { canvas.width = w; canvas.height = h; }