Reputation: 1966
I am creating page creation software online using amazing konva.js so the problem is when I was scaling the stage the whole elements are changing there position. Before scaling whole stage
After scaling the stage the line text is not in center.
the background at back is just rect having same width height of stage and having background image.
This is my scaling code.
function scaleboth(_x,_y){
stageBackgroundRect.scale({x:_x,y:_y});
stage.scale({x:_x,y:_y});
layer.batchDraw();
}
if you want to see demo here it is, https://mypagemaker.s3.amazonaws.com/index.html Thanks, I promise I will give bounty to correct answer.
function minusStage(){
stage.offsetX(stage.width() / 2);
stage.offsetY(stage.height() / 2);
scaleboth(stage.scaleX() - 0.01,stage.scaleY() - 0.01);
}
Upvotes: 0
Views: 1685
Reputation: 20298
Your background rectangle is inside a stage. So scaling the stage will affect the absolute scaling of all its children including the background rectangle.
You just need to apply scale once on one of the parents (it can be the stage).
Upvotes: 1