September 2018
Intermediate to advanced
328 pages
9h 10m
English
The code to compile the Wasm file and populate the <canvas> element is shown as follows:
methods: { // Create a new Image instance to pass into the drawImage function // for the <canvas> element's context: loadImage(imageSrc) { const loadedImage = new Image(); loadedImage.src = imageSrc; return new Promise((resolve, reject) => { loadedImage.onload = () => resolve(loadedImage); loadedImage.onerror = () => reject(); }); }, // Compile/load the contents of main.c and assign the resulting // Wasm module instance to the components this.instance property: async initializeWasm() { const ctx = this.$refs.canvas.getContext('2d'); // Create Image instances of the background and spaceship. // These are required to pass into the ctx.drawImage() ...Read now
Unlock full access