获取图片部分
function preloadAvatar() { console.log( 'preload avatar...' ); //如果超过1.5秒没有加载成功,使用默认头像 setTimeout(() => { if (loadAvatarFail) { console.log( "头像加载失败" ); // createScene(); } }, 1500); let preloaded = 0; let count = 0; for ( var i in friendData) { count++; let img = wx.createImage(); //处理没有头像的情况 if (friendData[i][ 'avatar' ] == "" ) { friendData[i][ 'avatar' ] = assets.avatar; preloaded++; } else { img.src = friendData[i][ 'avatar' ]; friendData[i][ 'avatar' ] = img; } img.onload = ()=> { preloaded++; if (preloaded == count) { loadAvatarFail = false ; console.log( "头像加载完毕" ); } } } } |
使用图片部分
context = sharedCanvas.getContext( "2d" ); context.globalCompositeOperation = "source-over" ; context.drawImage(assets.panel,(stageWidth - assets.panel.width) / 2,(stageHeight - assets.panel.height) / 2) context.drawImage(assets.content,(stageWidth - assets.content.width) / 2,((stageHeight - assets.content.height) / 2 ) - 20) |
模拟器的是可以跑 并且没有报错,但是真机显示第二真后 就没有图片了
[wxgl]invalid drawimage
微信开发工具 v1.02.1806120 直接演示(真机)不能显示,上传体验版本显示ok