2014-11-04 69 views
0

這裏是工作jsfiddle爲什麼這個標籤Polygon不起作用?

我正在繪製一個鑽石作爲一個多邊形,但它不工作..輸出應該是一個鑽石與藍色填充與中間的標籤「B」。

var labeledPolygon = new LabeledPolygon([ 
    {x: (xX), y: (yY+r)}, 
    {x: (xX+r), y: (yY)}, 
    {x: (xX+2*r), y: (yY+r)}, 
    {x: (xX+r), y: (yY+2*r)}], { 
     originX: 100, 
     originY: 100, 
     label: t, 
     fill: 'blue' 
    }); 
canvas.add(labeledPolygon); 

代碼中的座標後,不提前工作.. 感謝。

+0

檢查教程以獲取更多信息http://fabricjs.com/fabric-intro-part-3/#subclassing – Yogesh 2014-11-06 15:23:05

+0

還要檢查多邊形初始宣佈HTTP ://fabricjs.com/docs/fabric.Polygon.html#initialize – Yogesh 2014-11-06 15:34:29

回答

0

你的初始化方法只有「選項」作爲參數,但是你傳遞「polygonPoints」和「options」作爲參數。因此,你的初始化方法應該是這樣的

\t initialize: function (polygonPoints, options) { 
 
\t \t polygonPoints || (polygonPoints = {}); 
 
\t \t options || (options = {}); 
 

 
\t \t this.callSuper('initialize', polygonPoints, options); 
 
\t \t this.set('label', options.label || ''); 
 
\t },