小程序畫布開始創(chuàng)建一個路徑CanvasContext.beginPath
CanvasContext.beginPath()
開始創(chuàng)建一個路徑。需要調(diào)用 fill 或者 <code>stroke 才會使用路徑進(jìn)行填充或描邊
小程序插件:支持
在最開始的時候相當(dāng)于調(diào)用了一次 beginPath。
同一個路徑內(nèi)的多次 setFillStyle、<code>setStrokeStyle、setLineWidth等設(shè)置,以最后一次設(shè)置為準(zhǔn)。
示例代碼
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()
作者:大學(xué)生新聞網(wǎng) 來源:大學(xué)生新聞網(wǎng)