Step 1 - Start Your Engines
First in main.ts we can import all of Excalibur as ex, this makes it clear in this example what types are coming from Excalibur.
typescript
typescript
You can certainly import individual types like this if you prefer, but for this tutorial we'll be doing the "barrel" import * as ex.
typescript
typescript
We can start by creating our ex.Engine, which will be the container for our game and drives the whole thing.
- We can configure the width and height in pixels
- We can configure the background color #54C0CA
- There are different ex.DisplayMode's, If you want to fit the width and height to the screen and keep aspect ratio, useex.DisplayMode.FitScreen
- If you want to avoid the letter boxing you can use ex.DisplayMode.FitScreenAndFill, only the configured width and height are safe to draw in but outside of that is not guaranteed.
- In this sample we are using pixel art, so setting pixelArt: truewill provide the best defaults for that.
- pixelRatio: 2will "scale up` the canvas to give us more crisp look at lower resolutions.
- Call .start()to start the game
typescript
typescript
At this point the screen will just be a solid color we picked as our backgroundColor.
We can add some css to our game to center it on the screen
css
css
Then include this in your index.html in the <head> section
html
html