小游戏canvas画不出图片
下面的代码在开发者工具和安卓手机上能画出个绿方块, 画不出图片, 在ios上方块和图片都画不出来
图片在 项目根目录/images 下 是有的, 在开发者工具里面network里是加载了图片的
console出来canvas是有的, ctx也有, img也加载上了
const canvas = wx.createCanvas()
, ctx = canvas.getContext("2d")
, img = wx.createImage(), {screenWidth, screenHeight} = wx.getSystemInfoSync();
img.src = "images/background.png";
img.width = screenWidth;
img.height = screenHeight;
ctx.drawImage(img, 0, 0, screenWidth, screenHeight);
console.log(canvas, ctx, img);
ctx.fillStyle = "#00ff00";
ctx.fillRect(0, 0, 200, 200);
6 回复