import {ResourceLoader} from "./base/ResourcrLoader.js"; import {DataStore} from "./base/DataStorm.js"; import {Background} from "./runtime/Background.js"; import {Director} from "./Director.js"; import {Land} from "./runtime/Land.js"; // function createRecycleContext() { // return undefined; // } //let ctx = canvas.getContext('2d'); //const ctx = createRecycleContext(); export class Main{ constructor() { this.canvas = document.getElementById('game_canvas'); //准备好画布 this.ctx = this.canvas.getContext('2d'); //准备好上下文对象 this.dataStore = DataStore.getInstance(); //找到变量存储器 this.director = Director.getInstance(); //找到导演类 const loader = ResourceLoader.create(); //创建资源加载器 loader.onload(map=>this.onResourceFirstLoad(map)); // let image = new Image(); // image.src = './images/background1.png'; // image.onload = ()=>{ // this.ctx.drawImage(image, // 0,0, // image.width,image.height, // 0,0, // image.width,image.height); // } } onResourceFirstLoad(map){ //第一次完成加载时,将canvas,context,map对象存入变量存贮器中 //console.log(map) //let ctx = createRecycleContext(); this.dataStore = DataStore.getInstance(); this.dataStore.ctx = this.ctx ; this.dataStore.canvas = this.canvas; this.dataStore.images = map; //DataStore中的images变量储存的是图片对象 this.init(); } init(){ //将每个精灵放入DataStore中 this.dataStore.put('background1',Background) .put('land',Land); this.director.run(); } }
Uncaught TypeError: Cannot set property 'ctx' of u[图片][图片][图片]请问这个问题怎么办啊?(呜呜呜,我好卑微,根本看不懂~)
2020-04-20大大这是那个新问题https://developers.weixin.qq.com/s/N3v4wBme75gH
ReferenceError: canvas is not definedReferenceError: canvas is not defined 卑微小白在线求问,,这怎么改啊~[图片]
2020-04-14