
画布。2.9.0 起支持一套新 Canvas 2D 接口(需指定 type 属性),同时支持同层渲染。
Canvas 2D 示例代码
html:
<canvas type="2d" id="myCanvas"></canvas>
js:
// canvas.js Page({ onReady() { const query = wx.createSelectorQuery() query.select('#myCanvas') .fields({ node: true, size: true }) .exec((res) => { const canvas = res[0].node const ctx = canvas.getContext('2d') const dpr = wx.getSystemInfoSync().pixelRatio canvas.width = res[0].width * dpr canvas.height = res[0].height * dpr ctx.scale(dpr, dpr) ctx.fillRect(0, 0, 100, 100) }) } })
WebGL 示例代码:
html:
<canvas type="webgl" id="myCanvas"></canvas>
js:
// canvas.js Page({ onReady() { const query = wx.createSelectorQuery() query.select('#myCanvas').node().exec((res) => { const canvas = res[0].node const gl = canvas.getContext('webgl') gl.clearColor(1, 0, 1, 1) gl.clear(gl.COLOR_BUFFER_BIT) }) } })
评价
排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:
50010702506256


欢迎加群交流技术