I noticed (actually, i got report from other people, i didn't even noticed, since my rMBP is hooked up to external monitor on work) that when you resize canvas and continue to draw on it, it gets all messy on retina displays
i was using code like this:
this.canvasElementObject.height(height);
this.canvasElementObject.width(width);
this.canvasElementObject.attr('height', height);
this.canvasElementObject.attr('width', width);
but after that the image became blurry, and i need to re-fetch the context with .getContext('2d') method
After that i added two more methods to my AMD class, which acts as a light wrapper around canvas object, this has fixed my issue, but i was wandering is there something we can do automatically, or is there some better way you think we should use in this kind of situations?
/**
* ----------------------------------------------------------
* this is needed for resize and HiDPI stuff
* ----------------------------------------------------------
*/
this.reInitCtx = function() {
this.ctx = this.canvasElement.getContext('2d');
};
/**
* ----------------------------------------------------------
* ----------------------------------------------------------
* @param {Number} width
* @param {Number} height
*/
this.safeResizeCanvas = function(width, height) {
this.canvasElementObject.height(height);
this.canvasElementObject.width(width);
this.canvasElementObject.attr('height', height);
this.canvasElementObject.attr('width', width);
this.reInitCtx();
};
FYI, canvasElement is a reference to DOM element, and canvasElementObject is jQery object.
Any feedback is appreciated, thanks!