我在做一个小游戏的demo的时候,在开发者工具中操作没有问题,但是使用真机预览或者真机调试时一直卡在加载进度100%,无法进入小游戏,求指导
手机:荣耀8
微信版本:7.0.3
代码如下:
let canvas = wx.createCanvas()
let ctx = canvas.getContext('2d')
const screenWidth = wx.getSystemInfoSync().screenWidth
const screenHeight = wx.getSystemInfoSync().screenHeight
export default class Main {
constructor() {
this.restart()
}
restart() {
this.touchEndHandler = this.touchEndEventHandler.bind(this)
wx.onTouchEnd(this.touchEndHandler)
}
touchEndEventHandler(e) {
let x = e.changedTouches[0].clientX
let y = e.changedTouches[0].clientY
ctx.beginPath();
ctx.clearRect(0, 0, screenWidth, screenHeight);
ctx.strokeStyle = "#FFBB00";
ctx.fillStyle = "#FFBB00";
ctx.arc(x, y, 30, 0, Math.PI * 2);
ctx.fill();
}
}
你需要先画个背景图,可以这样改写
restart() {
let x = 0;
let y = 0;
ctx.beginPath();
ctx.clearRect(0, 0, screenWidth, screenHeight);
ctx.strokeStyle = "#FFBB00";
ctx.fillStyle = "#FFBB00";
ctx.arc(x, y, 30, 0, Math.PI * 2);
ctx.fill();
this.touchEndHandler = this.touchEndEventHandler.bind(this)
wx.onTouchEnd(this.touchEndHandler)
}