Sign up for a plan to instantly unlock all premium lessons.
Premium Features
There's a small bug you may have noticed in which the platforms of our game move the very beginning of the level whenever the browser window is refreshed. This occurs since our init() code is running before all of our game assets are loaded. Here I'll show you how to fix this using the power of promises and async / await.
Comments
Want to participate?
Create a free Chris Courses account to begin
i don't know why it is showing this
canvas.bundle.js:10 Uncaught Error: Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /Users/ankurarora/Desktop/games/mario-game-server/src/js/canvas.js: Unexpected token, expected "{" (158:4) (at canvas.bundle.js:10:7)
[0m [90m 156 |[39m
[90m 157 |[39m [36masync[39m [36mfunction[39m init()
[31m[1m>[22m[39m[90m 158 |[39m platformImage [33m=[39m [36mawait[39m createImageAsync(platform)
[90m |[39m [31m[1m^[22m[39m
[90m 159 |[39m
[90m 160 |[39m console[33m.[39mlog(platformImage[33m.[39mwidth)
[90m 161 |[39m [0m
at constructor (:3000/Users/ankurarora/Desktop/games/mario-game-server/node_modules/@babel/parser/lib/index.js:362:19)
at Parser.raise (:3000/Users/ankurarora/Desktop/games/mario-game-server/node_modules/@babel/parser/lib/index.js:3259:19)
at Parser.unexpected (:3000/Users/ankurarora/Desktop/games/mario-game-server/node_modules/@babel/parser/lib/index.js:3279:16)
at Parser.expect (:3000/Users/ankurarora/Desktop/games/mario-game-server/node_modules/@babel/parser/lib/index.js:3589:12)
at Parser.parseBlock (:3000/Users/ankurarora/Desktop/games/mario-game-server/node_modules/@babel/parser/lib/index.js:12773:10)
at Parser.parseFunctionBody (:3000/Users/ankurarora/Desktop/games/mario-game-server/node_modules/@babel/parser/lib/index.js:11620:24)
at Parser.parseFunctionBodyAndFinish (:3000/Users/ankurarora/Desktop/games/mario-game-server/node_modules/@babel/parser/lib/index.js:11606:10)
at :3000/Users/ankurarora/Desktop/games/mario-game-server/node_modules/@babel/parser/lib/index.js:12921:12
at Parser.withSmartMixTopicForbiddingContext (:3000/Users/ankurarora/Desktop/games/mario-game-server/node_modules/@babel/parser/lib/index.js:11914:14)
at Parser.parseFunction (:3000/Users/ankurarora/Desktop/games/mario-game-server/node_modules/@babel/parser/lib/index.js:12920:10)
at constructor (:3000/Users/ankurarora/Desktop/games/mario-game-server/node_modules/@babel/parser/lib/index.js:362:19)
at Parser.raise (:3000/Users/ankurarora/Desktop/games/mario-game-server/node_modules/@babel/parser/lib/index.js:3259:19)
at Parser.unexpected (:3000/Users/ankurarora/Desktop/games/mario-game-server/node_modules/@babel/parser/lib/index.js:3279:16)
at Parser.expect (:3000/Users/ankurarora/Desktop/games/mario-game-server/node_modules/@babel/parser/lib/index.js:3589:12)
at Parser.parseBlock (:3000/Users/ankurarora/Desktop/games/mario-game-server/node_modules/@babel/parser/lib/index.js:12773:10)
at Parser.parseFunctionBody (:3000/Users/ankurarora/Desktop/games/mario-game-server/node_modules/@babel/parser/lib/index.js:11620:24)
at Parser.parseFunctionBodyAndFinish (:3000/Users/ankurarora/Desktop/games/mario-game-server/node_modules/@babel/parser/lib/index.js:11606:10)
at :3000/Users/ankurarora/Desktop/games/mario-game-server/node_modules/@babel/parser/lib/index.js:12921:12
at Parser.withSmartMixTopicForbiddingContext (:3000/Users/ankurarora/Desktop/games/mario-game-server/node_modules/@babel/parser/lib/index.js:11914:14)
at Parser.parseFunction (:3000/Users/ankurarora/Desktop/games/mario-game-server/node_modules/@babel/parser/lib/index.js:12920:10)
at ./src/js/canvas.js (canvas.bundle.js:10:7)
at startup:5:1
at startup:5:1
still after npm start when i do cmd c it doesn't work
for some reason when i go to terminal and do cmd c it doesn't work
Hello Chris. my name is Mark... i just want to ask how to not double jump, i dont like my game jump even though the character still in the air! and not shoot fireflower continoustly if i long press the space button. i like to shoot one at a time! can you help me please... thank you in advance....
Hello! I fixed this issue in different way:
window.onload = () => {
init();
animate();
};hello i am getting this error at runtime
ERROR in ./src/js/canvas.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Cannot find module 'babel/preset-env'
hello, I have an error when I finish the 10.49 minute steps. My screen is all black and I get these errors, how do I solve it? Thanks
npm ERR! Missing script: "start"
npm ERR!
npm ERR! Did you mean one of these?
npm ERR! npm star # Mark your favorite packages
npm ERR! npm stars # View packages marked as favorites
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR! npm run
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/pedrocruz/.npm/_logs/2022-02-16T19_47_32_919Z-debug-0.log
there is a problem with the return Promise code. Here's the error.
canvas.js:134 Uncaught TypeError: undefined is not a promise
at Promise (<anonymous>)
at createImageAsync (canvas.js:134:12)
at init (canvas.js:164:18)
at Module../src/js/canvas.js (canvas.js:320:1)
at __webpack_require__ (bootstrap:19:1)
at bootstrap:83:1
at bootstrap:83:1
and here's my code: function createImageAsync(imageSrc) { return Promise((resolve) => { const image = new Image() image.onload = () => { resolve(image) } image.src = imageSrc }) }
does anybody know what I did wrong?
now fixed