Coder Social home page Coder Social logo

rblopes / generator-phaser-plus Goto Github PK

View Code? Open in Web Editor NEW
143.0 15.0 14.0 7.12 MB

[๐Ÿ›‘ DISCONTINUED] It has been a long journey but development of `generator-phaser-plus` is now over. I recommend you have a look and fork `yandeu/phaser-project-template` instead.

Home Page: https://github.com/yandeu/phaser-project-template

License: MIT License

JavaScript 98.26% HTML 1.74%
phaser gulp babel yeoman-generator browsersync webpack

generator-phaser-plus's Introduction

๐Ÿ›‘ DISCONTINUED ๐Ÿ›‘

It has been a long journey but development of generator-phaser-plus is now over. I recommend you have a look and fork yandeu/phaser-project-template instead. This repository will be archived shortly.


Create Phaser Web games with ease.

generator-phaser-plus is a Yeoman generator that makes starting up Phaser 3 game projects dead simple.

Table of Contents

Installation and Usage

NOTE: Assuming you have at least the latest Node.js release with long-term support installed.

Download and install generator-phaser-plus from npm, using either npm or Yarn.

New on v3.0.0: Installing Yeoman to use generator-phaser-plus is completely optional.

npm install --global generator-phaser-plus

Create a New Phaser Game Project

  1. First, create a new directory to keep you project contents and go into it.

    mkdir my-awesome-game/
    cd my-awesome-game/
  2. Run phaser-plus and fill in the short questionnaire.

    phaser-plus

    Screenshot

  3. After the installation of the development kit finishes, fire up your project running:

    npm start                           # Or: `yarn start`

Generators

generator-phaser-plus comes with a few handy generators to speed up some common Phaser game development tasks.

HINT: You can read a short description of what a command does running it with the --help option.

object generator

phaser-plus object <name>

Creates game object classes. This generator will ask which Phaser game object class your want your new game object class to extend from.

  • Alias: o.
  • Arguments:
    • name: The object class name. Required.

plugin generator

Beginning with release 3.8.0, Phaser enhanced its plugin manager and added support for two kinds of custom plugins: Global Plugins and Scene Plugins.

Global plugins are instantiated once and persist throughout the whole game session.

Scene plugins are instantiated with each scene, and each instance is tied to its host scene life cycle.

generator-phaser-plus can create the blueprint of a custom Phaser plugin to use with your games. If you need to add some extra functionality to your game, for example, integrating an external library into Phaser, you can achieve that using a custom plugin.

To create a custom plugin, use the following command:

phaser-plus plugin <name> --type <global|scene>
  • Command Alias: p.

  • Arguments:

    • name: The plugin class name. Required.
  • Options:

    • type: Alias: t. The kind of plugin to generate. Can be either global (the default) or scene.

scene generator.

phaser-plus scene <names...>

Creates scene classes and updates the scenes/index.js module with the new entries.

  • Alias: s.
  • Arguments:
    • names. Required. The name (or names) of the scene class.

A Brief Tutorial

This step-by-step tutorial takes the official game example as a starting point to guide you through generator-phaser-plus workflow.

The tutorial is written from an absolute beginners perspective, but assumes the user already have a little understanding of JavaScript syntax. Also, some previous Node.js development experience and some reasoning around the terminal emulator and command-line tools is desirable but not a necessary requirement to complete the tutorial.

NOTE: Some portions of sample code are formatted using a simplified 'diff' format. If you are not familiar with that format, keep in mind that whenever you see a line beginning in a plus (+) sign, you should add that highlighted line to your code. Conversely, lines to be deleted begin with a minus (-) sign.

First steps

When you fire up your game project for the first time, you should see a floating Phaser 3 logo rotating on your browser.

Screenshot

Your new game project is alive. We are ready to start producing some code and add the necessary parts to create a real game โ”€ that is, one that is more than just a spinning logo. Open up your game project in your favorite code editor or IDE, if you did not do so already, to start editing it.

Your first game scene

We will start by creating a new "Title" scene, using the scene generator.

To add that new game scene to your game project, run the following command:

phaser-plus scene title

That command will execute the scene generator to create a stub of a new Phaser Scene class. A scene is where all action in a Phaser game happens. For example, we use scenes to manipulate physics, update the game logic, process player input, display the player's score and so on.

The scene we are creating here will be named Title, and will serve as your game's title screen, with a simple "Start Game" button. Its code will be contained in a file named title.js, under the app/scripts/scenes/ directory.

Screenshot

Immediately after you hit Enter, the generator will create your new scene file but will halt for a moment. This is OK. The generator is now trying to update the scenes index (the app/scripts/scenes/index.js file) so you don't have to do that manually. Because it is modifying an already existing file, the generator gives you the opportunity to review these changes. To see which lines are being added to that file, just type D, followed by Enter, to get a preview of the changes. When you finish reviewing, or just want to proceed anyway, type Y and Enter to answer "Yes" and confirm.

Screenshot

Now that you added a new scene it is time to start using it. For that, you need to do a small update on the scene responsible for defining the game's splash screen appearance.

The SplashScreen class takes care of a few chores. First, it tells Phaser which media assets it must load. Meanwhile, it displays the cover art of your game and a progress bar telling the player how much time for the game engine to finish performing its initialization tasks remain before it can actually start running the game itself.

When all media assets finish loading, it starts the Game scene, with the rotating Phaser logo we saw earlier. You want to change that so the game jumps to the Title scene instead. Open the app/scripts/scenes/splash-screen.js file and find the create method. Modify it as in the highlighted code excerpt below, so the this.scene.start() method argument reads 'Title' instead of 'Game', and save it.

 create() {
   //  We have nothing left to do here. Start the next scene.
-  this.scene.start('Game');
+  this.scene.start('Title');
 }

Done. Now you will be left with a boring black screen. Don't worry, though, things are about to get interesting soon. Let's take a moment, though, and discuss one important aspect of your game project.

Declaring game assets

The crafting of a game requires not only code. In your project, to ambient your virtual world, you will need to use many kinds of media files, collectively known as game assets. Game assets come in a wide range of types, including:

  • Artwork, like graphical textures and three dimensional models;
  • Audio files for sound effects and background tunes;
  • Many sorts of miscellaneous files defining raw data, like level definitions, board maps and many more.

To use these media assets in your game, however, Phaser must know what kind of files it needs to load so they can be processed and committed into the browser's memory.

To save time, generator-phaser-plus projects follow a simple pattern: You copy files to the app/static/assets/ directory and declare them in the splash screen scene preload() method body.

For this part of the tutorial, we are going to use some files from the Phaser Labs.

After you copy the files to the assets directory, let's declare them. Find the preload() method in the splash screen scene class and modify the highlighted lines as follows:

 //  HINT: Declare all game assets to be loaded here.
-this.load.image('logo');
+this.load
+  .image('logo')
+  .image('sky', 'space3.png')
+  .image('red');

Adding the background to the Title scene

After adding your first media assets, you can start adding the elements of our Title scene. Let's start with the background. Inside the create() method body, type the following code block and save the module.

//  Save the center point coordinates for later reference.
const x = this.cameras.main.width / 2;
const y = this.cameras.main.height / 2;

//  Add the starry sky background.
this.add.image(x, y, 'sky');

In Phaser 3, textures have its origin point set at the center coordinate. We will match that origin point with the center of out game screen.

Creating a flame effect

Let's add a fancy flame effect to the scene. For that, write the following code below the one we added for the background image and save.

//  Create and start an particle emitter.
const flameParticle = this.add.particles('red');
const flame = flameParticle.createEmitter({
  speed: 100,
  scale: { start: 1, end: 0 },
  blendMode: 'ADD'
});

With that, we create a particle emitter. First, we tell Phaser which texture to use as the elementary particle. Then we start the emitter: the parameters tell how long the particles will be visible, starting large and scaling down until they completely disappear. The blendMode is the final touch, giving the texture a bright pink flame effect.

However, our flame is stuck to the top left corner now. We will fix this shortly.

Adding the 'Phaser 3' logo

Add this new code snippet below the flame particle emitter effect code.

//  Add the 'Phaser 3' logo.
const logo = this.add.image(x, 100, 'logo');

//  Attach and make the emitter follow the logo.
flame.startFollow(logo);
Screenshot

That will add the Phaser 3 logo near the top of the screen, with the flame effect attached behind it.

Making the logo bounce around the screen

Our title screen looks cool already, but what if we made it more animated? We could go a little overboard and use physics simulation to make the logo bounce around the screen, why not?

Phaser 3 comes with a selection of features out-of-the-box. Some of those, however, require some tweaking before they can be used in full. The configuration module (app/scripts/config.js) is where the parameters of some Phaser features are kept.

Take a moment to examine the contents of that module if you like. That module contains several tweaks that can be adjusted according to you project needs.

To enable physics simulation, uncomment the export const physics line and modify it, like shown below.

 //  Enable physics simulation and configure parameters. Available  systems are:
 //  - `arcade`: Phaser Arcade Physics 2;
 //  - `matter`: Liam Brummitt's (@liabru) Matter.js;
 //  - `impact`: ImpactJS Physics Engine.
-// export const physics = {};
+export const physics = {
+  default: 'arcade',
+  arcade: {
+    gravity: {y: 200}
+  }
+};

This instructs Phaser to enable the Arcade Physics Engine upon initialization with the given parameters and set it as the default physics engine.

Now, back in the Title scene code, let's replace the lines where the logo is added. To give the logo physics properties, we have to make some adjustments.

//  Add a bouncing Phaser 3 logo.
const logo = this.physics.add.image(x, 100, 'logo')
  .setVelocity(100, -100)
  .setBounce(1, 1)
  .setCollideWorldBounds(true);

Note that we are using this.physics.add.image(/* ... */) instead of this.add.image(/* ... */). The difference is that our image now is managed by the physics engine.

Also note how we are chaining method calls to set the physics properties of the image. We are telling it to ascend momentarily before falling down and bounce up every time it hits the floor of the screen.

Adding a simple text button

To finish this part of the tutorial, let's create a 'Start' button using a simple text label.

//  Add a text label.
const label = this.add.text(x, 400, 'START!!', {
  font: '64px Arial',
  color: 'white',
  stroke: 'black',
  strokeThickness: 6
});

//  Move the origin point to the center, make the label interactive.
label
  .setOrigin(0.5, 0.5)
  .setInteractive();

The first block of code defines the aspect of the text label, its coordinates and text.

In the second block, we move the origin point to the center of the label. Unlike other game objects, text labels have an origin point set at the top left corner. Also, we tell Phaser that this object will react to input interactions through a mouse or a touch screen.

But how do we know our button was clicked or touched, then? Game objects provide a mechanism known as event dispatcher. To explain that in a few words, game objects allow to subscribe to certain events, providing the instructions to be performed when these events occur.

When a player clicks our "start" button, we want to show the "Game" scene, where all the game action will happen. Add the code below to enable the text button.

//  When this label is clicked, move on to the next game scene.
label.on('pointerup', () => this.scene.start('Game'));

Here, we are subscribing to the pointerup event of the text label. When the text label is clicked, a pointerup fires immediately after the mouse button is released. When that happens, we tell Phaser scene manager to start the Game scene.

Now save the Title scene module. You should see a big white text label saying "START!!" on the lower part of the game screen. Click it โ”€ or, if using a mobile device, tap it โ”€ to be taken back to the "Game" scene, with the spinning Phaser logo, we saw earlier.

Screenshot

With that, we have created a fancy Title screen for our little game.

(To be continued...)

Project Setup

Features

Projects created with generator-phaser-plus have the following features out-of-the-box:

  • Gulp, a lean and simple task manager.

  • Webpack for better integration of components and dependencies.

  • Browsersync for cross-device testing.

  • Babel, with babel-preset-env, for authoring scripts using the most recent ECMAScript specification features and syntax additions ensuring compatibility with current browsers and devices.

Application Layout

Media assets and source code are organized in a dedicated app/ directory.

app/
โ”‚
โ”œโ”€โ”€ scripts/            # Where application modules are stored
โ”‚   โ”œโ”€โ”€ objects/        # Custom extended game objects
โ”‚   โ”‚   โ””โ”€โ”€ ...
โ”‚   โ”œโ”€โ”€ plugins/        # Custom private plugins
โ”‚   โ”‚   โ””โ”€โ”€ ...
โ”‚   โ”œโ”€โ”€ scenes/         # Game scenes
โ”‚   โ”‚   โ”œโ”€โ”€ index.js    # Reference module for all game scenes
โ”‚   โ”‚   โ””โ”€โ”€ ...
โ”‚   โ”œโ”€โ”€ config.js       # Contains certain Phaser configuration values
โ”‚   โ””โ”€โ”€ index.js        # The game application entry point routine
โ”‚
โ”œโ”€โ”€ static/             # Static files served by Browsersync
โ”‚   โ”œโ”€โ”€ assets/         # Where game assets are stored
โ”‚   โ”‚   โ””โ”€โ”€ ...
โ”‚   โ””โ”€โ”€ favicon.ico     # A sample Phaser logo favicon
โ”‚
โ””โ”€โ”€ index.html          # Main page template

Development Tasks

Automated tasks solve recurring development operations and help you prepare the application for distribution. A special gulpfile.js/ directory contains the development tasks and its related modules.

NOTE: If you prefer, install the Gulp command-line interface:

npm install --global gulp-cli

Alternatively, the same tasks can be performed using the provided runnable scripts explained below.

There are two main development tasks:

  • default task. This is the main development task, the one you will interact with the most. This task uses Browsersync to start an interactive Web server to test your game in the browser. Under the hood, it uses Webpack to watch application modules for changes, triggering the necessary builds when changes occur. When a build finishes successfully, the page will refresh to show the updated game. It is configured to serve the application code and static assets.

    Can be run with:
    gulp
    npm start
    yarn start
    
  • dist task. The distribution task. When your game is ready, use this task to bundle the application code, its dependencies and static assets. It performs the following jobs, in order:

    • Dispose the previously compiled version of your game, to avoid mixing outdated files.
    • Recursively copy all static assets located under the app/static/ directory.
    • Compile and minify your application modules and dependent libraries.

    After running this task, a working copy of the game will be found in the dist/ directory.

    Can be run with:
    gulp dist
    npm run dist
    yarn dist
    

Configuration

Gulp tasks configuration (gulpfile.js/config/)

Gulp configuration is organized inside the gulpfile.js/ directory.

gulpfile.js/
โ””โ”€โ”€ config/
    โ”œโ”€โ”€ webpack/            //  Webpack configuration modules
    โ”‚   โ”œโ”€โ”€ index.js        //  - The bulk of Webpack settings (entry points, loaders, etc.)
    โ”‚   โ”œโ”€โ”€ plugins.js      //  - Webpack plugins
    โ”‚   โ””โ”€โ”€ uglify.js       //  - Uglify settings
    โ”œโ”€โ”€ babel.js            //  Babel presets and plugins
    โ”œโ”€โ”€ browsersync.js      //  Browsersync settings
    โ””โ”€โ”€ paths.js            //  Describes the project layout

Yeoman metadata (.yo-rc.json)

Yeoman creates a hidden configuration file, storing some information required by generator-phaser-plus. This file also indicates the root of the project for Yeoman, so files created by any generator are relative to this location. Below is a commented sample of a regular .yo-rc.json file.

{
  "generator-phaser-plus": {                        //  The generator name, verified by Yeoman
    "meta": {                                       //  Creation date and generator version
      "createdWith": "3.0.0",
      "creationDate": "2018-01-01T12:34:56.789Z"
    },
    "objects": {                                    //  `object` generator data
      "dest": "app/scripts/objects/"                //  Where custom game objects are stored
    },
    "plugins": {                                    //  `plugin` generator data
      "dest": "app/scripts/plugins/"                //  Where private plugins are stored
    },
    "scenes": {                                     //  `scene` generator data
      "dest": "app/scripts/scenes/",                //  Where new scenes are stored
      "index": {                                    //  Data about the scene index module
        "name": "app/scripts/scenes/index.js",      //  The module name
        "requirePath": "./"                         //  The scenes path relative to that module
      }
    }
  }
}

For example, when using the scene generator, Yeoman will consume the related data to perform its task: the destination directory where the new scene module should be placed, and some other data required to update the scene index module with the new entry.

This file is required by Yeoman and you should keep it in case you want to continue using generator-phaser-plus with your project.

NOTE: You may be asked about .yo-rc.json contents when posting an issue.

Miscellaneous files

Miscellaneous Topics

Managing Dependencies

There will be times you will want to add features not provided by Phaser. This is where plugins and third party libraries come into play.

Thanks to Webpack, integrating npm packages to your project is very simple.

Using npm packages

First, install packages using either npm on Yarn.

npm install <package-name>      # (1)
yarn add <package-name>         # (2)

Let's take for example a fictitious plugin. To use that plugin with your game, open the app/scripts/scenes/preloader.js module and import the plugin in your code.

//  NOTE: This line goes before the scene `class` definition.
import MyPhaserPlugin from 'my-phaser-plugin';

Then, initialize the plugin, as recommended in its documentation.

Manually Adding Third-Party Libraries

Not all libraries are available for distribution through npm, though. In this case, you would have to copy the library scripts to the app/static/ directory of your game project, and to add it to your application, edit the index.html page to include the necessary <script /> tags to load the library. You don't need to import the library to use it in your game application. In general, these kinds of libraries make themselves available using browser globals.

However, this presents two big disadvantages:

  1. Every time you need to update that library to more recent versions, you will have to replace the necessary files manually.

  2. If you are using a version control system, such as Git, to manage your project, you will need to keep track those files in your repository as well.

To conclude, note that this method is not recommended and should be completely avoided. If you happen to find that kind of library, contact the respective authors and ask them to update their work and publish the referring library on npm.

A Few Recommendations

  • When dealing with third-party libraries, take some time to learn what it does. If it's an open-source library, also take some time to study how it works from the implementer's perspective.

  • Check if the library is well maintained, providing support like documentation and test cases, and authors are committed to their work, keeping it up to date and replying to reported issues within a reasonable time.

  • Verify which license apply to that library and if that license is adequate to your project.

  • If you think you found issues using someone's library, double-check your code to see what is wrong. If you are sure the problem is caused by the library itself, do not hesitate to report the authors so they can provide the necessary corrections.

Contributing

Read the contribution guidelines to learn how you can help generator-phaser-plus.

Release Notes

Read the news page for info about the latest release.

License

This software is distributed under the terms of the MIT License.

The remixed Yeoman logo is shared under a Creative Commons Attribution License.

generator-phaser-plus's People

Contributors

budda avatar rblopes 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

generator-phaser-plus's Issues

Getting "Super expression must either be null or a function, not undefined" when extending a Phaser class

First, just want to say I love the work you've done here and I've been using your generator exclusively for my Phaser projects.

I've just begun setting up a new project and encountered this error while extending a Phaser class in the same way that I have previously using this generator. Thinking it may have been something that I did, I set up a fresh project and created a new file extending the Phaser.Tilemap class and sure enough I immediately encountered the same error. Extending something like Phaser.Group works fine. Difference seems to be that I'm using the latest version of your generator for this project. Any help you could provide would be greatly appreciated.

Edit: Looks like the issue was fixed with a recent update

Failed to set-up fully

I just gave it a go slush phaser-plus and npm packed in with the following errors:

npm ERR! Darwin 14.5.0
npm ERR! argv "node" "/usr/local/bin/npm" "install"
npm ERR! node v0.12.7
npm ERR! npm  v2.14.1

npm ERR! Callback called more than once.
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/mike/Code/blox/npm-debug.log
[03:32:27] npm exited with non-zero code 1 , run `npm install` manually
events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: npm exited with non-zero code 1
    at ChildProcess.<anonymous> (/usr/local/lib/node_modules/slush-phaser-plus/node_modules/gulp-install/lib/commandRunner.js:14:19)
    at ChildProcess.emit (events.js:110:17)
    at maybeClose (child_process.js:1015:16)
    at Process.ChildProcess._handle.onexit (child_process.js:1087:5)

Any ideas?

[Bug] Uncaught TypeError: Cannot read property 'sys' of null

*   Which Node.js version: 9.6.1

*   Which package manager (npm or Yarn): Yarn: 1.5.1

*   The project configuration created by Yeoman (the `.yo-rc.json` file).
{
  "generator-phaser-plus": {
    "meta": {
      "createdWith": "3.0.0-beta.2",
      "creationDate": "2018-04-21T22:02:00.600Z"
    },
    "objects": {
      "dest": "app/scripts/objects/"
    },
    "plugins": {
      "dest": "app/scripts/plugins/"
    },
    "scenes": {
      "dest": "app/scripts/scenes/",
      "index": {
        "name": "app/scripts/scenes/index.js",
        "requirePath": "./"
      }
    }
  }
}

When I install all dependencies and run yarn start it runs ok, but gives me the following console error:
Uncaught TypeError: Cannot read property 'sys' of null

Facebook Instant Games issue - can't add plugin

Node 9.2.1

npm

.yo-rc.json
{
"generator-phaser-plus": {
"meta": {
"createdWith": "3.0.0-beta.7",
"creationDate": "2019-06-03T18:33:31.708Z"
},
"objects": {
"dest": "app/scripts/objects/"
},
"plugins": {
"dest": "app/scripts/plugins/"
},
"scenes": {
"dest": "app/scripts/scenes/",
"index": {
"name": "app/scripts/scenes/index.js",
"requirePath": "./"
}
}
}
}

I have added

<script src="https://connect.facebook.net/en_US/fbinstant.6.2.js"></script>

to the index.html file head. I also tried adding it to the body above the comment line where scripts are injected.

I also added

new webpack.DefinePlugin({
// Required by Phaser: Enable Canvas and WebGL renderers.
'CANVAS_RENDERER': JSON.stringify(true),
'WEBGL_RENDERER': JSON.stringify(true),
'PLUGIN_FBINSTANT': JSON.stringify(true)
}),

to the gulpfile.js/webpack/config/plugins.js file but I get the FBInstant is not defined when I add this to my index.js file

export function boot() {
return new Phaser.Game(config);
}
FBInstant.initializeAsync().then(function() {
FBInstant.setLoadingProgress(100);
FBInstant.startGameAsync().then(function() {
boot();
});
});

Any idea what I'm doing wrong? Other development environments do this and it works great, but this generated development environment is the best I've found yet and I would love to make it my go to project creator.

Thanks for your work on this generator.

audio assets

Hello there,

It seems that the audio assets are not loading correctly, I tried ogg and mp3 files without success:

In the assets.js file:

// - Music and Sound effects ------------------------------------------------
'audio': [
{
key: 'totta',
type: 'audio',
url: 'totta.ogg'
}
]

Gives error:

Uncaught TypeError: Cannot read property 'length' of undefined

I didn't find any email to check first if this is really an issue or an error from my part...

Regards

Error running Gulp messages around babel

Everytime i run npm start I always see a block of gulp script errors for babel.

Congrats! Now, launch your project with
npm start and happy hacking :)

$ npm start

> @ start /Users/mike/Code/blox
> gulp default

