2012-10-27 26 views

回答

1

我認爲文件在這方面有點過時。組沒有drawFunc,所以它們沒有寬度或高度。如果他們獲得寬度和高度,將可以創建剪輯組,這將是很好的。然而,就像現在這樣,組只是用來爲其中包含的對象定義一個相對的x和y起始座標。這使得可以立即移動多個對象(拖動,移動到,事件處理程序等),但這就是它。

JsFiddle as requested

var group = new Kinetic.Group({ 
    x: 220, 
    y: 40, 
    draggable: true 
}); 

只要讓您可拖動組和你的對象添加到組。

+0

我可以在jsfiddle中添加代碼以便一次移動多個對象。主要會有一個組中的圖像和錨點 – user1531437

0

下面的代碼將允許您創建一個具有剪輯屬性的組。 將其實例化爲一個組,其中寬度和高度就是您的裁剪框。

Kinetic.Clipper = function(config) { 
    this._initGroup(config); 
}; 
Kinetic.Clipper.prototype = { 
    _initGroup: function(config) { 
     this.nodeType = 'Group'; 
     Kinetic.Container.call(this, config); 
    }, 
    drawScene: function() { 
     if(this.isVisible()) { 

      var context = this.getLayer().getContext(); 
      var width = this.getWidth(), height = this.getHeight(); 
      context.save(); 
      context.beginPath(); 
      context.rect(0, 0, width, height); 
      context.clip(); 

      var children = this.children, len = children.length; 
      for(var n = 0; n < len; n++) { 
       children[n].drawScene(); 
      } 

      context.restore(); 
     } 
    }, 
}; 
Kinetic.Global.extend(Kinetic.Clipper, Kinetic.Container); 
+0

你可以在jsFiddle中放入一個例子嗎? – user1531437

+0

特別是一個例子,其中組不在(0,0),我無法工作。 –

0

文檔已過時或錯誤。 不可能直接改變組大小