Creating a Game
In the Quick Start guide, we learned how to set up a very simple project using dill pixel. Now let’s go through the process of creating a basic game.
Setup the Files
-
First, create a
package.json
in your project’s root directory: -
Create a
vite.config.js
file in the root directory to configure the build process. The default Vite configuration is sufficient but for handling static assets we’re using the vite-plugin-static-copy so that they can be loaded from within the game. You can configure the plugin however you like based on how you’ve organized your assets. -
Next, create an
index.html
file in the root directory. This file will be the entry point for your game and dill pixel will automatically create a<div id="game-container" />
to contain the game canvas: -
Create an
index.css
file in thesrc
directory that displays the game at full screen: -
Create an
index.ts
file in thesrc
directory that initializes the game:
Create the Game States
Loading Screen
Create a state
folder in the src
directory and create a LoadScreen.ts
file in it. This will
be displayed while the game is loading and also when transitioning between states.
To manage the transitions smoothly, we’re using gsap
to fade the loading screen in and out
in the animateIn()
and animateOut()
methods:
Intro Screen
Create an IntroScreen.ts
file in the state
folder. This will be displayed when the game starts.
Similar to the LoadScreen
, there are animateIn()
and animateOut()
methods to control how the screen
is revealed and hidden. For simplicity’s sake we’re just creating a green background and adding a title
that can be clicked to take us to the next screen:
Game Screen
Create a GameScreen.ts
file in the state
folder. This will be the main game screen with a few
elements: an image, a title, a message, and a button.
Clicking on the image will trigger a short animation and increment a counter. Clicking the
button will take us back to the IntroScreen
.
Note that in the destroy()
method we’re cleaning up the gsap
animations.
Create the Application
Create an Application.ts
file in the src
directory. This is the main application class that will
manage the game states and transitions between them:
Install the Dependencies
Once you have created the files, install the dependencies: