小游戏canvas自由绘画线条真机调试和预览花屏
const ctx = canvas.getContext('2d') // 创建一个 2d context const screenWidth = wx.getSystemInfoSync().screenWidth const screenHeight = wx.getSystemInfoSync().screenHeight export default class Main{ constructor(){ this.drawing() } drawing(){ ctx.fillStyle = '#ffffff' // 矩形颜色 ctx.fillRect(0, 0, screenWidth, screenHeight) // 矩形左上角顶点为(0, 0),右下角顶点为(100, 100) wx.onTouchStart(function(e){ ctx.beginPath() ctx.moveTo(100, 200); ctx.lineTo(100, 300); ctx.stroke() ctx.closePath(); }) } }