Giter Club home page Giter Club logo

rroylance / phaser-ce-npm-webpack-typescript-starter-project Goto Github PK

View Code? Open in Web Editor NEW
423.0 31.0 73.0 4.64 MB

Project to get you started with your Phaser-CE (using the npm module) game using Typescript and Webpack for building! No hassle asset management, Google Web Font loader, live server, development vs distribution build pipeline, Electron packaging for desktop builds, and more...

Home Page: https://rroylance.github.io/phaser-npm-webpack-typescript-starter-project/

License: The Unlicense

TypeScript 40.22% JavaScript 58.43% HTML 0.42% CSS 0.45% GLSL 0.48%
phaser typescript template npm node webpack game electron app desktop

phaser-ce-npm-webpack-typescript-starter-project's Introduction

Phaser-CE NPM Webpack TypeScript Starter Project (catchy name, isn't it?)

GitHub package version GitHub last commit

GitHub watchers GitHub stars GitHub forks

GitHub issues GitHub pull requests

David

PhaserNPMWebpackTypeScriptStarterProject

Hit the ground running and make some great games!
If you use this template/starter project in any capacity; I'd love to hear about your experience with it. Whether you continued with it or decided not to (I really want to hear why you made your decision).

Features:

  • Phaser-CE 2.11.1 (npm module, no having to download the library separately...)
  • TypeScript + TSLint
  • 3 States (Boot, Preloader, Title) showing transition between states and where some things should be done and how a TypeScript state looks
  • Google Web Font loader
  • Webpack
  • Separate Development and Distribution builds
  • Live server (builds and reloads the browser on changes)
  • No hassle asset management requiring no code, on your part, to load and parse assets
    • Assets are required and hashed via webpack, you can now guarantee that when you push an update, everyone will get the new files and not cached ones
    • Assets class created automatically allowing you to access all the assets and their frames and sprites (in the case of Atlases and Audiosprites) in a compiler validating way!
  • Setting up the game size and scaling through a script that does it all for you
    • Automatic template background
    • Sets up the size the game so that it is scaled only when absolutely necessary
    • Refer to src/utils/utils.ts for an explanation on the background_template and the sizing/scaling style
    • Landscape and Portrait support

TODO (in no particular order):

  • Clean up generateAssetsClass.js
  • Get Custom/Local Web Fonts hashed by Webpack (to avoid cache issues)
    • If anyone has experience webpacking font-face in css style web fonts and loading said fonts via webfontloader, let me know as I was having some trouble getting the font-face src to use the hashed assets.
  • Multiple resolution asset loader (@2x, @3x, etc...)
  • Yeoman Generator
  • Optional Analytics integration
  • Optional Cordova integration for iOS and Android builds

Folder Structure:

  • assets/ – This is where your assets that are processed when building goes
  • assets_raw/ – This folder is NOT processed at all and is merely an organizational folder (I use it for things like my individual images that get compiled into a spritesheet, individual sounds that get compiled into an audiosprite, etc...)
  • dist/ – This is where the built game will go
  • node_modules/ – This is where the node modules required for the game will be put with npm install
  • scripts/ – This is where node scripts go
  • src/ – This is where all the games code goes
  • templates/ – This is where the html template that gets built by Webpack goes
  • .gitignore – List of files and folders that are ignored by git
  • .npmrc – List of some project wide npm settings
  • electron-main.js – Entry point and application life controller for electron builds
  • package.json – Node config for the project
  • README.md – This is the README displayed ont he GitHub page
  • README_HEADER.png – This is just the header image for the GitHub README
  • tsconfig.json – List of some TypeScript settings
  • tslint.json – List of some TypeScript Linting rules
  • webpack.dev.config.js – Webpack config for the DEV build
  • webpack.dist.config.js – Webpack config for the DIST build

Setup:

To use this you’ll need to install a few things before you have a working copy of the project. But once you have node.js installed it only takes a few seconds and a couple commands to get going.

0. Install Git:

GIT Installation Instructions and Links

1. Download or Clone this repo:

Download:

Download the latest zip/tar.gz from GitHub Releases, extract it to where you want your project to be.

If you want a clean project ready for you to just start your own game and not have to worry about cleaning up the examples and samples from the v1.11.0 release, just download the v1.11.0-fresh release instead.

Clone (must've completed Step 0 first):

Navigate into your workspace directory.

Run:

git clone https://github.com/rroylance/phaser-ce-npm-webpack-typescript-starter-project.git

If you want a clean project ready for you to just start your own game and not have to worry about cleaning up the examples and samples from the master branch, just pull the 'fresh-start' branch instead of master.

2. Install node.js and npm (npm is included and installed with node.js):

NodeJS Installation Instructions and Links

3. Install dependencies:

Navigate to the cloned repo’s directory.

Run:

npm install

4. Run the dev server:

Run to use the dev build while developing:

npm run server:dev

Run to use the dist build while developing

npm run server:dist

The only real reason I can think of to use the dist server is if the minification process is breaking something in your game and you need to test using the minified version, or something you excluded with the DEBUG flag shouldn't have been excluded.

This will run a server that serves your built game straight to the browser and will be built and reloaded automatically anytime a change is detected.

Build for testing/developing/debugging:

Run:

npm run build:dev

This will build the game with a few caveats;

  • A compile time flag, DEBUG, set to true; allowing you to include or not include certain code depending on if it's DEBUG build or not.
  • The resulting game.js will not be minified

Build for release:

Run:

npm run build:dist

This will build the game with a few caveats;

  • The compile time flag, DEBUG, set to false; allowing you to include or not include certain code depending on if it's DEBUG build or not.
  • The resulting game.min.js will be minified

Generate Assets Class:

This project will manage your assets for you! All you need to do is drop your assets in assets/ (subdirectories do not matter) and run (you need to run this manually if you change assets while the server is running, otherwise it's run automatically when running a build);

npm run assets

or (if your dev GOOGLE_WEB_FONTS is different from your dist);

npm run assets:dev

src/assets.ts will be generated which contains sections for all your asset types (the generator is smart enough to distinguish what assets are what !) and classes for every asset, it will also generate an enum containing every frame and sprite in Atlases and AudioSprites respectively!

No need to remember keys, frames, or sprites anymore; which means no more typos resulting in asset not found errors. Just use, for example, Assets.Images.ImagesBackgroundTemplate.getName() or Assets.Audiosprites.AudiospritesSfx.Sprites.Laser1. This also allows the compiler to warn you if you are trying to use an asset that doesn't exist!

The preloader will use this class to load everything, you don't have to do anything in code to get your assets loading and available (except for any assets you need for your loading screen...)!

Currently supports the following (if you need a new extension or find an issue with one of your assets not exporting correctly, just let me know);

  • Images:
    • bmp, gif, jpg, jpeg, png, webp
  • Spritesheets:
    • bmp, gif, jpg, jpeg, png, webp
    • [frameWidth, frameHeight, frameMax, margin, spacing] - frameWidth & frameHeight are required.
    • Example: spritesheet.[100, 100].png
  • Atlases:
    • bmp, gif, jpg, jpeg, png, webp
    • json (the loader figures out if it's a JSONArray or JSONHash, no need to remember or care), xml
  • Audio:
    • aac, ac3, caf, flac, m4a, mp3, mp4, ogg, wav, webm
  • Audiosprites:
    • aac, ac3, caf, flac, m4a, mp3, mp4, ogg, wav, webm
    • json
  • Local Fonts:
    • eot, otf, svg, ttf, woff, woff2
    • css
  • Bitmap Font:
    • bmp, gif, jpg, jpeg, png, webp
    • xml, fnt
  • JSON:
    • json
  • Tilemap JSON:
    • json
  • XML:
    • xml
  • Text:
    • txt
  • Scripts:
    • js
  • Shaders:
    • frag

Which version of the audio to load is defined in the webpack.dev.config.js and webpack.dist.config.js under the DefinePlugin 'SOUND_EXTENSIONS_PREFERENCE' section;

  • Currently I set the order to: webm, ogg, m4a, mp3, aac, ac3, caf, flac, mp4, wav
  • The loader will load the audio using this as the preference; the first supported file that is found is used using the order of this list as most preferred to least preferred

Change the game size and generate a template background:

Note: This is automatically run after running npm install, however you may want to run it again (if you deleted the background.png and want it back, or if you want to change the game size from the default).

Run:

npm run setupGameSize

This will run a script that will generate a template background showing the safe and decoration area of your game when it is sized or scaled for different devices as well as updating a couple global values in the webpack configs so that the game knows about the new size when built.

If you do not want the default 800 x 500 with this scaling style, run the following and all will be updated.

DO NOT MODIFY THE (DEFAULT or MAX)_GAME_(WIDTH or HEIGHT) OR SCALE_MODE PLUGINS DEFINED IN THE WEBPACK CONFIGS, OR THIS WILL NOT WORK;

Run the following for descriptions and default values for all possible options;

npm run setupGameSize -- -h

Run the following specifying some or all of the options;

npm run setupGameSize -- --width [whatever width you want] --height [whatever height you want] --aspect-ratio [If you want a different default aspect ratio] --scale-mode [one of the Phaser Scale Modes] [--no-png]

The '--' after setupGameSize is not a mistake; it is required to pass arguments along to the script.

You can either provide the width and height (defaults 800 and 500 respectively) and as long as they result in an aspect ratio of what's set in the script or by --aspect-ratio, or you can provide the width or height and the one you didn't provide will be calculated for you using the aspect ratio of what's set in the script or by --aspect-ratio.

Provide --aspect-ratio to change the desired aspect ratio (default 1.6 or 16:10). The script checks to make sure the width and height match the aspect ratio so you get warned early about an incorrect dimension (maximum precision of 3 decimal places).

Providing --scale-mode will set this.game.scale.scaleMode to the corresponding Phaser.ScaleManager.SCALE_MODE (default USER_SCALE).

If you do not want the background to be created just add the flag --no-png (not putting this will let the background generate).

Google Web Fonts:

Add your desired Google Web Fonts to the webpack.dev.config.js and/or webpack.dist.config.js in the DefinePlugin 'GOOGLE_WEB_FONTS' section and they will then be loaded and available via Assets.GoogleWebFonts.

Custom/Local Web Fonts:

Add your desired Custom/Local Web Fonts to your assets folder and they will then be loaded and available via Assets.CustomWebFonts

  • The various font files, and the css MUST share the same name
  • One CSS file per font

I recommend one of the following generators for generating your font files;

Plugin management:

Drop the .js file (or .min.js) of the plugin in the assets/script folder. Your script(s) will be loaded in the Preloader state with the AssetUtils.Loader.loadAllAssets call. If you want the typescript support, you need to drop the .d.ts file somewhere (not in assets) and add it to the files array in tsconfig.json.

Here is an example of how to include your plugin in a state:

export default class MyState extends Phaser.State {

    myPlugin: Phaser.Plugin.MyPlugin;

    public preload(): void {
        this.myPlugin = new Phaser.Plugin.MyPlugin(this.game);
        this.game.plugins.add(this.myPlugin as any);
    }
}

Desktop Build via Electron

Note that I am not, currently, actively using this. So if you do, I'd appreciate if you could pass any changes you make or anything you need out of it. Although I'm not using it, I will still support it as best I can.

You can test your game via Electron by running;

npm run electron:dev

or

npm run electron:dist

To build the dev or dist version of your game, respectively, and then open up your game in an Electron instance.

Package Desktop App via Electron

Note that I am not, currently, actively using this. So if you do, I'd appreciate if you could pass any changes you make or anything you need out of it. Although I'm not using it, I will still support it as best I can.

You can package your game for Windows (win32 ia32/x64), OSX (darwin ia32/x64), Mac App Store (mas ia32/x64), Linux (linux ia32/x64/armv7l) using the following script;

npm run electron:pack:dev

or

npm run electron:pack:dist

To package the dev or dist version of your game, respectively, for the current platform you are on. You can provide many options to build specific platforms, for specific architectures, provide an icon, etc.

Refer to the API Documentation for a full list and details; I'm using it kind of oddly in that I'm using the API from the command line and not the command line version... to provide options appaend ' -- ' to the npm run command and then also append '--' to the option name and then either put the value after a space or '=', either way. Examples;

npm run electron:pack:dist -- --platform win32 --arch=ia32 //32 bit Windows exe

npm run electron:pack:dist -- --platform win32,darwin --arch=ia32,x64 //32 and 64 bit Windows exe and OSX app

All builds will be in the builds/ folder in appropriately named folders.

Note that building for Windows from a non windows device requires a little bit of extra setup; refer to Building Windows apps from non-Windows platforms.
Also note that for OSX / MAS target bundles: the .app bundle can only be signed when building on a host OSX platform.

Bugs/Issues?

If you have any issues please let me know via GitHub Issues!

Requests/Suggestions?

If you have any requests or suggestion for the project please let me know via GitHub Issues!

Contributing Code?

If you would like to have some of your code included; whether a new feature, a cleaned up feature, a bugfix, or whatever. Please open up a Pull Request!

Games made with this project (Click the images to play!)

Game: America First: The Game

Author: Enzo Testa

Github Repo: https://github.com/Shrakka/DoublePong

Description: This is Enzo's first game! Well done double pong demo.


Game: Coffee Conundrum

Author: Jonathan Grangien

Github Repo: https://github.com/codingInSpace/CoffeeConundrum

Description: Cool little SHMUP. Code looks well done and nice and clean and well thought out. Nice job Jonathan!


Game: P0ng

Author: ProfitWarning

Github Repo: https://github.com/ProfitWarning/p0ng

Description: Nice 2-player pong clone.


Game: Great Run

Author: Róbert Girhiny

Github Repo: https://github.com/robcaa/great-run

Description: Nice Dora The Explorer themed platformer/runner for kids.


Game: Take Back the Colors

Author: j3soon

Github Repo: https://github.com/j3soon/TakeBackTheColors

Description: 2D platformer game with swinging ability.


Game: R0d3nt

Author: tuskat

Github Repo: https://github.com/tuskat/R0d3nt

Description: Futur1st1c P3st C0ntr0l

phaser-ce-npm-webpack-typescript-starter-project's People

Contributors

carsonip avatar dependabot[bot] avatar eltoncezar avatar ignlg avatar j3soon avatar jdeblander avatar majinbui avatar nepoxx avatar pierlucsbk avatar richard-splashworks avatar roryokane avatar rroylance avatar sc0d3r avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phaser-ce-npm-webpack-typescript-starter-project's Issues

generateAssetClass.js

Hi,

there is a bug in line 213 of generate AssetClass:

for (var a in json['frames']) {
    frameFull = (json['frames'][a]['filename']);
     frame = frameFull.substring(0, frameFull.lastIndexOf('.'));                 
     shell.ShellString('\n        ' + toPascalCase(frame) + ' = <any>\'' + frameFull + '\',').toEnd(assetsClassFile);
}

assets in the atlas do not need to have a .png (or any extension) in the name. a simple fix is to add:

if (frame === "") {
    frame = frameFull;
 }

sample asset file:

{
    "frames": [{
            "filename": "Foo",
            "frame": { "x": 1627, "y": 1198, "w": 32, "h": 34 }
    }]
}

Thanks

Richard,
Thank you for creating this Phaser template, especially the very detailed write up on its design/structure. None of the other templates have that much detail. Although I don't have any issues at the moment, I would like some advice. Is TypeScript suitable for a beginner? I'll probably ask google but wanted to get your thoughts.

"If you use this template/starter project in any capacity; I’d love to hear about your experience with it. Whether you continued with it or decided not to (I really want to hear why you made your decision)."

  • I love the detailed write up on the template especially since I'm a beginner. I think it's important to know where to put things. Other templates leave it up to the user to figure out. If you're a beginner that can be challenging.
  • I like the fact that it works. I was able to install it without any issues from NPM.
  • I like that you included Electron support.
  • I like that you included links to three projects that use the template.

TJ

Corresponding File is Not Included In tsconfig.json

Hi, I just scaffolded this project. It compiiles, but I get a bnuch of errors in my IDE (webstorm) with squggly lines under the references to Phaser library. The error message is, "Corresponding File is Not Included In tsconfig.json".

Better dependency versions

All the dependency versions in package.json are too specific. We should change, for example "phaser-ce": "2.11.1", to "phaser-ce": "^2.11.1",

Keeping on fixed versions is bad, for example the electron version specified has security issues. The user can then use their own lock file for locking their versions.

Unable to use plugins

I have followed the instructions in the README, but i have still the error:

TS2694: Namespace 'Phaser.Plugin' has no exported member 'PhaserInput'.

Here is what I did:

  1. drop the plugin PhaserInput.js file into assets/scripts folder (https://github.com/orange-games/phaser-input/blob/master/build/phaser-input.js)

  2. declare the plugin in the assets.js file like this:

export namespace Scripts {
    export class ScriptsPhaserInput {
        static getName(): string { return 'PhaserInput'; }

        static getJS(): string { return require('assets/scripts/PhaserInput.js'); }
    }
}
  1. create a 'definitions' folder in the project root and drop the d.ts file into (https://github.com/orange-games/phaser-input/blob/master/build/phaser-input.d.ts)

  2. add the path to this file into the "files" array in the tsconfig.jsonfile.

But when, in my state preload function, I declare Phaser.Plugin.PhaserInput, it doesn't work.

Am I missing something?

Working with loaded JSON

Hi, thanks for creating this Starter Project.

I'm having some trouble trying to use JSON files loaded with assetsUtils. Not sure If it's my lack of understanding or an actual issue.

When I add a JSON to the assets folder, I was assuming I could later access it through Assets.JSON.[name of json].getJSON(). In actuality getJSON() returns a path to the JSON (for example: "assets/0471943eb658d5fbb7f06bf1275a7fc7.json").

But how can I actually access the JSON contents?

assets.ts, assetUtils.ts should be valid TypeScript in strict mode

If strict is activated, via "strict": true, at tsconfig.json, TypeScript throws many errors at utils/assetUtils.ts, but they're just a side effect of how assets.ts is constructed.

This kind of error:

ERROR in ./src/utils/assetUtils.ts
(10,48): error TS7017: Element implicitly has an 'any' type because type 'typeof Images' has no index signature.
. . .
ERROR in ./src/utils/assetUtils.ts
(22,48): error TS7017: Element implicitly has an 'any' type because type 'typeof Spritesheets' has no index signature.

thrown at code that accesses static methods through dynamic class definitions inside namespaces:

if (!this.game.cache.checkImageKey(Assets.Images[image].getName())) {

TypeScript cannot know what type Assets.Images[image] is, and me neither as each asset generates a class.

After some refactoring, I've found myself rewriting generateAssetsClass.js, and as I'd like to collaborate with this project, I don't want to diverge that much without further debate about options available.

Some relevant points:

  • Namespaces are not used as such and just as keys.
  • Classes are not created to be instantiated and just as containers.

The idea I'm studying is to create some classes:

export class AssetImage {
    constructor(public name: string) {
    }
    getName(): string {
        return this.name;
    }
}

export class AssetImagePNG extends AssetImage {
    constructor(name: string, public getPNG: () => string) {
        super(name);
    }
}

and then generate the code with instances like:

const Assets = {
    Images: {
        backgroundTemplate: new AssetImagePNG("background_template", () => require("assets/images/background_template.png"))
    }
};

The main advantage should be that TS can follow those types and it simplifies the generator and the generated assets.ts.

Issues? Options? Ideas?

Dependency on git

This project assumes that it is running in a git folder, I'm looking for a suggestion on how to remove that.
Right now, in webpack.dev.config.js , replacing:

'GIT_REVISION': '\"potato\"',

is a working workaround (the escaped quotes are required since the value is interpreted as-in (which seems bad)), but is hackish at best.

Not building on current version

trying to build the project after download the zip file.
Getting this error

npm run server:dev

fatal: Not a git repository (or any of the parent directories): .git
child_process.js:518
    throw err;
    ^

Error: Command failed: git rev-parse HEAD
fatal: Not a git repository (or any of the parent directories): .git

    at checkExecSyncError (child_process.js:475:13)
    at execSync (child_process.js:515:13)
    at module.exports (/Users/keenan/development/lastlight/node_modules/git-revision-webpack-plugin/lib/helpers/run-git-command.js:25:34)
    at GitRevisionPlugin.commithash (/Users/keenan/development/lastlight/node_modules/git-revision-webpack-plugin/lib/index.js:42:10)
    at Object.<anonymous> (/Users/keenan/development/lastlight/webpack.dev.config.js:29:68)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at requireConfig (/Users/keenan/development/lastlight/node_modules/webpack/bin/convert-argv.js:96:18)
    at /Users/keenan/development/lastlight/node_modules/webpack/bin/convert-argv.js:109:17
    at Array.forEach (native)
    at module.exports (/Users/keenan/development/lastlight/node_modules/webpack/bin/convert-argv.js:107:15)

Write files

Hi,

How to use the node fs module to write file when the game is running in Electron?

Thanks for your help!

uglify error: Unexpected token: name (ImagesBackgroundTemplate)

Hi,
I noticed that the latest version (master) has an error with build:dist .
Error:
ERROR in game.min.js from UglifyJs Unexpected token: name (ImagesBackgroundTemplate) [game.min.js:88,10]

Uglify can't parse es6 builds.

I had to change the target in tsconfig.json to es5 and include lib: ["es2016", "dom"]

here my tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": false,
    "experimentalDecorators": false,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2016",
      "dom"
    ]
  },
  "files": [
    "./src/globals.d.ts",
    "./src/app.ts",
    "./node_modules/phaser-ce/typescript/phaser.comments.d.ts"
  ]
} 

Webpack Error while loading assets

Hi,

I made a fresh clone of your repo to give it a try. However I have the following error while running npm run server:dev

ERROR in ./assets/atlases/preload_sprites_array.png Module parse failed: e:\MyFolder\assets\atlases\preload_sprites_array.png Unexpected character '�' (1:0) You may need an appropriate loader to handle this file type. (Source code omitted for this binary file) @ ./src/assets.ts 30:65-116 @ ./src/states/boot.ts @ ./src/app.ts @ multi (webpack)-dev-server/client?http://localhost:9000 ./src/app.ts

My node version is v6.9.5 and I'm using windows 7

Any idea ?

Integrate PusherJS

Hi, I'm having a hard time to integrate pusher here.

Can you help me to set it up?

Thanks.

debugging

I can't see sourcemaps when debugging in chrome, only plain js. How to debug code with this template?

assetUtils.ts is not es6 ready

Hi
assetutil is not es6 ready. It uses reflection api that is not available in es6.
I fixed this locally for resources I use ...

The rest of the code seems to be es6 ready (not promising full test coverage :)).

Added two functions that do the same and are es6 ready:

private static loadImages() {
        for (let image in Assets.Images) {
            if (!this.game.cache.checkImageKey(Assets.Images[image].getName())) {
                if (Assets.Images[image].getPNG !== undefined) {
                    this.game.load.image(Assets.Images[image].getName(), Assets.Images[image].getPNG());
                } else if (Assets.Images[image].getJPG !== undefined)  {
                    this.game.load.image(Assets.Images[image].getName(), Assets.Images[image].getJPG());
                } else {
                    throw 'not supported';
                }
            }
        }
    }
    
    private static loadAtlases() {
        for (let atlas in Assets.Atlases) {
            if (!this.game.cache.checkImageKey(Assets.Atlases[atlas].getName())) {
                let imageOption = null;
                let dataOption = null;

                if (Assets.Atlases[atlas].getPNG !== undefined) {
                    imageOption = Assets.Atlases[atlas].getPNG;
                } else if (imageOption = Assets.Atlases[atlas].getJPG !== undefined)  {
                    imageOption = Assets.Atlases[atlas].getJPG;
                } else {
                    throw 'image format not supported';
                }

                if (Assets.Atlases[atlas].getXML !== undefined) {
                    this.game.load.atlasXML(Assets.Atlases[atlas].getName(), imageOption.call(), Assets.Atlases[atlas].getXML());
                } else if (Assets.Atlases[atlas].getJSONArray !== undefined) {
                    this.game.load.atlasJSONArray(Assets.Atlases[atlas].getName(), imageOption.call(), Assets.Atlases[atlas].getJSONArray());
                } else if (Assets.Atlases[atlas].getJSONHash !== undefined) {
                    this.game.load.atlasJSONHash(Assets.Atlases[atlas].getName(), imageOption.call(), Assets.Atlases[atlas].getJSONHash());
                } else {
                    throw 'atlas format not supported';
                }
            }
        }
    }

Uglify not working: throw new _ValidationError2.default(ajv.errors, name);

When running npm run build:dist, I was getting the error below (after adding additional debug statements):

> webpack --config webpack.dist.config.js --progress --colors

[ { keyword: 'additionalProperties',
    dataPath: '[\'compress\']',
    schemaPath: '#/additionalProperties',
    params: { additionalProperty: 'compress' },
    message: 'should NOT have additional properties' },
  { keyword: 'additionalProperties',
    dataPath: '[\'screw_ie8\']',
    schemaPath: '#/additionalProperties',
    params: { additionalProperty: 'screw_ie8' },
    message: 'should NOT have additional properties' } ]
/home/aero/dev/mars-delivery/game/node_modules/schema-utils/dist/validateOptions.js:41
    throw new _ValidationError2.default(ajv.errors, name);

To fix it, I had to change

        new Uglify({
            compress: {
                warnings: false
            },
            screw_ie8: true
        }),

to

        new Uglify(),

Hacktoberfest 2017!

The annual Hacktoberfest is back!

Please feel free to take a look at the issues already present or if you think of something else to contriute; whether it be a bug fix, new feature, optimization, or whatever else.

We'd love the help! Remember to have fun and get those 4 pull requests in by Halloween 🎃

npm install not installing dependencies

Hey! Tried using this as an experimental test to see if I would go ahead and try using this instead of writing it all up myself--and I can't even get the dependencies to install. I tried installing that dependency below globally and it works--but I still get the below error regardless. Running Node_v8.4.0

I'm not sure if something with my environment is wonky--or if something is actually broken--but heads up regardless. I tried using the Bash terminal for npm install--also tried using Webstorm's built in support for installing the dependencies--as well as Atom's terminal. All the same.

What I am not actually understanding--is why npm is trying to resolve references in setupGameSize when all I want it to do is install deps?? Am I overlooking something?

image

UPDATE:

More information I have come across. I was able to get past the error above AFTER globally installing the dependency--then using an npm link

However, I had to do this for every single dependency in the package.json. I am unsure why. I am going to attempt to completely blow away and reinstall Node--but I can't imagine it would be causing problems because I use it for Angular Development on a daily basis.

Some tutorial on making this project

I know this may sound odd, but I want to learn it.

I am new to Front End development, and setting up a development environment is always the most frustrating thing. Lots of tools but I do not know how to choose, or which is better. Webpack, Gulp, Grunt, Babel... And most tutorials ignore telling this HARD process, just let learner choose a favorite text editor.

I analysed package.json in this project, and npm js scripts. But it's too hard for a newbie like me.

So would you please shed some light on how to set up a development environment for Phaser? Just to say telling me how you made this project step by step.

Days ago, I wanted to add source map for webpack for better debug. But it failed. Then I tried to set up a Phaser project from scratch, also no good. Webpack ran, but without showing my index.html, it showed a list of js files.

This is why I made this issue. Or would you recommend me some tutorials on this?

Thank you!

assetUtils.ts

Hi,
added some text content and it seems that assetUtils. loadText is just not implemented correctly but rather a copy of loadXML.

I changed it to this but have not been able to verify it works as designed as I am fighting other errors.

private static loadText() {
        for (let text in Assets.Text) {
            if (!this.game.cache.checkTextKey(Assets.Text[text].getName())) {
                this.game.load.text(Assets.Text[text].getName(), Assets.Text[text], true);
            }
        }
    }

Local Font Support

As for Chinese and Japanese languages, we should use a local font file(*.ttf file).

I am making a game with lots of dialogs, it will use many glyphs so bitmap is not suitable for Chinese.
Anyways to use local TTF fonts?

Getting Error running

Just cloned the repo, after npm install run npm run server:dev

ERROR in ./src/states/title.ts
(45,130): error TS2339: Property 'SpritesheetsMetalslugMummy' does not exist on type 'typeof Spritesheets'.

How to set aspect-ratio to 16:9

1: I can't set aspect-ratio to 16:9. I tried the val 16:9, 16/9, and I should not use 1.77777777..... I think.
2: After trying some times for problem 1, I can't set scale mode any more, it fix on USER-SCALE

Asset Generation issues...

I'm experiencing issues when building for dev/dist that are annoyingly happening only 90% of the time. When asset generation is happening, quite often the compiler falls over with 100s of

"ERROR in ./src/states/Instructions.ts
(25,86): error TS2339: Property 'BitmapFonts' does not exist on type 'typeof "C:/Users/XX/XX/XX/XX/src/assets"'.

It feels like the asset generation has not finished before it tries to compile the JS - meaning I get loads of errors of non-existent assets.

I did try and add in the few lines from the latest merges, but it made no difference.

Any help would be great :)

Spritesheet not generating

Hello,
it seems it's not possible to generate spritesheets.
I dropped a file "file[10,10].png" in assets and a spritesheet is not generated.

Looking at the code, it seems this portion is looking at the file extension:
var spritesheetData = gameAssets[i][0].match(/\[(-?[0-9],?)*]/);

I don't feel familiar with this part, can you confirm there's a problem with this?

Fail to change scale mode via "npm run setupGameSize"

I want to change scale mode from default's "USER_SCALE" to "SHOW_ALL" by using command:

npm run setupGameSize --width 800 --height 800 --scale-mode SHOW_ALL
But in game's console log:

DEBUG....................... true 
           
GIT_REVISION................ cc15ebdb3c91e11e0ebe53cec0454a8438a6ef58
           
SCALE_MODE.................. USER_SCALE
           
DEFAULT_GAME_WIDTH.......... 800
           
DEFAULT_GAME_HEIGHT......... 500
           
MAX_GAME_WIDTH.............. 888
           
MAX_GAME_HEIGHT............. 600 
           
game.width.................. 800 
           
game.height................. 580
           
GOOGLE_WEB_FONTS............ Barrio
           
SOUND_EXTENSIONS_PREFERENCE. webm,ogg,m4a,mp3,aac,ac3,caf,flac,mp4,wav

It's still USER_SCALE. Also, the game width and height are not changed.

Security risk for webpack-dev-server

Describe the bug
When using npm audit, this results in 1 high severity vulnerability for webpack-dev-server v3.1.10.

To Reproduce
Steps to reproduce the behavior:

  1. run npm audit
  2. See audit report

Expected behavior
No vulnerabilities 😄

Report

                       === npm audit security report ===

# Run  npm install [email protected]  to resolve 1 vulnerability

  High            Missing Origin Validation

  Package         webpack-dev-server

  Dependency of   webpack-dev-server

  Path            webpack-dev-server

  More info       https://nodesecurity.io/advisories/725

Additional context
Updating webpack-dev-server to 3.1.14 should fix this.

I've made a pull request #69.

Map

Is there any support for map's loading via load.tileMap?

Add Multi-platform Build Support

I create this issue just for keep track of the progress of multi-platform support: for Desktop(via Electron) and for Mobile(via Cordova).

There are some starter project.

For Electron:
Eletron

For Cordova:
Cordova

Thank you for your awesome work! Your project makes game-making have more fun instead of losing myself in "setup a development environment for a long time then give up".

👍

Failed to compile after cloning repository

image

There are a number of compile errors when running the project with npm run server:dev. Forgive me if I'm missing a step but I have tried it a couple times now. Cheers.

TypeScript definitions

Quick questions, where are the typescript definitions coming from? They're no working for me ([ts] Cannot find name 'Phaser') and I can't find them on DefinitelyTyped. How do you make them work with this project?

Help me with my project

@rroylance Sorry to add another issue here, but I don't know other ways to contact you.

I made a template project from scratch with TypeScript, webpack, webpack dev server.
https://github.com/Majirefy/PhaserTest
I copied some configuration from your project. But now there are some problems.

Visual Studio Code failed to give me code completion.
It will say "cannot find Phaser" if you add codes in app.ts file.

Do you use VSC? How to config?

Debugging

Hello. I love your project!

However, I am not sure, how to debug it.

In my similar, simpler, project, I use the "Debugger for Chrome" plugin in VS Code. For this I need to have launch.json in .vscode folder configured. I then create breakpoints and use the Debug panel to start/play debugging. It opens new chrome window and when I e.g. click on something it shows me the line in VS Code and all the values etc.

Please, can you let me know, how you do it?

Thanks and again - great template!

Missing License

Hi there,

would love to use your framework but can't as you have not offered a license and with that it is free. If you want it to be free I personally like MIT 2.0.

Cheers,
Carsten

Suggestion for tslint.json

Just a suggestion for the tslint.json file.

I noticed that it's basically the same as phaser's own tslint, with the exception of one setting. You use single quotes instead of double.

You could simplify the tslint.json file to this (I also added a max-line-length option, which I think helps making code more readable), and automatically use the default phaser settings, and extending those for your own overrides:

{
  "extends": "./node_modules/phaser-ce/typescript/tslint.json",
  "rules": {
    "quotemark": [
      true,
      "single"
    ],
    "max-line-length": [true, 140]
  }
}

Specify Sprite Sheet with no JSON.

Sometimes we need load a sprite sheet image file with no JSON like:

this.game.load.spritesheet('uiButtons', Assets.Images.ImagesUiButtons.getPNG(), 260, 100);

As you mentioned before, maybe we can specify these files with formatted name like rings[100,100].png, which indicates the frame size is 100*100.

Or just create a folder called sprite sheet and exclude it from auto loading, let users load manually.

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.