- 可以将canvas2D背景设置为透明吗?
场景是有两个canvas2D,重叠放置, 一个渲染静态的场景资源,放在下层, 一个是需要高频率渲染与用户的交互,放在上层, 可以将上层的canvas2D背景设置为透明吗?
2020-11-24 - 如何解决canvas.requestAnimationFrame()报错问题?
touchEnd(e){//TODO:复位 if(this._pointCountInScreenLessThanFive(tempSeat)){ let boxModel = this._getBoxModel(tempSeat) let direction = this._computeRestDirection(boxModel) this._reset(direction) } }, _reset(direction){ if(this._pointCountInScreenLessThanFive(tempSeat)){ this._updata(tempSeat,direction) this._render(tempSeat,{}) this.canvas.requestAnimationFrame(this._reset) } }, VM6312 WAService.js:2 MiniProgramError Cannot read property '_pointCountInScreenLessThanFive' of undefined TypeError: Cannot read property '_pointCountInScreenLessThanFive' of undefined at _reset (http://127.0.0.1:57867/appservice/components/seatMap/index.js:414:16) tempSeat是在当前页面下模拟的全局变量,试验用 如蒙赐教,感激不尽!
2020-11-22 - canvas画布ctx.isPointInPath()使用?
selectSeat:function(e){ const clickX = e.detail.x const clickY = e.detail.y const ctx = this.context ctx.beginPath() ctx.rect(200,0,100,100) ctx.closePath() ctx.stroke() console.log(ctx.isPointInPath(clickX,clickY),clickX,clickY) } [图片]
2020-11-03 - 在自定义组件的method中访问不了this.data.xxx?
_initCanvas:function(){ const q = wx.createSelectorQuery().in(this) q.select("#seatMap") .fields({ node : true , size : true}) .exec(res=>{ const canvas = res[0].node const context = canvas.getContext("2d") const dpr = wx.getSystemInfoSync().pixelRatio const phoneInfo = wx.getSystemInfoSync() const canvasHeight = phoneInfo.windowHeight *dpr const canvasWidth = phoneInfo.windowWidth * dpr const statusBarHeight = phoneInfo.statusBarHeight * dpr canvas.width = canvasWidth canvas.height = canvasHeight this.setData({ canvas, context, canvasHeight, canvasWidth, statusBarHeight }) context.scale(dpr,dpr) context.font="20px sans-serif" context.fillText("welcome",100,100) context.strokeRect(0,0,300,300) }) console.log(this.data.context) } [图片]
2020-11-02