2014-02-28 30 views
0

我有問題。我需要在畫布上繪製另一個邊框。如果我試試這個:在畫布上繪製另一個邊框

c2.beginPath(); 

c2.moveTo(0, 0); 

c2.lineTo(0, 100); 
c2.lineWidth = Number(sw) + 6; 
c2.strokeStyle = "red"; 
c2.stroke(); 
c2.lineTo(100, 100); 
c2.lineWidth = Number(sw) + 6; 
c2.strokeStyle = "#00ec11"; 
c2.stroke(); 
c2.lineTo(0, 100); 
c2.lineWidth = Number(ss) + 6; 
c2.strokeStyle = "red"; 
c2.stroke(); 
c2.closePath(); 
c2.lineWidth = Number(sw) + 6; 
c2.strokeStyle = "#00ec11"; 
c2.stroke(); 

c2.fill(); 

它不工作,因爲所有行都有綠色邊框。你可以幫我嗎?

---編輯: 我可以; t關閉補丁時,關閉我的線條杆這條線畫的形狀。當我關閉修補程序時,我的形狀不正確。梅比的另一個想法?

回答

0

c2.stroke();用當前的strokeStyle重繪整個路徑直到那個點。所以最後只會應用最後一種風格。

嘗試添加,隨後通過c2.closePath();每個c2.beginPath()c2.stroke()開始其可以有一個單獨的的StrokeStyle的新路徑。

例如:

c2.lineTo(0, 100); 
c2.lineWidth = Number(sw) + 6; 
c2.strokeStyle = "red"; 
c2.stroke(); 
c2.closePath(); 

c2.beginPath(); 
c2.moveTo(0, 100); 
c2.lineTo(100, 100); 
c2.lineWidth = Number(sw) + 6; 
c2.strokeStyle = "#00ec11"; 
c2.stroke(); 
c2.closePath(); 
. 
. 
.