2012-08-09 18 views
0

大家好我是KineticJS的noob,我想知道如何更改屬性值。例如,對於在創建後一個矩形:KineticJS在創建對象後更改屬性(NOOB)

var rect = new Kinetic.Rect({ 
      x: 239, 
      y: 75, 
      width: 100, 
      height: 50, 
      fill: "#00D2FF", 
      stroke: "black", 
      strokeWidth: 4 
     }); 

我怎麼會做這樣的事情:

rect.NewProperty({ 
     x: 100, 
     y: 30, 
     width: 100, 
     height: 50, 
     fill: "#cccccc", 
    }); 

,並保留其他屬性不變?

回答

2

像這樣:

var rect = new Kinetic.Rect({ 
      x: 239, 
      y: 75, 
      width: 100, 
      height: 50, 
      fill: "#00D2FF", 
      stroke: "black", 
      strokeWidth: 4 
     }); 

rect.setFill("#D200FF"); 
rect.setStrokeWidth(1); 
+0

感謝您的回答。所以正如我所提到的,我必須添加單詞「set」,並且所有內容都一樣嗎?例如.setWidth,.setStroke,setHeight,.setX,setY ... – Irakli 2012-08-09 12:47:36

1

感謝信息..

我也嘗試

rect.setWidth(100); 

rect.setHeight(100); 

工程:)