excaliburjs / Excalibur

🎮 Your friendly TypeScript 2D game engine for the web 🗡️
https://excaliburjs.com
BSD 2-Clause "Simplified" License
1.69k stars 183 forks source link

Feature request - Suppress canvas injection from the Engine constructor #2970

Open ewal opened 4 months ago

ewal commented 4 months ago

Context

When creating a new instance of the Engine the canvas element is automatically injected into the DOM and this behavior can cause problems if the document is not yet ready.

Proposal

By allowing manual mounting/injecting of the canvas element, we will have more control of the flow, eg.the game could be constructed before being used.

I ran into the problem with the document not being ready when wanted to prepare an exported game instance.

eonarheim commented 4 months ago

@ewal This is a great feature idea! I 100% support this

eonarheim commented 4 months ago

@ewal As a possible workaround you can supply the canvasElementId to the engine constructor and it will use a canvas that is defined in the DOM

ewal commented 4 months ago

@ewal As a possible workaround you can supply the canvasElementId to the engine constructor and it will use a canvas that is defined in the DOM

Thanks for the reply, @eonarheim. I tried specifying the canvasElementId but I still face the same problem since the code tries to find the element on line 760 in Engine.ts with the document being undefined.

eonarheim commented 4 months ago

@ewal AH! Good find, that definitely is a bigger problem for sure. I'll bump this in priority on my list!

github-actions[bot] commented 2 months ago

This issue hasn't had any recent activity lately and is being marked as stale automatically.