【问题标题】:Put text Inside Kinetic.Circle将文本放入 Kinetic.Circle
【发布时间】:2013-08-08 15:58:01
【问题描述】:

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

请问有什么方法可以实现吗?

【问题讨论】:

  • 你没有给文本一个 x,y 位置并且有一个错字...最后第二行应该是layer.add(text)
  • 你写错了应该是 layer.add(text);你是对的,但我证明在圆圈内给出 x,y,应该有另一种方法来做到这一点,不给出 x,y 坐标。
  • 找到了答案,很简单:layer.add(circle).add(text);

标签: text canvas kineticjs geometry


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2011-11-19
    • 1970-01-01
    • 2011-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多