Uncaught TypeError: Cannot read property 'addEventListener' of null
This happens when I start running spaaace on a computer where it never ran before, so it is fixed by refreshing the page.
When it happens, the game doesn't start. The exception is raised on the SpaaaceClientEngine::start() method, in the third line below:
this.gameEngine.once('renderer.ready', function () {
// click event for "try again" button
document.querySelector('#tryAgain').addEventListener('click', function () {
if (Utils.isTouchDevice()) {
_this2.renderer.enableFullScreen();
}
_this2.socket.emit('requestRestart');
});
That's probably because the element hadn't been loaded at the time when the bundle js was being executed.
I'd move the <script src="dist/bundle.js" type="text/javascript"></script> to the very bottom of the index.html file. This way you can ensure script is executed after all the html elements have been parsed and rendered .
alexus85/spaaace#1
Yep, that's a good notion in general. I'm in the process of re-writing spaaace for Lance V2 and that'll definitely get sorted out there soon :)
Thank you very much, alexus85 . Yesterday I spent the whole day trying to figure out what was going on in my code, where the mistake was. In the end, it was only the position of the script within the html file.
Thank you very much for bringing me the solution.
https://github.com/alexus85