小程序畫布開始創建一個路徑CanvasContext.beginPath
CanvasContext.beginPath()
開始創建一個路徑。需要調用 fill 或者 <code>stroke 才會使用路徑進行填充或描邊
小程序插件:支持
在最開始的時候相當于調用了一次 beginPath。
同一個路徑內的多次 setFillStyle、<code>setStrokeStyle、setLineWidth等設置,以最后一次設置為準。
示例代碼
const ctx = wx.createCanvasContext('myCanvas')
// begin path
ctx.rect(10, 10, 100, 30)
ctx.setFillStyle('yellow')
ctx.fill()
// begin another path
ctx.beginPath()
ctx.rect(10, 40, 100, 30)
// only fill this rect, not in current path
ctx.setFillStyle('blue')
ctx.fillRect(10, 70, 100, 30)
ctx.rect(10, 100, 100, 30)
// it will fill current path
ctx.setFillStyle('red')
ctx.fill()
ctx.draw()