-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from RobotlegsJS/phaser
Migrate to Phaser v3
- Loading branch information
Showing
78 changed files
with
60,766 additions
and
978 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
RobotlegsJS Phaser Extension | ||
=== | ||
# RobotlegsJS Phaser Extension | ||
|
||
[![GitHub license](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobotlegsJS/RobotlegsJS-Phaser/blob/master/LICENSE) | ||
[![Gitter chat](https://badges.gitter.im/RobotlegsJS/RobotlegsJS.svg)](https://gitter.im/RobotlegsJS/RobotlegsJS) | ||
|
@@ -12,61 +11,125 @@ RobotlegsJS Phaser Extension | |
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier) | ||
|
||
Integrate [RobotlegsJS](https://github.com/RobotlegsJS/RobotlegsJS) | ||
framework with [Phaser](http://phaser.io). | ||
framework with [Phaser](https://github.com/photonstorm/phaser). | ||
|
||
Usage | ||
--- | ||
## Installation | ||
|
||
You can get the latest release and the type definitions using [NPM](https://www.npmjs.com/): | ||
|
||
```bash | ||
npm install @robotlegsjs/phaser --save-prod | ||
``` | ||
|
||
Or using [Yarn](https://yarnpkg.com/en/): | ||
|
||
```bash | ||
yarn add @robotlegsjs/phaser | ||
``` | ||
|
||
From version `0.2.0` of this package, the [Phaser](https://github.com/photonstorm/phaser) dependency was moved to **peerDependencies**, | ||
allowing the final user to choose the desired version of the `phaser` library on each project. | ||
|
||
The `@robotlegsjs/phaser` package is compatible with versions between the `>=3.11.0 <4` version range of `phaser` library. | ||
|
||
As example, when you would like to use the version `3.11.0` of `phaser` library, you can run: | ||
|
||
```bash | ||
npm install [email protected] reflect-metadata --save-prod | ||
``` | ||
|
||
or | ||
|
||
```bash | ||
yarn add [email protected] reflect-metadata | ||
``` | ||
|
||
Then follow the [installation instructions](https://github.com/RobotlegsJS/RobotlegsJS/blob/master/README.md#installation) of **RobotlegsJS** library to complete the setup of your project. | ||
|
||
**Dependencies** | ||
|
||
+ [RobotlegsJS](https://github.com/RobotlegsJS/RobotlegsJS) | ||
+ [tslib](https://github.com/Microsoft/tslib) | ||
|
||
**Peer Dependencies** | ||
|
||
+ [Phaser](https://github.com/photonstorm/phaser) | ||
+ [reflect-metadata](https://github.com/rbuckton/reflect-metadata) | ||
|
||
## Usage | ||
|
||
```ts | ||
/// <reference path="../node_modules/phaser-ce/typescript/phaser.d.ts" /> | ||
/// <reference path="../node_modules/@robotlegsjs/phaser/definitions/phaser.d.ts" /> | ||
|
||
import "reflect-metadata"; | ||
import * as Phaser from "phaser"; | ||
|
||
import { Context, IContext, MVCSBundle } from "@robotlegsjs/core"; | ||
import { PhaserBundle, ContextStateManager } from "@robotlegsjs/phaser"; | ||
|
||
import { StateKey } from "./constants/StateKey"; | ||
|
||
import { Boot } from "./states/Boot"; | ||
import { Preload } from "./states/Preload"; | ||
import { GameTitle } from "./states/GameTitle"; | ||
import { Main } from "./states/Main"; | ||
import { GameOver } from "./states/GameOver"; | ||
import { ContextSceneManager } from "../src/robotlegs/bender/extensions/contextSceneManager/impl/ContextSceneManager"; | ||
import { PhaserBundle } from "../src/robotlegs/bender/bundles/phaser/PhaserBundle"; | ||
|
||
import { GameConfig } from "./config/GameConfig"; | ||
import { StateMediatorConfig } from "./config/StateMediatorConfig"; | ||
import { SceneMediatorConfig } from "./config/SceneMediatorConfig"; | ||
|
||
import { SceneKey } from "./constants/SceneKey"; | ||
|
||
class Game extends Phaser.Game { | ||
import { Boot } from "./scenes/Boot"; | ||
import { Main } from "./scenes/Main"; | ||
import { Preload } from "./scenes/Preload"; | ||
|
||
export class Game extends Phaser.Game { | ||
private _context: IContext; | ||
|
||
constructor() { | ||
|
||
super(window.innerWidth * window.devicePixelRatio, window.innerHeight * window.devicePixelRatio, Phaser.AUTO); | ||
super({ | ||
type: Phaser.CANVAS, | ||
width: 800, | ||
height: 600, | ||
backgroundColor: "#010101", | ||
parent: "phaser-example" | ||
}); | ||
|
||
this._context = new Context(); | ||
this._context.install(MVCSBundle, PhaserBundle) | ||
.configure(new ContextStateManager(this.state)) | ||
.configure(StateMediatorConfig) | ||
this._context | ||
.install(MVCSBundle, PhaserBundle) | ||
.configure(new ContextSceneManager(this.scene)) | ||
.configure(SceneMediatorConfig) | ||
.configure(GameConfig) | ||
.initialize(); | ||
|
||
this.state.add(StateKey.BOOT, Boot, false); | ||
this.state.add(StateKey.PRELOAD, Preload, false); | ||
this.state.add(StateKey.GAME_TITLE, GameTitle, false); | ||
this.state.add(StateKey.MAIN, Main, false); | ||
this.state.add(StateKey.GAME_OVER, GameOver, false); | ||
this.scene.add(SceneKey.BOOT, new Boot()); | ||
this.scene.add(SceneKey.PRELOAD, new Preload()); | ||
this.scene.add(SceneKey.MAIN, new Main()); | ||
|
||
this.state.start(StateKey.BOOT); | ||
this.scene.start(SceneKey.BOOT); | ||
} | ||
} | ||
|
||
new Game(); | ||
``` | ||
|
||
[See example](example) | ||
|
||
License | ||
--- | ||
## Running the example | ||
|
||
Run the following commands to run the example: | ||
|
||
```bash | ||
npm install | ||
npm start | ||
``` | ||
|
||
or: | ||
|
||
```bash | ||
yarn install | ||
yarn start | ||
``` | ||
|
||
## RobotlegsJS integration with Phaser CE (Community Edition) | ||
|
||
The `@robotlegsjs/phaser` package was updated to support [Phaser v3](https://www.npmjs.com/package/phaser) plugin. | ||
|
||
If you are looking for integration with [Phaser CE](https://github.com/photonstorm/phaser-ce) you can use the [RobotlegsJS-Phaser-CE](https://github.com/RobotlegsJS/RobotlegsJS-Phaser-CE) plugin. | ||
|
||
## License | ||
|
||
[MIT](LICENSE) |
Oops, something went wrong.