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 itslayerproperty totrue.However, in order for this to work properly, you should create this
scaleCanvaslayer before all other layers, and then you can later change itsscaleproperty layer.BTW, the
scaleproperty that I'm using in my examples changes both thescaleXandscaleYproperties that you are using in yours; thescaleproperty simply exists for convenience.Finally, here is a working JSFiddle demo that implements all of this.