Search code examples
kineticjs

how to reposition stage into initial place in kineticjs?


I am scaling stage using following code

var scale = stage.getScale();
    scale.x *= 1.5; //zoomFactor is a global variable
    scale.y *= 1.5;
    stage.setScale(scale);
    stage.setDraggable(true);
    stage.draw();

after dragging stage,now I want to reposition stage into initial position with initial scale value by,

    var scale = stage.getScale();
    scale.x=1;
    scale.y=1;
    stage.setScale(scale);        
    stage.x = 0;
    stage.y = 0;
    stage.draw();
    stage.setDraggable(false);

this code works good for resetting the scale value to initial value but stage is not moved to initial position, Is this correct or I need to make a change the code.

Thanks in advance


Solution

  • You can use the API functions !

      stage.x(0);
      stage.y(0);
    

    Or :

      stage.setX(0);
      stage.setY(0);