【发布时间】:2016-12-15 16:57:25
【问题描述】:
initialize 方法被调用,但 render 方法没有被调用。 我在the fabricjs website 上阅读了有关子类化的信息,并查看了demo。 我真的不明白我的代码中缺少什么。
var CustomCircle = fabric.util.createClass(fabric.Object, {
type: "customCircle",
initialize: function (options) {
this.callSuper('initialize', options);
},
_render: function (ctx) {
ctx.beginPath();
ctx.arc(100, 250, 50, 0, 2 * Math.PI, false);
ctx.fillStyle = 'green';
ctx.fill();
ctx.lineWidth = 5;
ctx.strokeStyle = '#003300';
ctx.stroke();
}
});
var customCircle = new CustomCircle();
canvas.add(customCircle);
【问题讨论】:
-
如果我写 render 而不是 _render 似乎可以工作 - 我不明白为什么......
-
好的,我不确定这是修复还是技巧,但是如果我在创建 customCircle 时提到 with& height ,则调用 _render: new CustomCircle({width:1, height:1} );但是在代码中宽度为 1 和高度为 1 是无意义的,而 cercle 比这大得多......任何关于我所说的内容的 cmets 或答案都会很有用。谢谢!
-
嗨。你能解决这个问题吗?我现在遇到了同样的问题:/
-
我发布了解决方案