[20:43:13] Using gulpfile ~/Code/blox/gulpfile.js
[20:43:13] Starting 'dev:lint'...
[20:43:13] Starting 'dev:watch'...
[20:43:13] Finished 'dev:watch' after 14 ms
[20:43:14] Finished 'dev:lint' after 770 ms
[20:43:14] Starting 'dev:scripts'...
[20:43:21] gulp-notify: [Error running Gulp] Cannot find module 'babel-runtime/core-js/object/keys' from '/Users/mike/Code/blox/src'
[20:43:21] gulp-notify: [Error running Gulp] Cannot find module 'babel-runtime/helpers/classCallCheck' from '/Users/mike/Code/blox/src/app/states'
[20:43:21] gulp-notify: [Error running Gulp] Cannot find module 'babel-runtime/helpers/createClass' from '/Users/mike/Code/blox/src/app/states'
[20:43:21] gulp-notify: [Error running Gulp] Cannot find module 'babel-runtime/helpers/possibleConstructorReturn' from '/Users/mike/Code/blox/src/app/states'
[20:43:21] gulp-notify: [Error running Gulp] Cannot find module 'babel-runtime/helpers/inherits' from '/Users/mike/Code/blox/src/app/states'
[20:43:21] gulp-notify: [Error running Gulp] Cannot find module 'babel-runtime/helpers/classCallCheck' from '/Users/mike/Code/blox/src/app/states'
[20:43:21] gulp-notify: [Error running Gulp] Cannot find module 'babel-runtime/helpers/createClass' from '/Users/mike/Code/blox/src/app/states'
[20:43:21] gulp-notify: [Error running Gulp] Cannot find module 'babel-runtime/helpers/possibleConstructorReturn' from '/Users/mike/Code/blox/src/app/states'
[20:43:21] gulp-notify: [Error running Gulp] Cannot find module 'babel-runtime/helpers/inherits' from '/Users/mike/Code/blox/src/app/states'
[20:43:21] gulp-notify: [Error running Gulp] Cannot find module 'babel-runtime/helpers/classCallCheck' from '/Users/mike/Code/blox/src/app/states'
[20:43:21] gulp-notify: [Error running Gulp] Cannot find module 'babel-runtime/helpers/createClass' from '/Users/mike/Code/blox/src/app/states'
[20:43:21] gulp-notify: [Error running Gulp] Cannot find module 'babel-runtime/helpers/possibleConstructorReturn' from '/Users/mike/Code/blox/src/app/states'
[20:43:21] gulp-notify: [Error running Gulp] Cannot find module 'babel-runtime/helpers/inherits' from '/Users/mike/Code/blox/src/app/states'
[20:43:21] gulp-notify: [Error running Gulp] Cannot find module 'babel-runtime/helpers/classCallCheck' from '/Users/mike/Code/blox/src/app/objects'
[20:43:21] gulp-notify: [Error running Gulp] Cannot find module 'babel-runtime/helpers/possibleConstructorReturn' from '/Users/mike/Code/blox/src/app/objects'
[20:43:21] gulp-notify: [Error running Gulp] Cannot find module 'babel-runtime/helpers/inherits' from '/Users/mike/Code/blox/src/app/objects'
[20:43:21] gulp-notify: [Error running Gulp] Cannot find module 'babel-runtime/core-js/object/get-prototype-of' from '/Users/mike/Code/blox/src/app/states'
[20:43:21] gulp-notify: [Error running Gulp] Cannot find module 'babel-runtime/core-js/object/get-prototype-of' from '/Users/mike/Code/blox/src/app/states'
[20:43:21] gulp-notify: [Error running Gulp] Cannot find module 'babel-runtime/core-js/object/get-prototype-of' from '/Users/mike/Code/blox/src/app/states'
[20:43:21] gulp-notify: [Error running Gulp] Cannot find module 'babel-runtime/core-js/object/get-prototype-of' from '/Users/mike/Code/blox/src/app/objects'
[20:43:21] Finished 'dev:scripts' after 7.17 s
[20:43:21] Starting 'dev:server'...
[20:43:21] Finished 'dev:server' after 91 ms
[20:43:21] Starting 'dev'...
[20:43:21] Finished 'dev' after 6.79 ฮผs
[20:43:21] Starting 'default'...
[20:43:21] Finished 'default' after 9.41 ฮผs
[BS] Access URLs:
 ------------------------------------
       Local: http://localhost:3000
    External: http://10.10.1.109:3000
 ------------------------------------
          UI: http://localhost:3001
 UI External: http://10.10.1.109:3001
 ------------------------------------
[BS] Serving files from: static
[BS] Serving files from: build

During the initial npm install the babel modules were all listed without any errors as being installed:

[email protected] node_modules/babel-polyfill
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ””โ”€โ”€ [email protected]

[email protected] node_modules/babel-plugin-transform-runtime
โ””โ”€โ”€ [email protected] ([email protected])

[email protected] node_modules/babelify
โ””โ”€โ”€ [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])

