我正在尝试将文字放入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 :(得分:0)
您可以像这样定位文本,这样您就不必提供x& y坐标。
text.setX( circle.getX() - text.getWidth()/2 );
text.setY( circle.getY() - text.getHeight()/2 );