From 0b51dd67c5fadcd3919ade6b22c4c521daa61859 Mon Sep 17 00:00:00 2001 From: Schahriar SaffarShargh Date: Mon, 9 Nov 2015 02:21:05 -0800 Subject: [PATCH] Ensure passed canvas abides by render options Engine.create takes a canvas element or creates a new canvas using the given options. While the properties width and height in options do apply to the created canvas, they do not apply to the passed canvas. These set options are under render.canvas, render.options.width and render.options.height. This issue was fixed by setting the canvas width and height only when a canvas element is directly provided. --- src/render/Render.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/render/Render.js b/src/render/Render.js index f2ee31a..31f9fb3 100644 --- a/src/render/Render.js +++ b/src/render/Render.js @@ -64,6 +64,10 @@ var Grid = require('../collision/Grid'); var render = Common.extend(defaults, options); + if(render.canvas) { + render.canvas.width = render.options.width || render.canvas.width; + render.canvas.height = render.options.height || render.canvas.height; + } render.canvas = render.canvas || _createCanvas(render.options.width, render.options.height); render.context = render.canvas.getContext('2d'); render.textures = {};