GithubHelp home page GithubHelp logo

xwillxu / phaser-examples Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 399.63 MB

A repository of javascript examples using Phaser JS. Examples include singleplayer games, remixes of games, multiplayer games, and original games. Note: Be advised that examples mean games.

Home Page: https://www.imini.app

License: MIT License

JavaScript 82.26% HTML 14.75% CSS 3.00%
examples games javascript multiplayer original-game phaserjs remixes repository singleplayer

phaser-examples's Introduction

phaser3-parceljs-template

Phaser 3 + Parcel Template

For people who want to spend time making games instead of configuring build tools.

License Games

Prerequisites

You'll need Node.js, npm, and Parcel installed.

It is highly recommended to use Node Version Manager (nvm) to install Node.js and npm.

For Windows users there is Node Version Manager for Windows.

Install Node.js and npm with nvm:

nvm install node

nvm use node

Replace 'node' with 'latest' for nvm-windows.

Then install Parcel:

npm install -g parcel-bundler

Getting Started

Clone this repository to your local machine:

git clone https://github.com/ourcade/phaser3-parcel-template.git

This will create a folder named phaser3-parcel-template. You can specify a different folder name like this:

git clone https://github.com/ourcade/phaser3-parcel-template.git my-folder-name

Go into your new project folder and install dependencies:

cd phaser3-parcel-template # or 'my-folder-name'
npm install

Start development server:

npm run start

To create a production build:

npm run build

Production files will be placed in the dist folder. Then upload those files to a web server. ๐ŸŽ‰

Project Structure

    .
    โ”œโ”€โ”€ dist
    โ”œโ”€โ”€ node_modules
    โ”œโ”€โ”€ public
    โ”œโ”€โ”€ src
    โ”‚   โ”œโ”€โ”€ scenes
    โ”‚   โ”‚   โ”œโ”€โ”€ HelloWorldScene.js
    โ”‚   โ”œโ”€โ”€ index.html
    โ”‚   โ”œโ”€โ”€ main.js
    โ”œโ”€โ”€ package.json

The contents of this template is the basic Phaser3 getting started example.

This template assumes you will want to organize your code into multiple files and use modern JavaScript (or TypeScript).

JavaScript files are intended for the src folder. main.js is the entry point referenced by index.html.

Other than that there is no opinion on how you should structure your project. There is a scenes folder in src where the HelloWorldScene.js lives but you can do whatever you want.

Static Assets

Any static assets like images or audio files should be placed in the public folder. It'll then be served at http://localhost:8000/images/my-image.png

Example public structure:

    public
    โ”œโ”€โ”€ images
    โ”‚   โ”œโ”€โ”€ my-image.png
    โ”œโ”€โ”€ music
    โ”‚   โ”œโ”€โ”€ ...
    โ”œโ”€โ”€ sfx
    โ”‚   โ”œโ”€โ”€ ...

They can then be loaded by Phaser with this.image.load('my-image', 'images/my-image.png').

Class Properties Support

This template includes class property support out of the box using @babel/plugin-proposal-class-properties.

A .babelrc is included as well as the use of babel-eslint as the parser for ESLint.

ESLint

This template uses a basic eslint set up for code linting to help you find and fix common problems in your JavaScript code.

It does not aim to be opinionated.

See here for rules to turn on or off.

TypeScript

Check out the phaser3-typescript-parcel-template for a ready-to-use version of this template in TypeScript!

Dev Server Port

You can change the dev server's port number by modifying the start script in package.json. We use Parcel's -p option to specify the port number.

The script looks like this:

parcel src/index.html -p 8000

Change 8000 to whatever you want.

Other Notes

parcel-plugin-clean-easy is used to ensure only the latest files are in the dist folder. You can modify this behavior by changing parcelCleanPaths in package.json.

parcel-plugin-static-files is used to copy static files from public into the output directory and serve it. You can add additional paths by modifying staticFiles in package.json.

License

MIT License

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.