2013-08-08 3 views
1

Kinetic.Circle에서 원 안에 텍스트를 넣으려고하는데 올바른 대답을 찾을 수 없습니다. 나는 다음과 같은 코드를 가지고있다 :Kinetic.Circle 안에 텍스트 넣기

var circle = new Kinetic.Circle({ 
    x: 30, 
    y: stage.getHeight()/2, 
    radius: 20, 
    fill: 'red', 
    stroke: 'black', 
    strokeWidth: 2, 
}); 

var text = new Kinetic.Text({ 
    text: 'A', 
    fontSize: 10, 
    fontFamily: 'Calibri', 
    width: 5, 
    fill: '#000' 
}); 

layer.add(circle); 
layer.add(texto); 
stage.add(layer); 

어떤 아이디어를 이뤄내 길까?

+0

은 당신이 텍스트로는 x, y 위치를 부여하고 오타가되지 않은 ... 2 마지막 줄은'layer.add한다 (텍스트)' – Ani

+0

Y는 잘못이 layer.add해야 썼다 (본문); 당신 말이 맞아요.하지만 x, y를 써클 안에 넣기 위해서는 x, y 좌표를주지 않아야합니다. – alosatriani

+0

대답을 찾았습니다. 간단합니다 : layer.add (circle) .add (text); – alosatriani

답변

0

x & y 좌표를 제공하지 않아도되도록 텍스트를 배치 할 수 있습니다.

text.setX(circle.getX() - text.getWidth()/2); 
text.setY(circle.getY() - text.getHeight()/2);