把文字放在Kinetic.Circle里面

时间:2013-08-08 15:58:01

标签: text canvas kineticjs geometry

我正在尝试将文字放入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);

任何想法如何实现这一点?

1 个答案:

答案 0 :(得分:0)

您可以像这样定位文本,这样您就不必提供x& y坐标。

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