I have painted a canvas with different layers. If I zoom the canvas, then no longer correct positions. But I want to be able to zoom, without any postponements. The canvas itself is zoomed.
This is my function:
function zoomCanvas(diff){
$("#myCanvas").scaleCanvas({
x: 0, y: 0,
scaleX: diff, scaleY: diff
})
.drawLayers();
}
Because you are working with jCanvas layers on your canvas, the canvas needs to be scaled whenever layers are redrawn.
Therefore, you must make make your
scaleCanvas()
call into a jCanvas layer (yes, you can actually do this) by setting itslayer
property totrue
.However, in order for this to work properly, you should create this
scaleCanvas
layer before all other layers, and then you can later change itsscale
property layer.BTW, the
scale
property that I'm using in my examples changes both thescaleX
andscaleY
properties that you are using in yours; thescale
property simply exists for convenience.Finally, here is a working JSFiddle demo that implements all of this.