var source = {};
function load_source(url,w,h,type){//返回图片还是canvas
this.canvas = document.createElement('canvas');
...
this.ctx =this.canvas.getContext('2d');
this.img = new Image();
this.img.onload = function () {
this.ctx.drawImage(this.img,0,0);
}.bind(this);
this.img.src = url;
if(type=='canvas')
return this.canvas;
else if(type=='img')
return this.img
}
source.build = new load_source('http://ut.png',1024,1024,'canvas');
source.lk = new load_source('http://ht.png',1024,1024,'canvas');
function Map_interpret(){
this.init = function(){//初始化地图
...
}
this.render = function(){//初始化地图
this.ctx.drawImage(source.lk,0,0);
}
}
m = new Map_interpret();
m.init();
m.render();
临时写的精简的代码可能会报小错误(思路是图片画到canvas里,再把这个canvas画到另一个canvas里,并显示),主要问题是为什么init方法里面的this.ctx.drawImage(source.build,0,0)画出来的canvas不显示,而render里的this.ctx.drawImage(source.lk,0,0);可以画出来
慕盖茨4494581
相关分类