Coder Social home page Coder Social logo

aceofsmiles's Introduction

Phaser Importmap Template

This is a Phaser 3 project template that uses importmap.

An import map is a JSON object that allows developers to control how the browser resolves module specifiers when importing JavaScript modules. It provides a mapping between the text used as the module specifier in an import statement or import() operator, and the corresponding value that will replace the text when resolving the specifier. The JSON object must conform to the Import map JSON representation format.

An import map is used to resolve module specifiers in static and dynamic imports, and therefore must be declared and processed before any <script> elements that import modules using specifiers declared in the map.

importmap a baseline 2023 feature. Please see MDN for details about browser compatibility.

Versions

This template has been updated for:

screenshot

Requirements

Node.js is required to install dependencies and run scripts via npm (if you want to use the development server).

Available Commands

Command Description
npm install Install project dependencies
npm run dev Launch a development web server

Writing Code

After cloning the repo, you will need a server to serve the resources of your game. This template provides your own server with hot-reloading. To start it, simply run npm run dev.

The local development server runs on http://localhost:3000 by default.

Important notes about importmap

  • You MUST use the phaser.esm build of Phaser. This is the only build that exports ES Modules that importmap supports.
  • Phaser v3.60.0 was the first version to export an ESM bundle. You cannot use earlier versions with this template.
  • The 'name' you give in the importmap (in your index.html) should match exactly that used in the import declarations within your game code.
  • You can store the Phaser ESM build locally if you'd rather not use the CDN. Simply put the phaser.esm.js in your local folder structure and reference that inside your HTML like this:
{
    "imports": {
        "phaser": "./my-local-folder/phaser.esm.js"
    }
}

Template Project Structure

We have provided a default project structure to get you started. This is as follows:

  • assets/ - Contains the static assets used by the game.
  • src/ - Contains the game source code.
  • src/scenes/ - The Phaser Scenes are in this folder.
  • src/main.js - The main entry point. This contains the game configuration and starts the game.
  • index.html - A basic HTML page to contain the game.
  • style.css - Some simple CSS rules to help with page layout.

Deploying to Production

In order to deploy your game, you will need to upload all the content of the folder to a public-facing web server.

Join the Phaser Community!

We love to see what developers like you create with Phaser! It really motivates us to keep improving. So please join our community and show off your work ๐Ÿ˜„

Visit: The Phaser website and follow on Phaser Twitter
Play: Some of the amazing games #madewithphaser
Learn: API Docs, Support Forum and StackOverflow
Discord: Join us on Discord
Code: 2000+ Examples
Read: The Phaser World Newsletter

Tell us about your game in [email protected]!

Created by Phaser Studio. Powered by coffee, anime, pixels, and love.

The Phaser logo and characters are ยฉ 2011 - 2024 Phaser Studio Inc.

All rights reserved.

aceofsmiles's People

Contributors

fencefoil avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.