[email protected] node_modules/babel-preset-es2015
โ”œโ”€โ”€ [email protected] ([email protected])
โ”œโ”€โ”€ [email protected] ([email protected])
โ”œโ”€โ”€ [email protected] ([email protected])
โ”œโ”€โ”€ [email protected] ([email protected])
โ”œโ”€โ”€ [email protected] ([email protected])
โ”œโ”€โ”€ [email protected] ([email protected])
โ”œโ”€โ”€ [email protected] ([email protected])
โ”œโ”€โ”€ [email protected] ([email protected])
โ”œโ”€โ”€ [email protected] ([email protected])
โ”œโ”€โ”€ [email protected] ([email protected], [email protected], [email protected])
โ”œโ”€โ”€ [email protected] ([email protected], [email protected])
โ”œโ”€โ”€ [email protected] ([email protected], [email protected], [email protected])
โ”œโ”€โ”€ [email protected] ([email protected], [email protected], [email protected])
โ”œโ”€โ”€ [email protected] ([email protected], [email protected], [email protected])
โ”œโ”€โ”€ [email protected] ([email protected], [email protected])
โ”œโ”€โ”€ [email protected] ([email protected], [email protected], [email protected], [email protected])
โ”œโ”€โ”€ [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
โ”œโ”€โ”€ [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
โ”œโ”€โ”€ [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
โ””โ”€โ”€ [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])

Handling assets preloading

How is asset preloading handled in this version?

In Generator Phaser+ v2 there was in src/assets.js file with an array of files in - and then a states/PreLoader.js to load it all in. I don't see anything in the new structure that gets generated?

I noticed in your snake game repo you've added an extra constants directory and stuck an assets.js in there. Is that the new intended way but it's missing from the auto-generated files at the moment?

Migrate to Yeoman?

Been considering migrating this generator to Yeoman for quite a while. Some limitations of using Gulp as a scaffolding tool are showing up and these may become more difficult to address over time.

My main concerns are:

  1. Testing: current test suites are brittle, but not on purpose. Some cases, like inspecting the contents of some generated files, are not covered yet. Writing some of these tests require reading the Gulp streaming internals directly. I can write the necessary fixtures for that (I'll have to research how to accomplish this, though), but I'm pondering if this is worth all the trouble.
  2. gulp-install: incompatible changes made to this task plugin since 0.3.0 are incompatible with the current project setup. Version 0.4.0 conflicted Bower and tests. Now, Bower is gone from the template project, so upgrading to 0.4.0 is not a problem, but tests run much slower with that version. 0.5.0 completely breaks the test suites, and I couldn't get it work at all. Again, I may replace this plugin with a more suitable one, perhaps gulp-spawn but, again, I'm considering if I should be doing this.

Suffice to say that much of these issues are addressed in Yeoman already. Only thing that holds me back is there are many Yeoman generators related to Phaser published already.

Should I decide to move forward and begin developing a new project based on this one's project template, further development and support for slush-phaser-plus will cease and its npm package will be deprecated in favor of the new solution instead.

I may be adding more details to this issue later.

Potential Improvement - auto add JSON files when generating project

I think it's a best-practice to export strings, integers, dimen, font definitions, and IDK what else to external files so it's easier to change them when the project becomes large. I know Android projects follow this design paradigm. I have all my JSON in assets/json, load it on preload, and then create aliases once preload finishes. That allows me to do things like:

//Scale to device pixelRatio - consistent dimensions across all screens
this.game.dimen = this.game.cache.getJSON('dimen');
for (var dimension in this.game.dimen) { //adjust dimensions for different screen densities
  this.game.dimen[dimension] = this.game.dimen[dimension] * window.devicePixelRatio;
}

[Suggestions] responsive screen resolution

since phaser 3 doesn't t have proper scale manager yet(or never). If you add support for the different screen sizes that would be wonderful. also, orientation(check) support, Thank you.

Game.js does not rebuild on save

I'm on Mac OSX 10.10.5 in a dev environment.

I've built a test project straight from the generator and am serving via gulp or npm start.

If I go into Logo.js under Objects and change the angle to say, 0.5 or 1.0 and save, gulp reports that game.js was changed (and the browser refreshes). However, the result of the change isn't persisted to game.js until I kill the server and restart it. There are no lint warnings or errors in evidence.

Any ideas what this could be?

Having to save files twice to get them working in browser

When I edit a file in Atom editor I need to save it twice before the new code is available in my browser, Chrome.

I can see the gulp stuff working in the terminal on each save -- but the new files are not being re-loaded in the browser it seems.

Is there a way to force the web browser to be using the new build output without me sacing each edited file twice?

Some inconsistence in the small tutorial.

Hi to you, I hope you have a great day and i would like to let you know that this generator is amasing! Good job really.

I found a small issue in your tutorial tough.

In the ''declaring game assets section'', you say we need to find the preload() method in the new title.js to load our assets. There is none since by default the generator create only the create and update method, maybe add a notice to use the --customize suffix?

PS: The assets seems to be handled in some way by the assets.js files. (maybe its for objects assets more than small assets inside scene classes). It would be nice to know how to take advantage of that with spritesheet and more complex type of assets.

Including 3rd party Phaser Plugins

This is more a question of approach

If I wanted to include a 3rd party plugin, installed via NPM or otherwise, what would be the best way to do that?

e.g, I've tried installing this plugin, but it doesn't seem to be part of the deployment process. Does it need to be included in index.html manually?

Dropping support for Node.js 0.12 in upcoming releases

This notice is a heads-up to the people using generator-phaser-plus under old Node.js releases. Currently, generator-phaser-plus is developed ensuring its compatible with the old Node.js 0.12 series.

In order to keep evolving the program and deliver the best Yeoman generator for Phaser Web game projects for everyone, I've decided it's time to push the boundaries a bit further. That means the currently planned 0.7.x will be the last version guaranteed to work with Node.js 0.12.

After that, the base Node.js version of generator-phaser-plus will become Node 4.

If you're a Node.js developer, no matter if a casual or a professional one, using Phaser and generator-phaser-plus to create games, you're encouraged to upgrade to, at least, the latest stable Node.js release.

How I know which Node.js version I'm running?

Just fire up your terminal emulator or command prompt of choice and run node --version.

What to expect when these changes take effect?

Developers using Node.js 0.12 will no longer be able to update the generator-phaser-plus package using npm, and both generator and its template projects are expected to no longer work under Node.js environments older than release 4.0, giving errors and not being able to run.

Why Node.js 4?

It's the current LTS release, supported by the Node.js Foundation until March 2018. Also, Node.js 0.12 end-of-life is scheduled to the end of December 2016.

Object generator fails with error

When trying to generate an object i get:

$ yo phaser-plus:object
Object class generator:
? What's the name of the object? Shape
? (Optional) What does this object do? Represents a single shape on the grid.
? From which base class this object extends? Group
? Is that OK to proceed? Yes
events.js:154
      throw er; // Unhandled 'error' event
      ^

TypeError: Cannot read property 'objects' of undefined
    at module.exports.yeoman.Base.extend.writing (/usr/local/lib/node_modules/generator-phaser-plus/generators/object/index.js:16:38)
    at Object.<anonymous> (/usr/local/lib/node_modules/generator-phaser-plus/node_modules/yeoman-generator/lib/base.js:436:25)
    at /usr/local/lib/node_modules/generator-phaser-plus/node_modules/run-async/index.js:24:25
    at /usr/local/lib/node_modules/generator-phaser-plus/node_modules/yeoman-generator/lib/base.js:448:8
    at processImmediate [as _immediateCallback] (timers.js:383:17)

Class inheritance from plugins

I'm using an external plugin called phaser-plugin-isometric to create isometric game spaces. I add this plugin to Phaser via simple command within the preload() method of my Boot state:

preload () {
    // Load the graphical assets required to show the splash screen later.
    this.load.pack('boot', null, assets);
    this.game.plugins.add(new Phaser.Plugin.Isometric(this.game));

It seems to work fine in all forthcoming states as well.

It, among other things, extends Phaser object with isoSprite function that creates isometric sprites. It works like charm when I use it explicitly in my Game state:

 tile = this.game.add.isoSprite(xx, yy, 0, 'tile', 0, this.isoGroup);

I would like to be able to describe object classes that inherit from isoSprite the same way they can inherit basic Sprite class from Phaser with something like this:

/* Tile object class, creates isometric tiles
*/
export default class Tile extends Phaser.isoSprite {

However I have found out that in this case the isoSprite method appears undefined. How can I make it visible in the scope of my object class?

Any documentation

For Phaser fiddlers who are just dipping their toe in the environment could be nice but some documentation on getting started would be useful.

Covering such basic things as:

  • where to put the game/app js files for the project.
  • how to upgrade phaser when a new release is available.
  • where to dump game assets in the created directory structure
  • any explanations about the built in Android & iOS support i see

Hopefully this info wont care about slush vs Yeoman issue either.
Enable the Github Wiki for the project to get started?

npm install is failing for me on Windows 10

I don't know if I'm doing something wrong or something is wrong with my config but I'm trying to install generator-phaser-plus and it's not working.

Via NPM and I get the following error.

$ npm install -global generator-phaser-plus
npm ERR! path C:\Users\Jesse\AppData\Roaming\npm\node_modules\generator-phaser-plus\cli.js
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall chmod
npm ERR! enoent ENOENT: no such file or directory, chmod 'C:\Users\Jesse\AppData\Roaming\npm\node_modules\generator-phaser-plus\cli.js'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Jesse\AppData\Roaming\npm-cache\_logs\2018-02-13T23_29_20_809Z-debug.log
/c/Program Files/nodejs/npm: line 34: 12576 Signal 112              (core dumped) "$NODE_EXE" "$NPM_CLI_JS" "$@"

I can't see the package in my global node_modules folder.

Installing via Yarn appears to work (I can see the folder in Yarn's global node_modules folder) but after installation running phaser-plus returns phaser-plus: command not found

Tests

What needs testing:

  • The default generator task
  • All subgenerator tasks
  • Inquirer input validators
  • Inquirer validation filters
  • "Transforms"
  • Project configuration fixtures

Problem with lib/post_install.js and gulp?

> node lib/post_install.js

npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN [email protected] requires a peer of ajv@^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"android","arch":"arm"})

added 976 packages in 178.255s

Congrats! Now, launch your project using
npm start and happy hacking :)
$ npm start

> @ start /data/data/com.termux/files/.../testproject2
> gulp

sh: 1: gulp: not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! @ start: `gulp`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the @ start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /data/data/com.termux/files/home/.npm/_logs/2018-02-21T07_23_40_153Z-debug.log

Tried a yarn add gulp

success Saved 689 new dependencies.
...
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]

Yet still getting gulp not found?

Also having trouble with fsevents so that might explain some of it. Thanks! So close though.

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.