2012-05-24 3 views
1

내 게임에 다음과 같은 서클이 있습니다. 플레이어는 그들을 게임의 다른 위치로 드래그합니다. 플레이어가 다시 선택하면 init 함수에 지정된 원래 위치로 모양을 되돌리려합니다. 이 문제를 어떻게 해결해야합니까? 고맙습니다. 별도의 변수에KineticJS로 기본 위치로 재설정

stage = new Kinetic.Stage({ 
    container: "container", 
    width: 900, 
    height: 550 
}); 

shapes = new Kinetic.Layer(); 

function init() { 
    circle1 = new Kinetic.Circle({ 
    x: stage.getWidth()/3.2, 
    y: stage.getHeight()/3.2, 
    radius: radius, 
    fill: "blue", 
    stroke: "black", 
    strokeWidth: 4, 
    name: "circle", 
    draggable: true 
}); 

shapes.add(circle1) 
stage.add(shapes) 

답변

2

저장소 기본값, 다음을 다시 .setPosition(x, y)를 사용

//store settings 
var settings = { 
    x: stage.getWidth()/3.2, 
    y: stage.getHeight()/3.2, 
    radius: radius, 
    fill: "blue", 
    stroke: "black", 
    strokeWidth: 4, 
    name: "circle", 
    draggable: true 
}; 

//use settings 
circle1 = new Kinetic.Circle(settings); 

//after move, reset using: 
circle1.setPosition(settings.x,settings.y); 
2

하기이 같은 슈퍼 편리한 setAttrs 방법을 사용할 수 있습니다 :

circle1.setAttrs(settings); 

건배!

0

나는이 질문이 상당히 오래되었다는 것을 알고 있지만 방금 이런 식으로 해결했다.

stage.removeChildren(); 
stage.setAttrs(stage.defaultNodeAttrs); 

더 이상 stage.reset()이 작동하지 않지만 원하는대로해야합니다.

관련 문제