├── .gitignore
├── .vscode
├── launch.json
└── tasks.json
├── LICENSE
├── README.md
├── bin
├── assets
│ └── logo.png
├── index.html
└── js
│ ├── game.js
│ ├── game.js.map
│ ├── phaser.js
│ ├── phaser.map
│ └── phaser.min.js
├── package-lock.json
├── package.json
├── server
└── server.js
├── src
├── main.ts
└── states
│ ├── boot.ts
│ ├── game.ts
│ └── preloader.ts
├── tsconfig.json
├── tsd
├── box2d.d.ts
├── p2.d.ts
├── phaser.comments.d.ts
├── phaser.d.ts
├── phaser_box2d.d.ts
├── pixi.comments.d.ts
└── pixi.d.ts
├── update_phaser.bat
└── update_phaser.sh
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Node ##
2 | # Logs
3 | logs
4 | *.log
5 | npm-debug.log*
6 |
7 | # Runtime data
8 | pids
9 | *.pid
10 | *.seed
11 | *.pid.lock
12 |
13 | # Directory for instrumented libs generated by jscoverage/JSCover
14 | lib-cov
15 |
16 | # Coverage directory used by tools like istanbul
17 | coverage
18 |
19 | # nyc test coverage
20 | .nyc_output
21 |
22 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
23 | .grunt
24 |
25 | # node-waf configuration
26 | .lock-wscript
27 |
28 | # Compiled binary addons (http://nodejs.org/api/addons.html)
29 | build/Release
30 |
31 | # Dependency directories
32 | node_modules
33 | jspm_packages
34 |
35 | # Optional npm cache directory
36 | .npm
37 |
38 | # Optional eslint cache
39 | .eslintcache
40 |
41 | # Optional REPL history
42 | .node_repl_history
43 |
44 | # Output of 'npm pack'
45 | *.tgz
46 |
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "0.1.0",
3 | // List of configurations. Add new configurations or edit existing ones.
4 | "configurations": [
5 | {
6 | // Name of configuration; appears in the launch configuration drop down menu.
7 | "name": "Launch Phaser Game",
8 | // Type of configuration.
9 | "type": "node",
10 | "request": "launch",
11 | // Workspace relative or absolute path to the program.
12 | "program": "${workspaceRoot}/server/server.js",
13 | // Automatically stop program after launch.
14 | "stopOnEntry": false,
15 | // Command line arguments passed to the program.
16 | "args": [],
17 | // Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
18 | "cwd": "${workspaceRoot}",
19 | // Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
20 | "runtimeExecutable": null,
21 | // Optional arguments passed to the runtime executable.
22 | "runtimeArgs": ["--nolazy"],
23 | // Environment variables passed to the program.
24 | "env": {
25 | "NODE_ENV": "development"
26 | },
27 | // Use JavaScript source maps (if they exist).
28 | "sourceMaps": true,
29 | // If JavaScript source maps are enabled, the generated code is expected in this directory.
30 | "outDir": null
31 | },
32 | {
33 | "name": "Attach",
34 | "type": "node",
35 | "request": "attach",
36 | // TCP/IP address. Default is "localhost".
37 | "address": "localhost",
38 | // Port to attach to.
39 | "port": 5858,
40 | "sourceMaps": true
41 | }
42 | ]
43 | }
44 |
--------------------------------------------------------------------------------
/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "npmTask",
3 | //...
4 | "suppressTaskName": true,
5 | "command": "npm",
6 | "isShellCommand": true,
7 |
8 | "tasks": [
9 | {
10 | //Build Task
11 | "taskName": "build",
12 | //Run On Shift+Ctrl+B
13 | "isBuildCommand": true,
14 | //Don't run when Shift+Ctrl+T
15 | "isTestCommand": false,
16 | // Show the output window if error any
17 | "showOutput": "silent",
18 | //Npm Task Name
19 | "args": [
20 | "run", "compile:ts"
21 | ]
22 | },
23 | {
24 | //Test Task
25 | "taskName": "install",
26 | // Don't run on Shift+Ctrl+B
27 | "isBuildCommand": false,
28 | // Run on Shift+Ctrl+T
29 | "isTestCommand": true,
30 | "showOutput": "always",
31 | "args": [
32 | "run", "inst"
33 | ]
34 | }
35 | ]
36 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Fatir Ahmad
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Phaser Typescript VS Code Boilerplate
2 | Boilerplate project to get up and running with [Typescript] and [Phaser] in [VS Code].
3 |
4 | Derived from: http://divillysausages.com/2015/06/09/using-phaser-with-visual-studio-code/
5 |
6 | *NOTE: This boilerplate is setup to use Phaser Community Edition (Phaser-CE). This is Phaser 2, not Phaser 3 or beyond.*
7 |
8 | ## Getting Started
9 | 1. Install [Node].
10 |
11 | 2. Use NPM (comes with [Node]) to install [Typescript] from the command line.
12 |
13 | ```
14 | npm install -g typescript
15 | ```
16 |
17 | 3. Install [VS Code].
18 |
19 | 4. [Download] and extract this repository to desired destination. Rename the folder as desired.
20 |
21 | 5. Open this folder using [VS Code]. You can do this by right-clicking the folder and selecting 'Open with Code' from your desktop, or from *File > Open Folder* from within VS Code.
22 |
23 | 6. Press *Ctrl+Shift+P* to bring up the command palette and select 'Tasks: Run Test Task'. This will install required node modules.
24 |
25 | 7. Press *Ctrl+Shift+B* to compile the typescript files in [src/](src/) to [bin/js/](bin/js/).
26 |
27 | 8. Press *F5* to start the webserver.
28 |
29 | 9. Open [localhost:5858] in your favorite web browser. To modify this port update the port number in [.vscode/launch.json](.vscode/launch.json) and [server/server.js](server/server.js).
30 |
31 | *NOTE: Steps 1-3 only need to be done once per machine.*
32 |
33 | ## Project Structure Overview
34 |
35 | ### [/.vscode](/.vscode)
36 | Contains [VS Code] project setup to handle compiling typescript code and running the webserver. Only needed if you are using VS Code for these purposes. If you're just using the project structure, this folder can be deleted.
37 |
38 | ### [/bin](/bin)
39 | Directory of all output files that can be directly uploaded to host your game files.
40 |
41 | #### [/bin/assets](/bin/assets)
42 | Directory of all assets that the game/site/webpage will use. Feel free to make more directories for better organization.
43 |
44 | #### [/bin/js](/bin/js)
45 | Directory of compiled javascript as well as Phaser. Any additional javascript libraries can be placed here as well.
46 |
47 | ### [/node_modules](/node_modules)
48 | Contains [Node] specific setup and packages. Currently the only package used is [node-static] to allow VS Code to run a server.
49 |
50 | ### [/server](/server)
51 | Contains server setup for the packaged [node-static] web server.
52 |
53 | ### [/src](/src)
54 | Contains all your source [Typescript] files. These compile into /bin/js. Feel free to make more directories for better organization. This is where you will mainly be working.
55 |
56 | ### [/tsd](/tsd)
57 | Contains [Typescript] definition files. This is what the typescript compiler uses to add types to objects/functions.
58 |
59 | ## Updating Dependencies
60 | This setup uses the node.js package [node-static] to handle the hosting of files. While we will attempt to keep this up to date, if your project needs to update this package, run the following command in the command line if the project folder:
61 | ```
62 | npm update node-static
63 | ```
64 | ### Updating Phaser
65 | *Current Version Phaser-CE v2.19.0*
66 |
67 | To update Phaser, run [/update_phaser.sh](/update_phaser.sh) or [/pdate_phaser.bat](/update_phaser.bat) on Windows machines.
68 |
69 | ## Contributing
70 | If something is out of date, please make an Issue or a Pull Request and I'll update it.
71 |
72 | [Phaser]: https://github.com/photonstorm/phaser-ce/
73 | [Node]: https://nodejs.org
74 | [Typescript]: https://www.npmjs.com/package/typescript
75 | [VS Code]: https://code.visualstudio.com
76 | [Download]: https://code.visualstudio.com/
77 | [localhost:5858]: localhost:5858
78 | [node-static]: https://github.com/cloudhead/node-static
79 |
--------------------------------------------------------------------------------
/bin/assets/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/djfdat/phaser-typescript-vscode-boilerplate/67c4ee4fac115a0b3b486c04f1833e2a466341c3/bin/assets/logo.png
--------------------------------------------------------------------------------
/bin/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Phaser Game
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/bin/js/game.js:
--------------------------------------------------------------------------------
1 | var __extends = (this && this.__extends) || (function () {
2 | var extendStatics = Object.setPrototypeOf ||
3 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
4 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
5 | return function (d, b) {
6 | extendStatics(d, b);
7 | function __() { this.constructor = d; }
8 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
9 | };
10 | })();
11 | var MyGame;
12 | (function (MyGame) {
13 | var PhaserGame = (function (_super) {
14 | __extends(PhaserGame, _super);
15 | function PhaserGame() {
16 | var _this = _super.call(this, 800, 600, Phaser.AUTO, 'content', null) || this;
17 | _this.state.add('Boot', MyGame.BootState);
18 | _this.state.add('Preloader', MyGame.PreloaderState);
19 | _this.state.add('Game', MyGame.GameState);
20 | _this.state.start('Boot');
21 | return _this;
22 | }
23 | return PhaserGame;
24 | }(Phaser.Game));
25 | MyGame.PhaserGame = PhaserGame;
26 | })(MyGame || (MyGame = {}));
27 | // when the page has finished loading, create our game
28 | window.onload = function () {
29 | var game = new MyGame.PhaserGame();
30 | };
31 | var MyGame;
32 | (function (MyGame) {
33 | var BootState = (function (_super) {
34 | __extends(BootState, _super);
35 | function BootState() {
36 | return _super !== null && _super.apply(this, arguments) || this;
37 | }
38 | BootState.prototype.preload = function () { };
39 | BootState.prototype.create = function () {
40 | // Use this if you don't need multitouch
41 | this.input.maxPointers = 1;
42 | if (this.game.device.desktop) {
43 | // Desktop specific settings go here
44 | }
45 | this.game.state.start('Preloader', true, false);
46 | };
47 | return BootState;
48 | }(Phaser.State));
49 | MyGame.BootState = BootState;
50 | })(MyGame || (MyGame = {}));
51 | var MyGame;
52 | (function (MyGame) {
53 | var GameState = (function (_super) {
54 | __extends(GameState, _super);
55 | function GameState() {
56 | return _super !== null && _super.apply(this, arguments) || this;
57 | }
58 | GameState.prototype.preload = function () { };
59 | GameState.prototype.create = function () {
60 | var logo = this.game.add.sprite(this.game.world.centerX, this.game.world.centerY, 'logo');
61 | logo.anchor.setTo(0.5, 0.5);
62 | };
63 | return GameState;
64 | }(Phaser.State));
65 | MyGame.GameState = GameState;
66 | })(MyGame || (MyGame = {}));
67 | var MyGame;
68 | (function (MyGame) {
69 | var PreloaderState = (function (_super) {
70 | __extends(PreloaderState, _super);
71 | function PreloaderState() {
72 | return _super !== null && _super.apply(this, arguments) || this;
73 | }
74 | PreloaderState.prototype.preload = function () {
75 | this.game.load.image('logo', 'assets/logo.png');
76 | };
77 | PreloaderState.prototype.create = function () {
78 | this.game.state.start('Game');
79 | };
80 | return PreloaderState;
81 | }(Phaser.State));
82 | MyGame.PreloaderState = PreloaderState;
83 | })(MyGame || (MyGame = {}));
84 | //# sourceMappingURL=game.js.map
--------------------------------------------------------------------------------
/bin/js/game.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"game.js","sourceRoot":"","sources":["../../src/main.ts","../../src/states/boot.ts","../../src/states/game.ts","../../src/states/preloader.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,IAAO,MAAM,CAoCZ;AApCD,WAAO,MAAM;IAEZ;QAAgC,8BAAW;QAG1C;YAAA,YAEC,kBAAM,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,SAO7C;YALA,KAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,OAAA,SAAS,CAAC,CAAC;YAClC,KAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,EAAE,OAAA,cAAc,CAAC,CAAC;YAC5C,KAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,OAAA,SAAS,CAAC,CAAC;YAElC,KAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;;QAC1B,CAAC;QAoBF,iBAAC;IAAD,CAAC,AAhCD,CAAgC,MAAM,CAAC,IAAI,GAgC1C;IAhCY,iBAAU,aAgCtB,CAAA;AAEF,CAAC,EApCM,MAAM,KAAN,MAAM,QAoCZ;AAED,sDAAsD;AACtD,MAAM,CAAC,MAAM,GAAG;IACf,IAAI,IAAI,GAAG,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;AACpC,CAAC,CAAA;ACzCD,IAAO,MAAM,CAmBZ;AAnBD,WAAO,MAAM;IAEZ;QAA+B,6BAAY;QAA3C;;QAeA,CAAC;QAbA,2BAAO,GAAP,cAAW,CAAC;QAEZ,0BAAM,GAAN;YACC,wCAAwC;YACxC,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,CAAC,CAAC;YAE3B,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;gBAC9B,oCAAoC;YACrC,CAAC;YAED,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,WAAW,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QACjD,CAAC;QAEF,gBAAC;IAAD,CAAC,AAfD,CAA+B,MAAM,CAAC,KAAK,GAe1C;IAfY,gBAAS,YAerB,CAAA;AAEF,CAAC,EAnBM,MAAM,KAAN,MAAM,QAmBZ;ACnBD,IAAO,MAAM,CAaZ;AAbD,WAAO,MAAM;IAEZ;QAA+B,6BAAY;QAA3C;;QASA,CAAC;QAPA,2BAAO,GAAP,cAAW,CAAC;QAEZ,0BAAM,GAAN;YACC,IAAI,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YAC1F,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC7B,CAAC;QAEF,gBAAC;IAAD,CAAC,AATD,CAA+B,MAAM,CAAC,KAAK,GAS1C;IATY,gBAAS,YASrB,CAAA;AAEF,CAAC,EAbM,MAAM,KAAN,MAAM,QAaZ;ACbD,IAAO,MAAM,CAcZ;AAdD,WAAO,MAAM;IAEZ;QAAoC,kCAAY;QAAhD;;QAUA,CAAC;QARA,gCAAO,GAAP;YACC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;QACjD,CAAC;QAED,+BAAM,GAAN;YACC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC/B,CAAC;QAEF,qBAAC;IAAD,CAAC,AAVD,CAAoC,MAAM,CAAC,KAAK,GAU/C;IAVY,qBAAc,iBAU1B,CAAA;AAEF,CAAC,EAdM,MAAM,KAAN,MAAM,QAcZ"}
--------------------------------------------------------------------------------
/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "phaser-typescript-vscode-boilerplate",
3 | "version": "1.0.0",
4 | "lockfileVersion": 1,
5 | "requires": true,
6 | "dependencies": {
7 | "colors": {
8 | "version": "1.4.0",
9 | "resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz",
10 | "integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA=="
11 | },
12 | "mime": {
13 | "version": "1.6.0",
14 | "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz",
15 | "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg=="
16 | },
17 | "minimist": {
18 | "version": "0.0.10",
19 | "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz",
20 | "integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8="
21 | },
22 | "node-static": {
23 | "version": "0.7.11",
24 | "resolved": "https://registry.npmjs.org/node-static/-/node-static-0.7.11.tgz",
25 | "integrity": "sha512-zfWC/gICcqb74D9ndyvxZWaI1jzcoHmf4UTHWQchBNuNMxdBLJMDiUgZ1tjGLEIe/BMhj2DxKD8HOuc2062pDQ==",
26 | "requires": {
27 | "colors": ">=0.6.0",
28 | "mime": "^1.2.9",
29 | "optimist": ">=0.3.4"
30 | }
31 | },
32 | "optimist": {
33 | "version": "0.6.1",
34 | "resolved": "https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz",
35 | "integrity": "sha1-2j6nRob6IaGaERwybpDrFaAZZoY=",
36 | "requires": {
37 | "minimist": "~0.0.1",
38 | "wordwrap": "~0.0.2"
39 | }
40 | },
41 | "wordwrap": {
42 | "version": "0.0.3",
43 | "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz",
44 | "integrity": "sha1-o9XabNXAvAAI03I0u68b7WMFkQc="
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "phaser-typescript-vscode-boilerplate",
3 | "version": "1.0.0",
4 | "description": "Project Boilerplate for using Phaser in VS Code.",
5 | "main": "",
6 | "repository": "",
7 | "scripts": {
8 | "compile:ts": "tsc --outFile ./bin/js/game.js",
9 | "inst": "npm install"
10 | },
11 | "author": "Fatir Ahmad",
12 | "license": "MIT",
13 | "dependencies": {
14 | "node-static": ">0.7.11"
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/server/server.js:
--------------------------------------------------------------------------------
1 | // import our modules
2 | var nodeStatic = require( 'node-static' ); // used for serving static files
3 | var http = require( 'http' ); // default node http server
4 | var port = 5858; // NOTE: this is the same port as specified in launch.json
5 |
6 | // create our file server config
7 | var file = new nodeStatic.Server( 'bin', { // anything in the bin/ folder is served
8 | cache:0, // no cache (only for testing)
9 | gzip:true // gzip our assets
10 | });
11 |
12 | // create our basic server
13 | http.createServer( function( request, response ) {
14 | request.addListener( 'end', function() {
15 | file.serve( request, response ); // any url asked for, just try and serve the file from bin/
16 | }).resume();
17 | }).listen( port );
--------------------------------------------------------------------------------
/src/main.ts:
--------------------------------------------------------------------------------
1 | module MyGame {
2 |
3 | export class PhaserGame extends Phaser.Game
4 | {
5 |
6 | constructor()
7 | {
8 | super(800, 600, Phaser.AUTO, 'content', null);
9 |
10 | this.state.add('Boot', BootState);
11 | this.state.add('Preloader', PreloaderState);
12 | this.state.add('Game', GameState);
13 |
14 | this.state.start('Boot');
15 | }
16 |
17 | // preload()
18 | // {
19 | // // add our logo image to the assets class under the
20 | // // key 'logo'. We're also setting the background colour
21 | // // so it's the same as the background colour in the image
22 | // this.game.load.image( 'logo', "assets/logo.png" );
23 | // this.game.stage.backgroundColor = 0xB20059;
24 | // }
25 |
26 | // create()
27 | // {
28 | // // add the 'logo' sprite to the game, position it in the
29 | // // center of the screen, and set the anchor to the center of
30 | // // the image so it's centered properly. There's a lot of
31 | // // centering in that last sentence
32 | // var logo = this.game.add.sprite( this.game.world.centerX, this.game.world.centerY, 'logo' );
33 | // logo.anchor.setTo( 0.5, 0.5 );
34 | // }
35 | }
36 |
37 | }
38 |
39 | // when the page has finished loading, create our game
40 | window.onload = () => {
41 | var game = new MyGame.PhaserGame();
42 | }
--------------------------------------------------------------------------------
/src/states/boot.ts:
--------------------------------------------------------------------------------
1 | module MyGame {
2 |
3 | export class BootState extends Phaser.State {
4 |
5 | preload() {}
6 |
7 | create() {
8 | // Use this if you don't need multitouch
9 | this.input.maxPointers = 1;
10 |
11 | if (this.game.device.desktop) {
12 | // Desktop specific settings go here
13 | }
14 |
15 | this.game.state.start('Preloader', true, false);
16 | }
17 |
18 | }
19 |
20 | }
--------------------------------------------------------------------------------
/src/states/game.ts:
--------------------------------------------------------------------------------
1 | module MyGame {
2 |
3 | export class GameState extends Phaser.State {
4 |
5 | preload() {}
6 |
7 | create() {
8 | let logo = this.game.add.sprite(this.game.world.centerX, this.game.world.centerY, 'logo');
9 | logo.anchor.setTo(0.5, 0.5);
10 | }
11 |
12 | }
13 |
14 | }
--------------------------------------------------------------------------------
/src/states/preloader.ts:
--------------------------------------------------------------------------------
1 | module MyGame {
2 |
3 | export class PreloaderState extends Phaser.State {
4 |
5 | preload() {
6 | this.game.load.image('logo', 'assets/logo.png');
7 | }
8 |
9 | create() {
10 | this.game.state.start('Game');
11 | }
12 |
13 | }
14 |
15 | }
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "ES5",
4 | "sourceMap": true
5 | },
6 | "exclude": [
7 | "node_modules",
8 | "bin",
9 | "tsd/phaser.d.ts",
10 | "tsd/pixi.d.ts"
11 | ]
12 | }
--------------------------------------------------------------------------------
/tsd/p2.d.ts:
--------------------------------------------------------------------------------
1 | // Type definitions for p2.js v0.6.0
2 | // Project: https://github.com/schteppe/p2.js/
3 |
4 | declare module p2 {
5 |
6 | export class AABB {
7 |
8 | constructor(options?: {
9 | upperBound?: number[];
10 | lowerBound?: number[];
11 | });
12 |
13 | setFromPoints(points: number[][], position: number[], angle: number, skinSize: number): void;
14 | copy(aabb: AABB): void;
15 | extend(aabb: AABB): void;
16 | overlaps(aabb: AABB): boolean;
17 |
18 | }
19 |
20 | export class Broadphase {
21 |
22 | static AABB: number;
23 | static BOUNDING_CIRCLE: number;
24 |
25 | static NAIVE: number;
26 | static SAP: number;
27 |
28 | static boundingRadiusCheck(bodyA: Body, bodyB: Body): boolean;
29 | static aabbCheck(bodyA: Body, bodyB: Body): boolean;
30 | static canCollide(bodyA: Body, bodyB: Body): boolean;
31 |
32 | constructor(type: number);
33 |
34 | type: number;
35 | result: Body[];
36 | world: World;
37 | boundingVolumeType: number;
38 |
39 | setWorld(world: World): void;
40 | getCollisionPairs(world: World): Body[];
41 | boundingVolumeCheck(bodyA: Body, bodyB: Body): boolean;
42 |
43 | }
44 |
45 | export class GridBroadphase extends Broadphase {
46 |
47 | constructor(options?: {
48 | xmin?: number;
49 | xmax?: number;
50 | ymin?: number;
51 | ymax?: number;
52 | nx?: number;
53 | ny?: number;
54 | });
55 |
56 | xmin: number;
57 | xmax: number;
58 | ymin: number;
59 | ymax: number;
60 | nx: number;
61 | ny: number;
62 | binsizeX: number;
63 | binsizeY: number;
64 |
65 | }
66 |
67 | export class NativeBroadphase extends Broadphase {
68 |
69 | }
70 |
71 | export class Narrowphase {
72 |
73 | contactEquations: ContactEquation[];
74 | frictionEquations: FrictionEquation[];
75 | enableFriction: boolean;
76 | slipForce: number;
77 | frictionCoefficient: number;
78 | surfaceVelocity: number;
79 | reuseObjects: boolean;
80 | resuableContactEquations: any[];
81 | reusableFrictionEquations: any[];
82 | restitution: number;
83 | stiffness: number;
84 | relaxation: number;
85 | frictionStiffness: number;
86 | frictionRelaxation: number;
87 | enableFrictionReduction: boolean;
88 | contactSkinSize: number;
89 |
90 | collidedLastStep(bodyA: Body, bodyB: Body): boolean;
91 | reset(): void;
92 | createContactEquation(bodyA: Body, bodyB: Body, shapeA: Shape, shapeB: Shape): ContactEquation;
93 | createFrictionFromContact(c: ContactEquation): FrictionEquation;
94 |
95 | }
96 |
97 | export class SAPBroadphase extends Broadphase {
98 |
99 | axisList: Body[];
100 | axisIndex: number;
101 |
102 | }
103 |
104 | export class Constraint {
105 |
106 | static DISTANCE: number;
107 | static GEAR: number;
108 | static LOCK: number;
109 | static PRISMATIC: number;
110 | static REVOLUTE: number;
111 |
112 | constructor(bodyA: Body, bodyB: Body, type: number, options?: {
113 | collideConnected?: boolean;
114 | wakeUpBodies?: boolean;
115 | });
116 |
117 | type: number;
118 | equeations: Equation[];
119 | bodyA: Body;
120 | bodyB: Body;
121 | collideConnected: boolean;
122 |
123 | update(): void;
124 | setStiffness(stiffness: number): void;
125 | setRelaxation(relaxation: number): void;
126 |
127 | }
128 |
129 | export class DistanceConstraint extends Constraint {
130 |
131 | constructor(bodyA: Body, bodyB: Body, type: number, options?: {
132 | collideConnected?: boolean;
133 | wakeUpBodies?: boolean;
134 | distance?: number;
135 | localAnchorA?: number[];
136 | localAnchorB?: number[];
137 | maxForce?: number;
138 | });
139 |
140 | localAnchorA: number[];
141 | localAnchorB: number[];
142 | distance: number;
143 | maxForce: number;
144 | upperLimitEnabled: boolean;
145 | upperLimit: number;
146 | lowerLimitEnabled: boolean;
147 | lowerLimit: number;
148 | position: number;
149 |
150 | setMaxForce(f: number): void;
151 | getMaxForce(): number;
152 |
153 | }
154 |
155 | export class GearConstraint extends Constraint {
156 |
157 | constructor(bodyA: Body, bodyB: Body, type: number, options?: {
158 | collideConnected?: boolean;
159 | wakeUpBodies?: boolean;
160 | angle?: number;
161 | ratio?: number;
162 | maxTorque?: number;
163 | });
164 |
165 | ratio: number;
166 | angle: number;
167 |
168 | setMaxTorque(torque: number): void;
169 | getMaxTorque(): number;
170 |
171 | }
172 |
173 | export class LockConstraint extends Constraint {
174 |
175 | constructor(bodyA: Body, bodyB: Body, type: number, options?: {
176 | collideConnected?: boolean;
177 | wakeUpBodies?: boolean;
178 | localOffsetB?: number[];
179 | localAngleB?: number;
180 | maxForce?: number;
181 | });
182 |
183 | setMaxForce(force: number): void;
184 | getMaxForce(): number;
185 |
186 | }
187 |
188 | export class PrismaticConstraint extends Constraint {
189 |
190 | constructor(bodyA: Body, bodyB: Body, type: number, options?: {
191 | collideConnected?: boolean;
192 | wakeUpBodies?: boolean;
193 | maxForce?: number;
194 | localAnchorA?: number[];
195 | localAnchorB?: number[];
196 | localAxisA?: number[];
197 | disableRotationalLock?: boolean;
198 | upperLimit?: number;
199 | lowerLimit?: number;
200 | });
201 |
202 | localAnchorA: number[];
203 | localAnchorB: number[];
204 | localAxisA: number[];
205 | position: number;
206 | velocity: number;
207 | lowerLimitEnabled: boolean;
208 | upperLimitEnabled: boolean;
209 | lowerLimit: number;
210 | upperLimit: number;
211 | upperLimitEquation: ContactEquation;
212 | lowerLimitEquation: ContactEquation;
213 | motorEquation: Equation;
214 | motorEnabled: boolean;
215 | motorSpeed: number;
216 |
217 | enableMotor(): void;
218 | disableMotor(): void;
219 | setLimits(lower: number, upper: number): void;
220 |
221 | }
222 |
223 | export class RevoluteConstraint extends Constraint {
224 |
225 | constructor(bodyA: Body, bodyB: Body, type: number, options?: {
226 | collideConnected?: boolean;
227 | wakeUpBodies?: boolean;
228 | worldPivot?: number[];
229 | localPivotA?: number[];
230 | localPivotB?: number[];
231 | maxForce?: number;
232 | });
233 |
234 | pivotA: number[];
235 | pivotB: number[];
236 | motorEquation: RotationalVelocityEquation;
237 | motorEnabled: boolean;
238 | angle: number;
239 | lowerLimitEnabled: boolean;
240 | upperLimitEnabled: boolean;
241 | lowerLimit: number;
242 | upperLimit: number;
243 | upperLimitEquation: ContactEquation;
244 | lowerLimitEquation: ContactEquation;
245 |
246 | enableMotor(): void;
247 | disableMotor(): void;
248 | motorIsEnabled(): boolean;
249 | setLimits(lower: number, upper: number): void;
250 | setMotorSpeed(speed: number): void;
251 | getMotorSpeed(): number;
252 |
253 | }
254 |
255 | export class AngleLockEquation extends Equation {
256 |
257 | constructor(bodyA: Body, bodyB: Body, options?: {
258 | angle?: number;
259 | ratio?: number;
260 | });
261 |
262 | computeGq(): number;
263 | setRatio(ratio: number): number;
264 | setMaxTorque(torque: number): number;
265 |
266 | }
267 |
268 | export class ContactEquation extends Equation {
269 |
270 | constructor(bodyA: Body, bodyB: Body);
271 |
272 | contactPointA: number[];
273 | penetrationVec: number[];
274 | contactPointB: number[];
275 | normalA: number[];
276 | restitution: number;
277 | firstImpact: boolean;
278 | shapeA: Shape;
279 | shapeB: Shape;
280 |
281 | computeB(a: number, b: number, h: number): number;
282 |
283 | }
284 |
285 | export class Equation {
286 |
287 | static DEFAULT_STIFFNESS: number;
288 | static DEFAULT_RELAXATION: number;
289 |
290 | constructor(bodyA: Body, bodyB: Body, minForce?: number, maxForce?: number);
291 |
292 | minForce: number;
293 | maxForce: number;
294 | bodyA: Body;
295 | bodyB: Body;
296 | stiffness: number;
297 | relaxation: number;
298 | G: number[];
299 | offset: number;
300 | a: number;
301 | b: number;
302 | epsilon: number;
303 | timeStep: number;
304 | needsUpdate: boolean;
305 | multiplier: number;
306 | relativeVelocity: number;
307 | enabled: boolean;
308 |
309 | gmult(G: number[], vi: number[], wi: number[], vj: number[], wj: number[]): number;
310 | computeB(a: number, b: number, h: number): number;
311 | computeGq(): number;
312 | computeGW(): number;
313 | computeGWlambda(): number;
314 | computeGiMf(): number;
315 | computeGiMGt(): number;
316 | addToWlambda(deltalambda: number): number;
317 | computeInvC(eps: number): number;
318 |
319 | }
320 |
321 | export class FrictionEquation extends Equation {
322 |
323 | constructor(bodyA: Body, bodyB: Body, slipForce: number);
324 |
325 | contactPointA: number[];
326 | contactPointB: number[];
327 | t: number[];
328 | shapeA: Shape;
329 | shapeB: Shape;
330 | frictionCoefficient: number;
331 |
332 | setSlipForce(slipForce: number): number;
333 | getSlipForce(): number;
334 | computeB(a: number, b: number, h: number): number;
335 |
336 | }
337 |
338 | export class RotationalLockEquation extends Equation {
339 |
340 | constructor(bodyA: Body, bodyB: Body, options?: {
341 | angle?: number;
342 | });
343 |
344 | angle: number;
345 |
346 | computeGq(): number;
347 |
348 | }
349 |
350 | export class RotationalVelocityEquation extends Equation {
351 |
352 | constructor(bodyA: Body, bodyB: Body);
353 |
354 | computeB(a: number, b: number, h: number): number;
355 |
356 | }
357 |
358 | export class EventEmitter {
359 |
360 | on(type: string, listener: Function, context: any): EventEmitter;
361 | has(type: string, listener: Function): boolean;
362 | off(type: string, listener: Function): EventEmitter;
363 | emit(event: any): EventEmitter;
364 |
365 | }
366 |
367 | export class ContactMaterialOptions {
368 |
369 | friction: number;
370 | restitution: number;
371 | stiffness: number;
372 | relaxation: number;
373 | frictionStiffness: number;
374 | frictionRelaxation: number;
375 | surfaceVelocity: number;
376 |
377 | }
378 |
379 | export class ContactMaterial {
380 |
381 | static idCounter: number;
382 |
383 | constructor(materialA: Material, materialB: Material, options?: ContactMaterialOptions);
384 |
385 | id: number;
386 | materialA: Material;
387 | materialB: Material;
388 | friction: number;
389 | restitution: number;
390 | stiffness: number;
391 | relaxation: number;
392 | frictionStiffness: number;
393 | frictionRelaxation: number;
394 | surfaceVelocity: number;
395 | contactSkinSize: number;
396 |
397 | }
398 |
399 | export class Material {
400 |
401 | static idCounter: number;
402 |
403 | constructor(id: number);
404 |
405 | id: number;
406 |
407 | }
408 |
409 | export class vec2 {
410 |
411 | static crossLength(a: number[], b: number[]): number;
412 | static crossVZ(out: number[], vec: number[], zcomp: number): number;
413 | static crossZV(out: number[], zcomp: number, vec: number[]): number;
414 | static rotate(out: number[], a: number[], angle: number): void;
415 | static rotate90cw(out: number[], a: number[]): number;
416 | static centroid(out: number[], a: number[], b: number[], c: number[]): number[];
417 | static create(): number[];
418 | static clone(a: number[]): number[];
419 | static fromValues(x: number, y: number): number[];
420 | static copy(out: number[], a: number[]): number[];
421 | static set(out: number[], x: number, y: number): number[];
422 | static toLocalFrame(out: number[], worldPoint: number[], framePosition: number[], frameAngle: number): void;
423 | static toGlobalFrame(out: number[], localPoint: number[], framePosition: number[], frameAngle: number): void;
424 | static add(out: number[], a: number[], b: number[]): number[];
425 | static subtract(out: number[], a: number[], b: number[]): number[];
426 | static sub(out: number[], a: number[], b: number[]): number[];
427 | static multiply(out: number[], a: number[], b: number[]): number[];
428 | static mul(out: number[], a: number[], b: number[]): number[];
429 | static divide(out: number[], a: number[], b: number[]): number[];
430 | static div(out: number[], a: number[], b: number[]): number[];
431 | static scale(out: number[], a: number[], b: number): number[];
432 | static distance(a: number[], b: number[]): number;
433 | static dist(a: number[], b: number[]): number;
434 | static squaredDistance(a: number[], b: number[]): number;
435 | static sqrDist(a: number[], b: number[]): number;
436 | static length(a: number[]): number;
437 | static len(a: number[]): number;
438 | static squaredLength(a: number[]): number;
439 | static sqrLen(a: number[]): number;
440 | static negate(out: number[], a: number[]): number[];
441 | static normalize(out: number[], a: number[]): number[];
442 | static dot(a: number[], b: number[]): number;
443 | static str(a: number[]): string;
444 |
445 | }
446 |
447 | export interface BodyOptions {
448 |
449 | mass?: number;
450 | position?: number[];
451 | velocity?: number[];
452 | angle?: number;
453 | angularVelocity?: number;
454 | force?: number[];
455 | angularForce?: number;
456 | fixedRotation?: boolean;
457 |
458 | }
459 |
460 | export class Body extends EventEmitter {
461 |
462 | sleepyEvent: {
463 | type: string;
464 | };
465 |
466 | sleepEvent: {
467 | type: string;
468 | };
469 |
470 | wakeUpEvent: {
471 | type: string;
472 | };
473 |
474 | static DYNAMIC: number;
475 | static STATIC: number;
476 | static KINEMATIC: number;
477 | static AWAKE: number;
478 | static SLEEPY: number;
479 | static SLEEPING: number;
480 |
481 | constructor(options?: BodyOptions);
482 |
483 | id: number;
484 | world: World;
485 | shapes: Shape[];
486 | shapeOffsets: number[][];
487 | shapeAngles: number[];
488 | mass: number;
489 | invMass: number;
490 | inertia: number;
491 | invInertia: number;
492 | invMassSolve: number;
493 | invInertiaSolve: number;
494 | fixedRotation: number;
495 | position: number[];
496 | interpolatedPosition: number[];
497 | interpolatedAngle: number;
498 | previousPosition: number[];
499 | previousAngle: number;
500 | velocity: number[];
501 | vlambda: number[];
502 | wlambda: number[];
503 | angle: number;
504 | angularVelocity: number;
505 | force: number[];
506 | angularForce: number;
507 | damping: number;
508 | angularDamping: number;
509 | type: number;
510 | boundingRadius: number;
511 | aabb: AABB;
512 | aabbNeedsUpdate: boolean;
513 | allowSleep: boolean;
514 | wantsToSleep: boolean;
515 | sleepState: number;
516 | sleepSpeedLimit: number;
517 | sleepTimeLimit: number;
518 | gravityScale: number;
519 |
520 | updateSolveMassProperties(): void;
521 | setDensity(density: number): void;
522 | getArea(): number;
523 | getAABB(): AABB;
524 | updateAABB(): void;
525 | updateBoundingRadius(): void;
526 | addShape(shape: Shape, offset?: number[], angle?: number): void;
527 | removeShape(shape: Shape): boolean;
528 | updateMassProperties(): void;
529 | applyForce(force: number[], worldPoint: number[]): void;
530 | toLocalFrame(out: number[], worldPoint: number[]): void;
531 | toWorldFrame(out: number[], localPoint: number[]): void;
532 | fromPolygon(path: number[][], options?: {
533 | optimalDecomp?: boolean;
534 | skipSimpleCheck?: boolean;
535 | removeCollinearPoints?: any; //boolean | number
536 | }): boolean;
537 | adjustCenterOfMass(): void;
538 | setZeroForce(): void;
539 | resetConstraintVelocity(): void;
540 | applyDamping(dy: number): void;
541 | wakeUp(): void;
542 | sleep(): void;
543 | sleepTick(time: number, dontSleep: boolean, dt: number): void;
544 | getVelocityFromPosition(story: number[], dt: number): number[];
545 | getAngularVelocityFromPosition(timeStep: number): number;
546 | overlaps(body: Body): boolean;
547 |
548 | }
549 |
550 | export class Spring {
551 |
552 | constructor(bodyA: Body, bodyB: Body, options?: {
553 |
554 | stiffness?: number;
555 | damping?: number;
556 | localAnchorA?: number[];
557 | localAnchorB?: number[];
558 | worldAnchorA?: number[];
559 | worldAnchorB?: number[];
560 |
561 | });
562 |
563 | stiffness: number;
564 | damping: number;
565 | bodyA: Body;
566 | bodyB: Body;
567 |
568 | applyForce(): void;
569 |
570 | }
571 |
572 | export class LinearSpring extends Spring {
573 |
574 | localAnchorA: number[];
575 | localAnchorB: number[];
576 | restLength: number;
577 |
578 | setWorldAnchorA(worldAnchorA: number[]): void;
579 | setWorldAnchorB(worldAnchorB: number[]): void;
580 | getWorldAnchorA(result: number[]): number[];
581 | getWorldAnchorB(result: number[]): number[];
582 | applyForce(): void;
583 |
584 | }
585 |
586 | export class RotationalSpring extends Spring {
587 |
588 | constructor(bodyA: Body, bodyB: Body, options?: {
589 | restAngle?: number;
590 | stiffness?: number;
591 | damping?: number;
592 | });
593 |
594 | restAngle: number;
595 |
596 | }
597 |
598 | export class Capsule extends Shape {
599 |
600 | constructor(length?: number, radius?: number);
601 |
602 | length: number;
603 | radius: number;
604 |
605 | }
606 |
607 | export class Circle extends Shape {
608 |
609 | constructor(radius: number);
610 |
611 | radius: number;
612 |
613 | }
614 |
615 | export class Convex extends Shape {
616 |
617 | static triangleArea(a: number[], b: number[], c: number[]): number;
618 |
619 | constructor(options?: any);
620 |
621 | vertices: number[][];
622 | axes: number[];
623 | centerOfMass: number[];
624 | triangles: number[];
625 | boundingRadius: number;
626 |
627 | projectOntoLocalAxis(localAxis: number[], result: number[]): void;
628 | projectOntoWorldAxis(localAxis: number[], shapeOffset: number[], shapeAngle: number, result: number[]): void;
629 |
630 | updateCenterOfMass(): void;
631 |
632 | }
633 |
634 | export class Heightfield extends Shape {
635 |
636 | constructor(data: number[], options?: {
637 | minValue?: number;
638 | maxValue?: number;
639 | elementWidth: number;
640 | });
641 |
642 | data: number[];
643 | maxValue: number;
644 | minValue: number;
645 | elementWidth: number;
646 |
647 | }
648 |
649 | export interface SharedShapeOptions {
650 |
651 | position?: number[];
652 | angle?: number;
653 | collisionGroup?: number;
654 | collisionResponse?: boolean;
655 | collisionMask?: number;
656 | sensor?: boolean;
657 |
658 | }
659 |
660 | export interface ShapeOptions extends SharedShapeOptions {
661 |
662 | type?: number;
663 |
664 | }
665 |
666 | export class Shape {
667 |
668 | static idCounter: number;
669 | static CIRCLE: number;
670 | static PARTICLE: number;
671 | static PLANE: number;
672 | static CONVEX: number;
673 | static LINE: number;
674 | static RECTANGLE: number;
675 | static CAPSULE: number;
676 | static HEIGHTFIELD: number;
677 |
678 | constructor(options?: ShapeOptions);
679 |
680 | type: number;
681 | id: number;
682 | boundingRadius: number;
683 | collisionGroup: number;
684 | collisionMask: number;
685 | material: Material;
686 | area: number;
687 | sensor: boolean;
688 |
689 | computeMomentOfInertia(mass: number): number;
690 | updateBoundingRadius(): number;
691 | updateArea(): void;
692 | computeAABB(out: AABB, position: number[], angle: number): void;
693 |
694 | }
695 |
696 | export class Line extends Shape {
697 |
698 | constructor(length?: number);
699 |
700 | length: number;
701 |
702 | }
703 |
704 | export class Particle extends Shape {
705 |
706 | }
707 |
708 | export class Plane extends Shape {
709 |
710 | }
711 |
712 | export interface BoxOptions {
713 |
714 | width?: number;
715 | height?: number;
716 |
717 | }
718 |
719 | export class Box extends Shape {
720 | constructor(options?: BoxOptions);
721 |
722 | width: number;
723 | height: number;
724 | }
725 |
726 | export class Rectangle extends Shape {
727 |
728 | static sameDimensions(a: Rectangle, b: Rectangle): boolean;
729 |
730 | constructor(width?: number, height?: number);
731 |
732 | width: number;
733 | height: number;
734 |
735 | }
736 |
737 | export class Solver extends EventEmitter {
738 |
739 | static GS: number;
740 | static ISLAND: number;
741 |
742 | constructor(options?: {}, type?: number);
743 |
744 | type: number;
745 | equations: Equation[];
746 | equationSortFunction: Equation; //Equation | boolean
747 |
748 | solve(dy: number, world: World): void;
749 | solveIsland(dy: number, island: Island): void;
750 | sortEquations(): void;
751 | addEquation(eq: Equation): void;
752 | addEquations(eqs: Equation[]): void;
753 | removeEquation(eq: Equation): void;
754 | removeAllEquations(): void;
755 |
756 | }
757 |
758 | export class GSSolver extends Solver {
759 |
760 | constructor(options?: {
761 | iterations?: number;
762 | tolerance?: number;
763 | });
764 |
765 | iterations: number;
766 | tolerance: number;
767 | useZeroRHS: boolean;
768 | frictionIterations: number;
769 | usedIterations: number;
770 |
771 | solve(h: number, world: World): void;
772 |
773 | }
774 |
775 | export class OverlapKeeper {
776 |
777 | constructor(bodyA: Body, shapeA: Shape, bodyB: Body, shapeB: Shape);
778 |
779 | shapeA: Shape;
780 | shapeB: Shape;
781 | bodyA: Body;
782 | bodyB: Body;
783 |
784 | tick(): void;
785 | setOverlapping(bodyA: Body, shapeA: Shape, bodyB: Body, shapeB: Body): void;
786 | bodiesAreOverlapping(bodyA: Body, bodyB: Body): boolean;
787 | set(bodyA: Body, shapeA: Shape, bodyB: Body, shapeB: Shape): void;
788 |
789 | }
790 |
791 | export class TupleDictionary {
792 |
793 | data: number[];
794 | keys: number[];
795 |
796 | getKey(id1: number, id2: number): string;
797 | getByKey(key: number): number;
798 | get(i: number, j: number): number;
799 | set(i: number, j: number, value: number): number;
800 | reset(): void;
801 | copy(dict: TupleDictionary): void;
802 |
803 | }
804 |
805 | export class Utils {
806 |
807 | static appendArray(a: Array, b: Array): Array;
808 | static chanceRoll(chance: number): boolean;
809 | static defaults(options: any, defaults: any): any;
810 | static extend(a: any, b: any): void;
811 | static randomChoice(choice1: any, choice2: any): any;
812 | static rotateArray(matrix: any[], direction: any): any[];
813 | static splice(array: Array, index: number, howMany: number): void;
814 | static shuffle(array: T[]): T[];
815 | static transposeArray(array: T[]): T[];
816 |
817 | }
818 |
819 | export class Island {
820 |
821 | equations: Equation[];
822 | bodies: Body[];
823 |
824 | reset(): void;
825 | getBodies(result: any): Body[];
826 | wantsToSleep(): boolean;
827 | sleep(): boolean;
828 |
829 | }
830 |
831 | export class IslandManager extends Solver {
832 |
833 | static getUnvisitedNode(nodes: Node[]): IslandNode; // IslandNode | boolean
834 |
835 | equations: Equation[];
836 | islands: Island[];
837 | nodes: IslandNode[];
838 |
839 | visit(node: IslandNode, bds: Body[], eqs: Equation[]): void;
840 | bfs(root: IslandNode, bds: Body[], eqs: Equation[]): void;
841 | split(world: World): Island[];
842 |
843 | }
844 |
845 | export class IslandNode {
846 |
847 | constructor(body: Body);
848 |
849 | body: Body;
850 | neighbors: IslandNode[];
851 | equations: Equation[];
852 | visited: boolean;
853 |
854 | reset(): void;
855 |
856 | }
857 |
858 | export class World extends EventEmitter {
859 |
860 | postStepEvent: {
861 | type: string;
862 | };
863 |
864 | addBodyEvent: {
865 | type: string;
866 | };
867 |
868 | removeBodyEvent: {
869 | type: string;
870 | };
871 |
872 | addSpringEvent: {
873 | type: string;
874 | };
875 |
876 | impactEvent: {
877 | type: string;
878 | bodyA: Body;
879 | bodyB: Body;
880 | shapeA: Shape;
881 | shapeB: Shape;
882 | contactEquation: ContactEquation;
883 | };
884 |
885 | postBroadphaseEvent: {
886 | type: string;
887 | pairs: Body[];
888 | };
889 |
890 | beginContactEvent: {
891 | type: string;
892 | shapeA: Shape;
893 | shapeB: Shape;
894 | bodyA: Body;
895 | bodyB: Body;
896 | contactEquations: ContactEquation[];
897 | };
898 |
899 | endContactEvent: {
900 | type: string;
901 | shapeA: Shape;
902 | shapeB: Shape;
903 | bodyA: Body;
904 | bodyB: Body;
905 | };
906 |
907 | preSolveEvent: {
908 | type: string;
909 | contactEquations: ContactEquation[];
910 | frictionEquations: FrictionEquation[];
911 | };
912 |
913 | static NO_SLEEPING: number;
914 | static BODY_SLEEPING: number;
915 | static ISLAND_SLEEPING: number;
916 |
917 | static integrateBody(body: Body, dy: number): void;
918 |
919 | constructor(options?: {
920 | solver?: Solver;
921 | gravity?: number[];
922 | broadphase?: Broadphase;
923 | islandSplit?: boolean;
924 | doProfiling?: boolean;
925 | });
926 |
927 | springs: Spring[];
928 | bodies: Body[];
929 | solver: Solver;
930 | narrowphase: Narrowphase;
931 | islandManager: IslandManager;
932 | gravity: number[];
933 | frictionGravity: number;
934 | useWorldGravityAsFrictionGravity: boolean;
935 | useFrictionGravityOnZeroGravity: boolean;
936 | doProfiling: boolean;
937 | lastStepTime: number;
938 | broadphase: Broadphase;
939 | constraints: Constraint[];
940 | defaultMaterial: Material;
941 | defaultContactMaterial: ContactMaterial;
942 | lastTimeStep: number;
943 | applySpringForces: boolean;
944 | applyDamping: boolean;
945 | applyGravity: boolean;
946 | solveConstraints: boolean;
947 | contactMaterials: ContactMaterial[];
948 | time: number;
949 | stepping: boolean;
950 | islandSplit: boolean;
951 | emitImpactEvent: boolean;
952 | sleepMode: number;
953 |
954 | addConstraint(c: Constraint): void;
955 | addContactMaterial(contactMaterial: ContactMaterial): void;
956 | removeContactMaterial(cm: ContactMaterial): void;
957 | getContactMaterial(materialA: Material, materialB: Material): ContactMaterial; // ContactMaterial | boolean
958 | removeConstraint(c: Constraint): void;
959 | step(dy: number, timeSinceLastCalled?: number, maxSubSteps?: number): void;
960 | runNarrowphase(np: Narrowphase, bi: Body, si: Shape, xi: any[], ai: number, bj: Body, sj: Shape, xj: any[], aj: number, cm: number, glen: number): void;
961 | addSpring(s: Spring): void;
962 | removeSpring(s: Spring): void;
963 | addBody(body: Body): void;
964 | removeBody(body: Body): void;
965 | getBodyByID(id: number): Body; //Body | boolean
966 | disableBodyCollision(bodyA: Body, bodyB: Body): void;
967 | enableBodyCollision(bodyA: Body, bodyB: Body): void;
968 | clear(): void;
969 | clone(): World;
970 | hitTest(worldPoint: number[], bodies: Body[], precision: number): Body[];
971 | setGlobalEquationParameters(parameters: {
972 | relaxation?: number;
973 | stiffness?: number;
974 | }): void;
975 | setGlobalStiffness(stiffness: number): void;
976 | setGlobalRelaxation(relaxation: number): void;
977 | }
978 |
979 | }
980 |
--------------------------------------------------------------------------------
/tsd/phaser_box2d.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 |
4 | declare module Phaser {
5 |
6 | module Physics {
7 |
8 | class Box2D {
9 |
10 | constructor(game: Phaser.Game, config?: any);
11 |
12 | // @property {Phaser.Game} game - Local reference to game.
13 | game: Phaser.Game;
14 | // @property {string} version - The version of the Box2D Plugin that is running.
15 | version: string;
16 | // @property {number} ptmRatio - Pixels to Meters ratio - @default 50
17 | ptmRatio: number;
18 | // @property {box2d.b2World} world - The Box2D world in which the simulation is run.
19 | world: box2d.b2World;
20 | // @property {Phaser.Physics.Box2D.DefaultDebugDraw} - used for rendering debug information
21 | debugDraw: Box2D.DefaultDebugDraw;
22 | // @property {Phaser.Physics.Box2D.DefaultContactListener} - used to check if bodies have contact callbacks set
23 | contactListener: Box2D.DefaultContactListener;
24 | // @property {number} nextBodyId - The id to give the next created body
25 | nextBodyId: number;
26 | // @property {number} nextFixtureId - The id to give the next created fixture
27 | nextFixtureId: number;
28 | // @property {box2d.b2Vec2} gravity - The gravity of the Box2D world.
29 | gravity: Box2D.PointProxy;
30 | // @property {number} friction - The default friction for fixtures created by 'enable', or other functions like setRectangle, setPolygon etc
31 | friction: number;
32 | // @property {number} restitution - The default restitution for fixtures created by 'enable', or other functions like setRectangle, setPolygon etc
33 | restitution: number;
34 | // @property {number} density - The default density for fixtures created by 'enable', or other functions like setRectangle, setPolygon etc
35 | density: number;
36 | // @property {number} frameRate - The frame rate the world will be stepped at. Defaults to 1 / 60, but you can change here. Also see useElapsedTime property.
37 | frameRate: number;
38 | // @property {number} velocityIterations - The maximum number of iterations allowed to adjust velocities to match constraints. Defaults to 8.
39 | velocityIterations: number;
40 | // @property {number} positionIterations - The maximum number of iterations allowed to adjust positions to match constraints. Defaults to 3.
41 | positionIterations: number;
42 | // @property {boolean} useElapsedTime - If true the frameRate value will be ignored and instead Box2D will step with the value of Game.Time.physicsElapsed, which is a delta time value.
43 | useElapsedTime: boolean;
44 | // @property {boolean} paused - The paused state of the Box2D world.
45 | paused: boolean;
46 | // @property {box2d.b2ParticleSystem} particleSystem - The World Particle System. Enabled with World.createParticleSystem.
47 | particleSystem: box2d.b2ParticleSystem;
48 | // @property {box2d.b2Body} mouseJointBody - A static body with no fixtures, used internally as the 'body A' for mouse joints when dragging dynamic bodies.
49 | mouseJointBody: box2d.b2Body;
50 | // @property {box2d.b2MouseJoint} mouseJoint - The active mouse joint for dragging dynamic bodies.
51 | mouseJoint: box2d.b2MouseJoint;
52 | // Pixel to meter function overrides.
53 | // mpx: Function;
54 | // pxm: Function;
55 | // @property {object} walls - An object containing the 4 wall bodies that bound the physics world.
56 | walls: Box2D.WallsObject;
57 | // @property {Phaser.Signal} onBodyAdded - Dispatched when a new Body is added to the World.
58 | onBodyAdded: Phaser.Signal;
59 | // @property {Phaser.Signal} onBodyRemoved - Dispatched when a Body is removed from the World.
60 | onBodyRemoved: Phaser.Signal;
61 |
62 | static worldBoundsFilterCategory: number;
63 |
64 | // Returns the next id to use to keep body ids unique
65 | getNextBodyId(): number;
66 | // Returns the next id to use to keep fixture ids unique
67 | getNextFixtureId(): number;
68 | // This will add a Box2D physics body into the removal list for the next step.
69 | removeBodyNextStep(body: Box2D.Body): void;
70 | // Called at the start of the core update loop. Purges flagged bodies from the world.
71 | preUpdate(): void;
72 | // This will create a Box2D physics body on the given game object or array of game objects.
73 | // A game object can only have 1 physics body active at any one time, and it can't be changed until the object is destroyed.
74 | // Note: When the game object is enabled for Box2D physics it has its anchor x/y set to 0.5 so it becomes centered.
75 | enable(object: any, children?: boolean): void;
76 | // Creates a Box2D physics body on the given game object.
77 | // A game object can only have 1 physics body active at any one time, and it can't be changed until the body is nulled.
78 | enableBody(object: any): void;
79 | // Sets the bounds of the Physics world to match the Game.World dimensions.
80 | // You can optionally set which 'walls' to create: left, right, top or bottom.
81 | setBoundsToWorld(left?: boolean, right?: boolean, top?: boolean, bottom?: boolean, collisionCategory?: number, collisionMask?: number): void;
82 | // Sets the bounds of the Physics world to match the given world pixel dimensions.
83 | // You can optionally set which 'walls' to create: left, right, top or bottom.
84 | setBounds(x: number, y: number, width: number, height: number,
85 | left?: boolean, right?: boolean, top?: boolean, bottom?: boolean, collisionCategory?: number, collisionMask?: number): void;
86 | // Pauses the Box2D world independent of the game pause state.
87 | pause(): void;
88 | // Resumes a paused Box2D world.
89 | resume(): void;
90 | // Internal Box2D update loop.
91 | update(): void;
92 | // Clears all bodies from the simulation, resets callbacks.
93 | reset(): void;
94 | // Clears all bodies from the simulation, resets callbacks.
95 | clear(): void;
96 | // Clears all bodies from the simulation and unlinks World from Game. Should only be called on game shutdown. Call `clear` on a State change.
97 | destroy(): void;
98 | // Creates a new Body and adds it to the World.
99 | createBody(x?: number, y?: number, density?: number): Box2D.Body;
100 | // Creates a new dynamic Body and adds a Circle fixture to it of the given size.
101 | createCircle(x?: number, y?: number, radius?: number, offsetX?: number, offsetY?: number): Box2D.Body;
102 | // Creates a new dynamic Body and adds a Rectangle fixture to it of the given dimensions.
103 | createRectangle(x?: number, y?: number, width?: number, height?: number, offsetX?: number, offsetY?: number, rotation?: number): Box2D.Body;
104 | // Creates a new dynamic Body and adds a Polygon fixture to it.
105 | createPolygon(x: number, y: number, vertices: number[], firstIndex?: number, count?: number): Box2D.Body;
106 | // Adds an already created Box2D Body to this Box2D world.
107 | addBody(body: Box2D.Body): boolean;
108 | // Removes a body from the world. This will silently fail if the body wasn't part of the world to begin with.
109 | removeBody(body: Box2D.Body): Box2D.Body;
110 | // Populates and returns an array with references to of all current Bodies in the world.
111 | getBodies(): Box2D.Body[];
112 | // Checks the given object to see if it has a Box2D body and if so returns it.
113 | getBody(object: Object): Box2D.Body;
114 | // Converts the current world into a JSON object.
115 | toJSON(): any;
116 | // Convert Box2D physics value (meters) to pixel scale.
117 | // By default we use a scale of 50px per meter.
118 | // If you need to modify this you can over-ride these functions via the Physics Configuration object.
119 | mpx(v: number): number;
120 | // Convert pixel value to Box2D physics scale (meters).
121 | // By default we use a scale of 50px per meter.
122 | // If you need to modify this you can over-ride these functions via the Physics Configuration object.
123 | pxm(v: number): number;
124 | // Runs the standard 'debug draw' rendering. What actually gets drawn will depend
125 | // on the current status of the flags set in the debug draw object held by the b2World.
126 | // This could perhaps be made modifiable at runtime, but for now it is just rendering
127 | // shapes (see usage of b2Shapes flag below).
128 | renderDebugDraw(context: CanvasRenderingContext2D): void;
129 | // Renders information about the body as text. This is intended to be used internally by Phaser.Utils.Debug.
130 | // To make use of this from your code you would call something like game.debug.bodyInfo(sprite, x, y)
131 | renderBodyInfo(debug: Utils.Debug, body: Box2D.Body): void;
132 | // Returns all fixtures found under the given point. Set the onlyOne parameter to true if you only
133 | // care about finding one fixture under the point.
134 | getFixturesAtPoint(x: number, y: number, onlyOne?: boolean, onlyDynamic?: boolean): box2d.b2Fixture[];
135 | // Returns all bodies (Phaser.Physics.Box2D.Body) found under the given coordinates. Set the onlyOne
136 | // parameter to true if you only care about finding one body.
137 | getBodiesAtPoint(x: number, y: number, onlyOne?: boolean, onlyDynamic?: boolean): box2d.b2Body[];
138 |
139 | // If there is a dynamic body under the given point, a mouse joint will be created
140 | // to drag that body around. Use the mouseDragMove and mouseDragEnd functions to
141 | // continue the drag action. Any mouse drag already in progress will be canceled.
142 | mouseDragStart(point: Phaser.Point): void;
143 | // Updates the target location of the active mouse joint, if there is one. If there
144 | // is no mouse joint active, this does nothing.
145 | mouseDragMove(point: Phaser.Point): void;
146 | // Ends the active mouse joint if there is one. If there is no mouse joint active, does nothing.
147 | mouseDragEnd(): void;
148 |
149 | // Creates a distance joint.
150 | distanceJoint(bodyA: Box2D.Body | Phaser.Sprite, bodyB: Box2D.Body | Phaser.Sprite, length?: number,
151 | ax?: number, ay?: number, bx?: number, by?: number, frequency?: number, damping?: number): box2d.b2DistanceJoint;
152 | // Creates a rope joint.
153 | ropeJoint(bodyA: Box2D.Body | Phaser.Sprite, bodyB: Box2D.Body | Phaser.Sprite, length?: number,
154 | ax?: number, ay?: number, bx?: number, by?: number): box2d.b2RopeJoint;
155 | // Creates a revolute joint.
156 | revoluteJoint(bodyA: Box2D.Body | Phaser.Sprite, bodyB: Box2D.Body | Phaser.Sprite,
157 | ax?: number, ay?: number, bx?: number, by?: number,
158 | motorSpeed?: number, motorTorque?: number, motorEnabled?: boolean,
159 | lowerLimit?: number, upperLimit?: number, limitEnabled?: boolean): box2d.b2RevoluteJoint;
160 | // Creates a prismatic joint.
161 | prismaticJoint(bodyA: Box2D.Body | Phaser.Sprite, bodyB: Box2D.Body | Phaser.Sprite,
162 | axisX?: number, axisY?: number,
163 | ax?: number, ay?: number, bx?: number, by?: number,
164 | motorSpeed?: number, motorForce?: number, motorEnabled?: boolean,
165 | owerLimit?: number, upperLimit?: number, limitEnabled?: boolean,
166 | offsetAngle?:number): box2d.b2PrismaticJoint;
167 | // Creates a friction joint.
168 | frictionJoint(bodyA: Box2D.Body | Phaser.Sprite, bodyB: Box2D.Body | Phaser.Sprite,
169 | maxForce?:number, maxTorque?:number,
170 | ax?: number, ay?: number, bx?: number, by?: number): box2d.b2FrictionJoint;
171 | // Creates a weld joint.
172 | weldJoint(bodyA: Box2D.Body | Phaser.Sprite, bodyB: Box2D.Body | Phaser.Sprite,
173 | ax?: number, ay?: number, bx?: number, by?: number,
174 | frequency?:number, damping?:number): box2d.b2WeldJoint;
175 | // Creates a motor joint.
176 | motorJoint(bodyA: Box2D.Body | Phaser.Sprite, bodyB: Box2D.Body | Phaser.Sprite,
177 | maxForce? :number, maxTorque?:number, correctionFactor?:number,
178 | offsetX?:number, offsetY?:number,
179 | offsetAngle?: number): box2d.b2MotorJoint;
180 | // Creates a wheel joint.
181 | wheelJoint(bodyA: Box2D.Body | Phaser.Sprite, bodyB: Box2D.Body | Phaser.Sprite,
182 | ax?: number, ay?: number, bx?: number, by?: number,
183 | axisX?: number, axisY?: number,
184 | frequency?: number, damping?: number, motorSpeed?: number, motorTorque?: number, motorEnabled?: boolean): box2d.b2WheelJoint;
185 | // Creates a pulley joint.
186 | pulleyJoint(bodyA: Box2D.Body | Phaser.Sprite, bodyB: Box2D.Body | Phaser.Sprite,
187 | ax?: number, ay?: number, bx?: number, by?: number,
188 | gax?: number, gay?: number, gbx?: number, gby?: number,
189 | ratio?: number, lengthA?: number, lengthB?: number): box2d.b2PulleyJoint;
190 | // Creates a gear joint.
191 | gearJoint(joint1: box2d.b2Joint, joint2: box2d.b2Joint, ratio?:number): box2d.b2GearJoint;
192 |
193 |
194 | // Clears all physics bodies from the given TilemapLayer that were created with `World.convertTilemap`.
195 | clearTilemapLayerBodies(map: Phaser.Tilemap, layer: number | string | Phaser.TilemapLayer): void;
196 | // Goes through all tiles in the given Tilemap and TilemapLayer and converts those set to collide into physics bodies.
197 | // Only call this *after* you have specified all of the tiles you wish to collide with calls like Tilemap.setCollisionBetween, etc.
198 | // Every time you call this method it will destroy any previously created bodies and remove them from the world.
199 | // Therefore understand it's a very expensive operation and not to be done in a core game update loop.
200 | convertTilemap(map: Phaser.Tilemap, layer: number | string | Phaser.TilemapLayer, addToWorld?: boolean, optimize?: boolean): Box2D.Body[];
201 |
202 | // Casts a ray and finds intersecting fixtures in the world.
203 | raycast(x1: number, y1: number, x2: number, y2: number, closestHitOnly?: boolean, filterFunction?: Function): Box2D.RaycastHit[];
204 | // Finds all fixtures with AABBs overlapping the given area. This does NOT mean
205 | // that the fixtures themselves are actually overlapping the given area.
206 | queryAABB(x: number, y: number, width: number, height: number): Box2D.AABBHit[];
207 | // Finds all fixtures that overlap the given fixture.
208 | queryFixture(fixture: box2d.b2Fixture): Box2D.AABBHit[];
209 |
210 | // If the PTM ratio is changed after creating the world, the debug draw scale needs to be updated.
211 | setPTMRatio(newRatio: number): void;
212 | }
213 |
214 |
215 | module Box2D {
216 |
217 | class DefaultDebugDraw {
218 |
219 | constructor(pixelsPerMeter: number);
220 |
221 | color: box2d.b2Color;
222 |
223 | // Sets which aspects of the world to render
224 | SetFlags(flags: number): void;
225 | // Gets which aspects of the world are currently set to be rendered
226 | GetFlags(): number;
227 | // Sets the canvas context to use in subsequent rendering and applies overall transform.
228 | start(context: CanvasRenderingContext2D): void;
229 | // Resets transform state to original
230 | stop(): void;
231 | // Push transform
232 | PushTransform(xf: box2d.b2Transform): void;
233 | // Pop transform
234 | PopTransform(): box2d.b2Transform;
235 | // Draw polygon
236 | DrawPolygon(vertices: Array, vertexCount: number, color: box2d.b2Color): void;
237 | // Draw solid polygon
238 | DrawSolidPolygon(vertices: Array, vertexCount: number, color: box2d.b2Color): void;
239 | // Draw circle
240 | DrawCircle(center: box2d.b2Vec2, radius: number, color: box2d.b2Color): void;
241 | // Draw solid circle
242 | DrawSolidCircle(center: box2d.b2Vec2, radius: number, axis: box2d.b2Vec2, color: box2d.b2Color): void;
243 | // Draw segment
244 | DrawSegment(p1: box2d.b2Vec2, p2: box2d.b2Vec2, color: box2d.b2Color): void;
245 | // Draw transform
246 | DrawTransform(xf: box2d.b2Transform): void;
247 | // Draw point
248 | DrawPoint(p: box2d.b2Vec2, size: number, color: box2d.b2Color): void;
249 | // Draw AABB
250 | DrawAABB(aabb: box2d.b2AABB, color: box2d.b2Color): void;
251 |
252 | // shapes - Specifies whether the debug draw should render shapes.
253 | shapes: boolean;
254 | // joints - Specifies whether the debug draw should render joints.
255 | joints: boolean;
256 | // @property {boolean} aabbs - Specifies whether the debug draw should render fixture AABBs.
257 | aabbs: boolean;
258 | // @property {boolean} pairs - Specifies whether the debug draw should render contact pairs.
259 | pairs: boolean;
260 | // @property {boolean} centerOfMass - Specifies whether the debug draw should render the center of mass of bodies.
261 | centerOfMass: boolean;
262 | }
263 |
264 |
265 | class DefaultContactListener {
266 |
267 | constructor();
268 |
269 | // Called when two fixtures begin to touch.
270 | BeginContact(contact: box2d.b2Contact): void;
271 | // Called when two fixtures cease touching.
272 | EndContact(contact: box2d.b2Contact): void;
273 | // Common code for begin and end contacts.
274 | handleContactBeginOrEnd(contact: box2d.b2Contact, begin: boolean): void;
275 | // This is called after a contact is updated. This allows you to
276 | // inspect a contact before it goes to the solver. If you are
277 | // careful, you can modify the contact manifold (e.g. disable contact).
278 | PreSolve(contact: box2d.b2Contact, oldManifold: box2d.b2Manifold): void;
279 | // This lets you inspect a contact after the solver is finished.
280 | PostSolve(contact: box2d.b2Contact, impulse: box2d.b2ContactImpulse): void;
281 | }
282 |
283 |
284 | class PointProxy {
285 |
286 | constructor(world: Physics.Box2D, object: any, gettor: Function, settor: Function);
287 |
288 | x: number;
289 | y: number;
290 | }
291 |
292 |
293 | class Body {
294 |
295 | constructor(game: Phaser.Game, sprite: Phaser.Sprite, x?: number, y?: number, density?: number, world?: Physics.Box2D);
296 |
297 | // @property {Phaser.Game} game - Local reference to game.
298 | game: Phaser.Game;
299 | // @property {Phaser.Physics.Box2D} world - Local reference to the Box2D World.
300 | world: Physics.Box2D;
301 | // @property {number} id - a unique id for this body in the world
302 | id: number;
303 | // @property {Phaser.Sprite} sprite - Reference to the parent Sprite.
304 | sprite: Phaser.Sprite;
305 | // @property {number} type - The type of physics system this body belongs to.
306 | type: number;
307 | // @property {Phaser.Point} offset - The offset of the Physics Body from the Sprite x/y position.
308 | offset: Phaser.Point;
309 | // @property {box2d.b2BodyDef} bodyDef - The Box2D body definition
310 | bodyDef: box2d.b2BodyDef;
311 | // @property {box2d.b2Body} data - The Box2D body data.
312 | data: box2d.b2Body;
313 | // @property {Phaser.Physics.Box2D.PointProxy} velocity - The velocity of the body. Set velocity.x to a negative value to move to the left, position to the right. velocity.y negative values move up, positive move down.
314 | velocity: Box2D.PointProxy;
315 | // @property {boolean} removeNextStep - To avoid deleting this body during a physics step, and causing all kinds of problems, set removeNextStep to true to have it removed in the next preUpdate.
316 | removeNextStep: boolean;
317 |
318 | // Sets a callback to be fired any time a fixture in this Body begins or ends contact with a fixture in the given Body.
319 | setBodyContactCallback(object: Phaser.Sprite | Box2D.Body, callback: Function, callbackContext: any): void;
320 | // Sets a callback to be fired any time the given fixture begins or ends contact something
321 | setFixtureContactCallback(fixture: box2d.b2Fixture, callback: Function, callbackContext: any): void;
322 | // Sets a callback to be fired any time a fixture in this body begins contact with a fixture in another body that matches given category set.
323 | setCategoryContactCallback(category: number, callback: Function, callbackContext: any) : void;
324 | // Sets a callback to be fired when PreSolve is done for contacts between a fixture in this body and a fixture in the given Body.
325 | setBodyPresolveCallback(object: Phaser.Sprite | Box2D.Body, callback: Function, callbackContext: any): void;
326 | // Sets a callback to be fired when PreSolve is done for contacts between a fixture in this body the given fixture.
327 | setFixturePresolveCallback(fixture: box2d.b2Fixture, callback: Function, callbackContext:any) : void;
328 | // Sets a callback to be fired when PreSolve is done for contacts between a fixture in this body and a fixture in another body that matches given category set.
329 | setCategoryPresolveCallback(category: number, callback: Function, callbackContext: any) : void;
330 | // Sets a callback to be fired when PostSolve is done for contacts between a fixture in this body and a fixture in the given Body.
331 | setBodyPostsolveCallback(object: Phaser.Sprite | Box2D.Body, callback: Function, callbackContext:any) : void;
332 | // Sets a callback to be fired when PostSolve is done for contacts between a fixture in this body the given fixture.
333 | setFixturePostsolveCallback(fixture: box2d.b2Fixture, callback: Function, callbackContext: any): void;
334 | // Sets a callback to be fired when PostSolve is done for contacts between a fixture in this body and a fixture in another body that matches given category set.
335 | setCategoryPostsolveCallback(category: number, callback:Function, callbackContext:any): void;
336 |
337 | // Sets the given collision category for all fixtures in this Body, unless a specific fixture is given.
338 | setCollisionCategory(category: number, fixture?: box2d.b2Fixture): void;
339 | // Sets the given collision mask for all fixtures in this Body, unless a specific fixture is given.
340 | setCollisionMask(mask: number, fixture?: box2d.b2Fixture): void;
341 |
342 | // Apply force at the center of mass. This will not cause any rotation.
343 | applyForce(x: number, y: number): void;
344 | // If this Body is dynamic then this will zero its angular velocity.
345 | setZeroRotation(): void;
346 | // If this Body is dynamic then this will zero its velocity on both axis.
347 | setZeroVelocity(): void;
348 | // Sets the linear damping and angular damping to zero.
349 | setZeroDamping(): void;
350 |
351 | // Transform a world point to local body frame.
352 | toLocalPoint(out: box2d.b2Vec2, worldPoint: box2d.b2Vec2): box2d.b2Vec2;
353 | // Transform a local point to world frame.
354 | toWorldPoint(out: box2d.b2Vec2, localPoint: box2d.b2Vec2): box2d.b2Vec2;
355 | // Transform a world vector to local body frame.
356 | toLocalVector(out: box2d.b2Vec2, worldVector: box2d.b2Vec2): box2d.b2Vec2;
357 | // Transform a local vector to world frame.
358 | toWorldVector(out: box2d.b2Vec2, localVector: box2d.b2Vec2): box2d.b2Vec2;
359 |
360 | // This will rotate the Body by the given speed to the left (counter-clockwise).
361 | rotateLeft(speed: number): void;
362 | // This will rotate the Body by the given speed to the left (clockwise).
363 | rotateRight(speed: number): void;
364 | // Moves the Body forwards based on its current angle and the given speed.
365 | // The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second.
366 | moveForward(speed: number): void;
367 | // Moves the Body backwards based on its current angle and the given speed.
368 | // The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second.
369 | moveBackward(speed: number): void;
370 | // Applies a force to the Body that causes it to 'thrust' forwards, based on its current angle and the given speed.
371 | thrust(power: number): void;
372 | // Applies a force to the Body that causes it to 'thrust' backwards (in reverse), based on its current angle and the given speed.
373 | reverse(power: number): void;
374 | // If this Body is dynamic then this will move it to the left by setting its x velocity to the given speed.
375 | // The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second.
376 | moveLeft(speed: number): void;
377 | // If this Body is dynamic then this will move it to the right by setting its x velocity to the given speed.
378 | // The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second.
379 | moveRight(speed: number): void;
380 | // If this Body is dynamic then this will move it up by setting its y velocity to the given speed.
381 | // The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second.
382 | moveUp(speed: number): void;
383 | // If this Body is dynamic then this will move it down by setting its y velocity to the given speed.
384 | // The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second.
385 | moveDown(speed: number): void;
386 |
387 | // Internal method. This is called directly before the sprites are sent to the renderer and after the update function has finished.
388 | // preUpdate(): void;
389 | // Internal method. This is called directly before the sprites are sent to the renderer and after the update function has finished.
390 | // postUpdate(): void;
391 |
392 | // Sets this body as inactive. It will not participate in collisions or
393 | // any other aspect of the physics simulation. Intended for use by Phaser.Sprite.kill()
394 | kill(): void;
395 | // Restores the active status of this body.
396 | reset(x: number, y: number): void;
397 | // Removes this physics body from the world.
398 | removeFromWorld(): void;
399 | // Destroys this Body and all references it holds to other objects.
400 | destroy(): void;
401 |
402 | // Removes all fixtures from this Body.
403 | clearFixtures(): void;
404 | // Adds a Circle fixture to this Body. You can control the offset from the center of the body and the rotation.
405 | // It will use the World friction, restitution and density by default.
406 | addCircle(radius:number, offsetX ?:number, offsetY ?:number): box2d.b2Fixture;
407 | // Adds a Rectangle fixture to this Body. You can control the offset from the center of the body and the rotation.
408 | // It will use the World friction, restitution and density by default.
409 | addRectangle(width ?:number, height ?:number, offsetX ?:number, offsetY ?:number, rotation ?:number): box2d.b2Fixture;
410 | // Creates a new Edge Shape and adds it to this Body.
411 | // It will use the World friction, restitution and density by default.
412 | addEdge(x1 ?:number, y1 ?:number, x2 ?:number, y2 ?:number): box2d.b2Fixture;
413 | // Creates a new chain shape and adds it to this Body.
414 | // It will use the World friction, restitution and density by default.
415 | addChain(vertices: number[], firstIndex ?:number, count ?:number, loop ?:boolean): box2d.b2Fixture;
416 | // Creates a new loop shape and adds it to this Body.
417 | addLoop(vertices: number[], firstIndex ?:number, count ?:number): box2d.b2Fixture;
418 | // Creates a new polygon shape and adds it to this Body.
419 | addPolygon(vertices: number[], firstIndex ?: number, count ?:number): box2d.b2Fixture;
420 | // Remove a shape from the body. Will automatically update the mass properties and bounding radius.
421 | removeFixture(fixture: box2d.b2Fixture): boolean;
422 | // Clears any previously set fixtures. Then creates a new Circle shape and adds it to this Body.
423 | setCircle(radius ?:number, offsetX ?:number, offsetY ?:number): box2d.b2Fixture;
424 | // Clears any previously set fixtures. The creates a new Rectangle fixture at the given size and offset, and adds it to this Body.
425 | // If you wish to create a Rectangle to match the size of a Sprite or Image see Body.setRectangleFromSprite.
426 | setRectangle(width ?:number, height ?:number, offsetX ?:number, offsetY ?:number, rotation ?:number): box2d.b2Fixture;
427 | // Clears any previously set fixtures.
428 | // Then creates a Rectangle shape sized to match the dimensions and orientation of the Sprite given.
429 | // If no Sprite is given it defaults to using the parent of this Body.
430 | setRectangleFromSprite(sprite: Phaser.Sprite | Phaser.Image): box2d.b2Fixture;
431 | // Clears any previously set fixtures. Then creates a new edge shape and adds it to this Body.
432 | setEdge(x1 ?:number, y1 ?:number, x2 ?:number, y2?:number): box2d.b2Fixture;
433 | // Clears any previously set fixtures. Then creates a new chain shape and adds it to this Body.
434 | setChain(vertices: number[], firstIndex?:number, count?:number, loop?:boolean): box2d.b2Fixture;
435 | // An alias for setChain.
436 | setLoop(vertices: number[], firstIndex?:number, count?:number): box2d.b2Fixture;
437 | // Clears any previously set fixtures. Then creates a new polygon shape and adds it to this Body.
438 | setPolygon(vertices: number[], firstIndex?: number, count?: number): box2d.b2Fixture;
439 | // Reads the shape data from a physics data file stored in the Game.Cache and adds it as a polygon to this Body.
440 | loadPolygon(key: string, object: string, sprite: Phaser.Sprite | Phaser.Image):boolean;
441 |
442 |
443 | // Checks if the given point (pixel coords) is contained by any of the fixtures on this body.
444 | // Not efficient for checking a large number of bodies to find which is under the mouse. (Use
445 | // Phaser.Physics.Box2D.getBodiesAtPoint for that.)
446 | containsPoint(point: Phaser.Point): boolean;
447 |
448 | // @property {boolean} static - Returns true if the Body is static. Setting Body.static to 'false' will make it dynamic.
449 | static: boolean;
450 | // @property {boolean} dynamic - Returns true if the Body is dynamic. Setting Body.dynamic to 'false' will make it static.
451 | dynamic: boolean;
452 | // @property {boolean} kinematic - Returns true if the Body is kinematic. Setting Body.kinematic to 'false' will make it static.
453 | kinematic: boolean;
454 |
455 | // @property {number} angle - The angle of this Body in degrees.
456 | angle: number;
457 | // @property {number} linearDamping - The linear damping acting acting on the body.
458 | linearDamping: number;
459 | // @property {number} angularDamping - The angular damping acting acting on the body.
460 | angularDamping: number;
461 | // @property {number} angularVelocity - The angular velocity of the body.
462 | angularVelocity: number;
463 | // @property {boolean} fixedRotation - If true, the body will not rotate.
464 | fixedRotation: boolean;
465 | // @property {number} gravityScale - Set to zero to completely ignore gravity, or negative values to reverse gravity for this body.
466 | gravityScale: number;
467 | // @property {number} friction - When setting, all fixtures on the body will be set to the given friction. When getting, the friction of the first fixture will be returned, or zero if no fixtures are present.
468 | friction: number;
469 | // @property {number} restitution - When setting, all fixtures on the body will be set to the given restitution. When getting, the restitution of the first fixture will be returned, or zero if no fixtures are present.
470 | restitution: number;
471 | // @property {boolean} sensor - When setting, all fixtures on the body will be set to the given sensor status. When getting, the sensor status of the first fixture will be returned, or false if no fixtures are present.
472 | sensor: boolean;
473 | // @property {boolean} bullet - Set to true to give the body 'bullet' status, and use continous collision detection when moving it.
474 | bullet: boolean;
475 | // @property {number} mass - the new mass for the body. Setting this to zero will cause the body to become a static body.
476 | mass: number;
477 | // @property {number} rotation - The angle of this Body in radians.
478 | rotation: number;
479 | // @property {number} x - The x coordinate of this Body.
480 | x: number;
481 | // @property {number} y - The y coordinate of this Body.
482 | y: number;
483 | // @property {boolean} collideWorldBounds - Should the Body collide with the World bounds?
484 | collideWorldBounds: boolean;
485 | }
486 |
487 |
488 | class WallsObject {
489 | left: any;
490 | right: any;
491 | top: any;
492 | bottom: any;
493 | }
494 |
495 |
496 | class AABBHit {
497 | body: Box2D.Body;
498 | fixture: box2d.b2Fixture;
499 | }
500 |
501 |
502 | class RaycastHit extends AABBHit {
503 | point: Phaser.Point;
504 | normal: Phaser.Point;
505 | }
506 | }
507 | }
508 | }
509 |
--------------------------------------------------------------------------------
/tsd/pixi.comments.d.ts:
--------------------------------------------------------------------------------
1 | // Type definitions for PIXI with Phaser Deviations.
2 |
3 | declare module PIXI {
4 |
5 | export var game: Phaser.Game;
6 | export var WEBGL_RENDERER: number;
7 | export var CANVAS_RENDERER: number;
8 | export var VERSION: string;
9 |
10 | export enum blendModes {
11 |
12 | NORMAL,
13 | ADD,
14 | MULTIPLY,
15 | SCREEN,
16 | OVERLAY,
17 | DARKEN,
18 | LIGHTEN,
19 | COLOR_DODGE,
20 | COLOR_BURN,
21 | HARD_LIGHT,
22 | SOFT_LIGHT,
23 | DIFFERENCE,
24 | EXCLUSION,
25 | HUE,
26 | SATURATION,
27 | COLOR,
28 | LUMINOSITY
29 |
30 | }
31 |
32 | export enum scaleModes {
33 |
34 | DEFAULT,
35 | LINEAR,
36 | NEAREST
37 |
38 | }
39 |
40 | export var glContexts: WebGLRenderingContext[];
41 | export var instances: any[];
42 |
43 | export var TextureSilentFail: boolean;
44 |
45 | export function canUseNewCanvasBlendModes(): boolean;
46 |
47 | export function CompileFragmentShader(gl: WebGLRenderingContext, shaderSrc: string[]): any;
48 |
49 | export interface IEventCallback {
50 | (e?: IEvent): void;
51 | }
52 |
53 | export interface IEvent {
54 | type: string;
55 | content: any;
56 | }
57 |
58 | export interface HitArea {
59 | contains(x: number, y: number): boolean;
60 | }
61 |
62 | export interface IInteractionDataCallback {
63 | (interactionData: InteractionData): void;
64 | }
65 |
66 | export interface PixiRenderer {
67 |
68 | autoResize: boolean;
69 | clearBeforeRender: boolean;
70 | height: number;
71 | resolution: number;
72 | transparent: boolean;
73 | type: number;
74 | view: HTMLCanvasElement;
75 | width: number;
76 |
77 | destroy(): void;
78 | render(stage: DisplayObjectContainer): void;
79 | resize(width: number, height: number): void;
80 |
81 | }
82 |
83 | export interface PixiRendererOptions {
84 |
85 | autoResize?: boolean;
86 | antialias?: boolean;
87 | clearBeforeRender?: boolean;
88 | preserveDrawingBuffer?: boolean;
89 | resolution?: number;
90 | transparent?: boolean;
91 | view?: HTMLCanvasElement;
92 |
93 | }
94 |
95 | export interface BitmapTextStyle {
96 |
97 | font?: string;
98 | align?: string;
99 | tint?: string;
100 |
101 | }
102 |
103 | export interface TextStyle {
104 |
105 | align?: string;
106 | dropShadow?: boolean;
107 | dropShadowColor?: string;
108 | dropShadowAngle?: number;
109 | dropShadowDistance?: number;
110 | fill?: string;
111 | font?: string;
112 | lineJoin?: string;
113 | stroke?: string;
114 | strokeThickness?: number;
115 | wordWrap?: boolean;
116 | wordWrapWidth?: number;
117 |
118 | }
119 |
120 | export interface Loader {
121 |
122 | load(): void;
123 |
124 | }
125 |
126 | export interface MaskData {
127 |
128 | alpha: number;
129 | worldTransform: number[];
130 |
131 | }
132 |
133 | export interface RenderSession {
134 |
135 | context: CanvasRenderingContext2D;
136 | maskManager: CanvasMaskManager;
137 | scaleMode: scaleModes;
138 | smoothProperty: string;
139 | roundPixels: boolean;
140 |
141 | }
142 |
143 | export interface ShaderAttribute {
144 | // TODO: Find signature of shader attributes
145 | }
146 |
147 | export interface FilterBlock {
148 |
149 | visible: boolean;
150 | renderable: boolean;
151 |
152 | }
153 |
154 | // Phaser.Filter is used instead
155 | export class AbstractFilter {
156 |
157 | constructor(fragmentSrc: string | string[], uniforms: any);
158 |
159 | dirty: boolean;
160 | padding: number;
161 | uniforms: any;
162 | fragmentSrc: string | string[];
163 |
164 | apply(frameBuffer: WebGLFramebuffer): void;
165 | syncUniforms(): void;
166 |
167 | }
168 |
169 |
170 | /**
171 | * A texture stores the information that represents an image. All textures have a base texture.
172 | */
173 | export class BaseTexture implements Mixin {
174 |
175 |
176 | /**
177 | * Helper function that creates a base texture from the given canvas element.
178 | *
179 | * @param canvas The canvas element source of the texture
180 | * @param scaleMode See {{#crossLink "PIXI/scaleModes:property"}}PIXI.scaleModes{{/crossLink}} for possible values
181 | * @param resolution the resolution of the texture (for HiDPI displays)
182 | */
183 | static fromCanvas(canvas: HTMLCanvasElement, scaleMode?: scaleModes): BaseTexture;
184 |
185 |
186 | /**
187 | * A texture stores the information that represents an image. All textures have a base texture.
188 | *
189 | * @param source the source object (image or canvas)
190 | * @param scaleMode See {{#crossLink "PIXI/scaleModes:property"}}PIXI.scaleModes{{/crossLink}} for possible values
191 | * @param resolution the resolution of the texture (for HiDPI displays)
192 | */
193 | constructor(source: HTMLCanvasElement | HTMLImageElement | HTMLVideoElement, scaleMode: scaleModes, resolution?: number);
194 |
195 |
196 | /**
197 | * [read-only] The height of the base texture set when the image has loaded
198 | */
199 | height: number;
200 |
201 | /**
202 | * [read-only] Set to true once the base texture has loaded
203 | */
204 | hasLoaded: boolean;
205 |
206 | /**
207 | * Set this to true if a mipmap of this texture needs to be generated. This value needs to be set before the texture is used
208 | * Also the texture must be a power of two size to work
209 | */
210 | mipmap: boolean;
211 |
212 | /**
213 | * Controls if RGB channels should be pre-multiplied by Alpha (WebGL only)
214 | * Default: true
215 | */
216 | premultipliedAlpha: boolean;
217 |
218 | /**
219 | * The Resolution of the texture.
220 | */
221 | resolution: number;
222 |
223 | /**
224 | * The scale mode to apply when scaling this texture
225 | * Default: PIXI.scaleModes.LINEAR
226 | */
227 | scaleMode: scaleModes;
228 |
229 | /**
230 | * A BaseTexture can be set to skip the rendering phase in the WebGL Sprite Batch.
231 | *
232 | * You may want to do this if you have a parent Sprite with no visible texture (i.e. uses the internal `__default` texture)
233 | * that has children that you do want to render, without causing a batch flush in the process.
234 | */
235 | skipRender: boolean;
236 |
237 | /**
238 | * The image source that is used to create the texture.
239 | */
240 | source: HTMLCanvasElement | HTMLImageElement | HTMLVideoElement;
241 |
242 | /**
243 | * The multi texture batching index number.
244 | */
245 | textureIndex: number;
246 |
247 | /**
248 | * [read-only] The width of the base texture set when the image has loaded
249 | */
250 | width: number;
251 |
252 | _dirty: boolean[];
253 | _glTextures: WebGLTexture[];
254 |
255 | listeners(eventName: string): Function[];
256 | emit(eventName: string, data?: any): boolean;
257 | dispatchEvent(eventName: string, data?: any): boolean;
258 | on(eventName: string, fn: Function): Function;
259 | addEventListener(eventName: string, fn: Function): Function;
260 | once(eventName: string, fn: Function): Function;
261 | off(eventName: string, fn: Function): Function;
262 | removeAllEventListeners(eventName: string): void;
263 |
264 | /**
265 | * Forces this BaseTexture to be set as loaded, with the given width and height.
266 | * Then calls BaseTexture.dirty.
267 | * Important for when you don't want to modify the source object by forcing in `complete` or dimension properties it may not have.
268 | *
269 | * @param width The new width to force the BaseTexture to be.
270 | * @param height The new height to force the BaseTexture to be.
271 | */
272 | forceLoaded(width: number, height: number): void;
273 |
274 | /**
275 | * Destroys this base texture
276 | */
277 | destroy(): void;
278 |
279 | /**
280 | * Sets all glTextures to be dirty.
281 | */
282 | dirty(): void;
283 |
284 | /**
285 | * Removes the base texture from the GPU, useful for managing resources on the GPU.
286 | * Atexture is still 100% usable and will simply be reuploaded if there is a sprite on screen that is using it.
287 | */
288 | unloadFromGPU(): void;
289 |
290 | }
291 |
292 |
293 | /**
294 | * Creates a Canvas element of the given size.
295 | */
296 | export class CanvasBuffer {
297 |
298 |
299 | /**
300 | * Creates a Canvas element of the given size.
301 | *
302 | * @param width the width for the newly created canvas
303 | * @param height the height for the newly created canvas
304 | */
305 | constructor(width: number, height: number);
306 |
307 |
308 | /**
309 | * The Canvas object that belongs to this CanvasBuffer.
310 | */
311 | canvas: HTMLCanvasElement;
312 |
313 | /**
314 | * A CanvasRenderingContext2D object representing a two-dimensional rendering context.
315 | */
316 | context: CanvasRenderingContext2D;
317 |
318 | /**
319 | * The height of the Canvas in pixels.
320 | */
321 | height: number;
322 |
323 | /**
324 | * The width of the Canvas in pixels.
325 | */
326 | width: number;
327 |
328 |
329 | /**
330 | * Frees the canvas up for use again.
331 | */
332 | destroy(): void;
333 |
334 | /**
335 | * Clears the canvas that was created by the CanvasBuffer class.
336 | */
337 | clear(): void;
338 |
339 | /**
340 | * Resizes the canvas to the specified width and height.
341 | *
342 | * @param width the new width of the canvas
343 | * @param height the new height of the canvas
344 | */
345 | resize(width: number, height: number): void;
346 |
347 | }
348 |
349 |
350 | /**
351 | * A set of functions used to handle masking.
352 | */
353 | export class CanvasMaskManager {
354 |
355 |
356 | /**
357 | * This method adds it to the current stack of masks.
358 | *
359 | * @param maskData the maskData that will be pushed
360 | * @param renderSession The renderSession whose context will be used for this mask manager.
361 | */
362 | pushMask(maskData: MaskData, renderSession: RenderSession): void;
363 |
364 | /**
365 | * Restores the current drawing context to the state it was before the mask was applied.
366 | *
367 | * @param renderSession The renderSession whose context will be used for this mask manager.
368 | */
369 | popMask(renderSession: RenderSession): void;
370 |
371 | }
372 |
373 |
374 | /**
375 | * The CanvasRenderer draws the Stage and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL.
376 | * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :)
377 | */
378 | export class CanvasRenderer implements PixiRenderer {
379 |
380 |
381 | /**
382 | * The CanvasRenderer draws the Stage and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL.
383 | * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :)
384 | *
385 | * @param game A reference to the Phaser Game instance
386 | */
387 | constructor(game: Phaser.Game);
388 |
389 |
390 | /**
391 | * A reference to the Phaser Game instance.
392 | */
393 | game: Phaser.Game;
394 |
395 | /**
396 | * The renderer type.
397 | */
398 | type: number;
399 |
400 | /**
401 | * The resolution of the canvas.
402 | */
403 | resolution: number;
404 |
405 | /**
406 | * This sets if the CanvasRenderer will clear the canvas or not before the new render pass.
407 | * If the Stage is NOT transparent Pixi will use a canvas sized fillRect operation every frame to set the canvas background color.
408 | * If the Stage is transparent Pixi will use clearRect to clear the canvas every frame.
409 | * Disable this by setting this to false. For example if your game has a canvas filling background image you often don't need this set.
410 | */
411 | clearBeforeRender: boolean;
412 |
413 | /**
414 | * Whether the render view is transparent
415 | */
416 | transparent: boolean;
417 |
418 | /**
419 | * Whether the render view should be resized automatically
420 | */
421 | autoResize: boolean;
422 |
423 | /**
424 | * The width of the canvas view
425 | * Default: 800
426 | */
427 | width: number;
428 |
429 | /**
430 | * The height of the canvas view
431 | * Default: 600
432 | */
433 | height: number;
434 |
435 | /**
436 | * The canvas element that everything is drawn to.
437 | */
438 | view: HTMLCanvasElement;
439 |
440 | /**
441 | * The canvas 2d context that everything is drawn with
442 | */
443 | context: CanvasRenderingContext2D;
444 |
445 | /**
446 | * Boolean flag controlling canvas refresh.
447 | */
448 | refresh: boolean;
449 |
450 | /**
451 | * Internal var.
452 | */
453 | count: number;
454 |
455 | /**
456 | * Instance of a PIXI.CanvasMaskManager, handles masking when using the canvas renderer
457 | */
458 | maskManager: CanvasMaskManager;
459 |
460 | /**
461 | * The render session is just a bunch of parameter used for rendering
462 | */
463 | renderSession: RenderSession;
464 |
465 |
466 | /**
467 | * Renders the DisplayObjectContainer, usually the Phaser.Stage, to this canvas view.
468 | *
469 | * @param root The root element to be rendered.
470 | */
471 | render(stage: DisplayObjectContainer): void;
472 | postRender(): void;
473 |
474 | /**
475 | * Resizes the canvas view to the specified width and height
476 | *
477 | * @param width the new width of the canvas view
478 | * @param height the new height of the canvas view
479 | */
480 | resize(width: number, height: number): void;
481 | setTexturePriority(textureNameCollection: string[]): string[];
482 |
483 | /**
484 | * Removes everything from the renderer and optionally removes the Canvas DOM element.
485 | *
486 | * @param removeView Removes the Canvas element from the DOM. - Default: true
487 | */
488 | destroy(removeView?: boolean): void;
489 |
490 | }
491 |
492 |
493 | /**
494 | * Utility methods for Sprite/Texture tinting.
495 | */
496 | export class CanvasTinter {
497 |
498 |
499 | /**
500 | * Basically this method just needs a sprite and a color and tints the sprite with the given color.
501 | *
502 | * @param sprite the sprite to tint
503 | * @param color the color to use to tint the sprite with
504 | * @return The tinted canvas
505 | */
506 | static getTintedTexture(sprite: Sprite, color: number): HTMLCanvasElement;
507 |
508 | /**
509 | * Tint a texture using the "multiply" operation.
510 | *
511 | * @param texture the texture to tint
512 | * @param color the color to use to tint the sprite with
513 | * @param canvas the current canvas
514 | */
515 | static tintWithMultiply(texture: Texture, color: number, canvas: HTMLCanvasElement): void;
516 | static tintWithOverlay(texture: Texture, color: number, canvas: HTMLCanvasElement): void;
517 | static tintWithPerPixel(texture: Texture, color: number, canvas: HTMLCanvasElement): void;
518 |
519 | static canUseMultiply: boolean;
520 | static tintMethod: any;
521 |
522 | }
523 |
524 |
525 | /**
526 | * The base class for all objects that are rendered. Contains properties for position, scaling,
527 | * rotation, masks and cache handling.
528 | *
529 | * This is an abstract class and should not be used on its own, rather it should be extended.
530 | *
531 | * It is used internally by the likes of PIXI.Sprite.
532 | */
533 | export class DisplayObject {
534 |
535 |
536 | /**
537 | * The alpha value of this DisplayObject. A value of 1 is fully opaque. A value of 0 is transparent.
538 | * Please note that an object with an alpha value of 0 is skipped during the render pass.
539 | *
540 | * The value of this property does not reflect any alpha values set further up the display list.
541 | * To obtain that value please see the `worldAlpha` property.
542 | * Default: 1
543 | */
544 | alpha: number;
545 | buttonMode: boolean;
546 |
547 | /**
548 | * Sets if this DisplayObject should be cached as a bitmap.
549 | *
550 | * When invoked it will take a snapshot of the DisplayObject, as it is at that moment, and store it
551 | * in a RenderTexture. This is then used whenever this DisplayObject is rendered. It can provide a
552 | * performance benefit for complex, but static, DisplayObjects. I.e. those with lots of children.
553 | *
554 | * Transparent areas adjoining the edges may be removed ({@link https://github.com/photonstorm/phaser-ce/issues/283 #283}).
555 | *
556 | * Cached Bitmaps do not track their parents. If you update a property of this DisplayObject, it will not
557 | * re-generate the cached bitmap automatically. To do that you need to call `DisplayObject.updateCache`.
558 | *
559 | * To remove a cached bitmap, set this property to `null`. Cache this DisplayObject as a Bitmap. Set to `null` to remove an existing cached bitmap.
560 | */
561 | cacheAsBitmap: boolean;
562 | defaultCursor: string;
563 |
564 | /**
565 | * The rectangular area used by filters when rendering a shader for this DisplayObject.
566 | */
567 | filterArea: Rectangle;
568 |
569 | /**
570 | * Sets the filters for this DisplayObject. This is a WebGL only feature, and is ignored by the Canvas
571 | * Renderer. A filter is a shader applied to this DisplayObject. You can modify the placement of the filter
572 | * using `DisplayObject.filterArea`.
573 | *
574 | * To remove filters, set this property to `null`.
575 | *
576 | * Note: You cannot have a filter set, and a MULTIPLY Blend Mode active, at the same time. Setting a
577 | * filter will reset this DisplayObjects blend mode to NORMAL. An Array of Phaser.Filter objects, or objects that extend them.
578 | */
579 | filters: AbstractFilter[];
580 |
581 | /**
582 | * This is the defined area that will pick up mouse / touch events. It is null by default.
583 | * Setting it is a neat way of optimising the hitTest function that the interactionManager will use (as it will not need to hit test all the children)
584 | */
585 | hitArea: HitArea;
586 | interactive: boolean;
587 |
588 | /**
589 | * Sets a mask for this DisplayObject. A mask is an instance of a Graphics object.
590 | * When applied it limits the visible area of this DisplayObject to the shape of the mask.
591 | * Under a Canvas renderer it uses shape clipping. Under a WebGL renderer it uses a Stencil Buffer.
592 | * To remove a mask, set this property to `null`. The mask applied to this DisplayObject. Set to `null` to remove an existing mask.
593 | */
594 | mask: Phaser.Graphics;
595 |
596 | /**
597 | * The parent DisplayObjectContainer that this DisplayObject is a child of.
598 | * All DisplayObjects must belong to a parent in order to be rendered.
599 | * The root parent is the Stage object. This property is set automatically when the
600 | * DisplayObject is added to, or removed from, a DisplayObjectContainer.
601 | */
602 | parent: DisplayObjectContainer;
603 |
604 | /**
605 | * The pivot point of this DisplayObject that it rotates around. The values are expressed
606 | * in pixel values.
607 | */
608 | pivot: Point;
609 |
610 | /**
611 | * The coordinates, in pixels, of this DisplayObject, relative to its parent container.
612 | *
613 | * The value of this property does not reflect any positioning happening further up the display list.
614 | * To obtain that value please see the `worldPosition` property.
615 | */
616 | position: Point;
617 |
618 | /**
619 | * Should this DisplayObject be rendered by the renderer? An object with a renderable value of
620 | * `false` is skipped during the render pass.
621 | */
622 | renderable: boolean;
623 |
624 | /**
625 | * The rotation of this DisplayObject. The value is given, and expressed, in radians, and is based on
626 | * a right-handed orientation.
627 | *
628 | * The value of this property does not reflect any rotation happening further up the display list.
629 | * To obtain that value please see the `worldRotation` property.
630 | */
631 | rotation: number;
632 |
633 | /**
634 | * The scale of this DisplayObject. A scale of 1:1 represents the DisplayObject
635 | * at its default size. A value of 0.5 would scale this DisplayObject by half, and so on.
636 | *
637 | * The value of this property does not reflect any scaling happening further up the display list.
638 | * To obtain that value please see the `worldScale` property.
639 | */
640 | scale: Point;
641 | stage: DisplayObjectContainer;
642 |
643 | /**
644 | * The visibility of this DisplayObject. A value of `false` makes the object invisible.
645 | * A value of `true` makes it visible.
646 | *
647 | * An object with a visible value of `false` is skipped during the render pass.
648 | * Equally a DisplayObject with visible `false` will not render any of its children.
649 | *
650 | * The value of this property does not reflect any visible values set further up the display list.
651 | * To obtain that value please see the {@link PIXI.DisplayObject#worldVisible worldVisible} property.
652 | *
653 | * Objects that are not {@link PIXI.DisplayObject#worldVisible worldVisible} do not update their {@link PIXI.DisplayObject#worldPosition worldPosition}.
654 | * Default: true
655 | */
656 | visible: boolean;
657 |
658 | /**
659 | * The multiplied alpha value of this DisplayObject. A value of 1 is fully opaque. A value of 0 is transparent.
660 | * This value is the calculated total, based on the alpha values of all parents of this DisplayObjects
661 | * in the display list.
662 | *
663 | * To obtain, and set, the local alpha value, see the `alpha` property.
664 | *
665 | * Note: This property is only updated at the end of the `updateTransform` call, once per render. Until
666 | * that happens this property will contain values based on the previous frame. Be mindful of this if
667 | * accessing this property outside of the normal game flow, i.e. from an asynchronous event callback.
668 | */
669 | worldAlpha: number;
670 |
671 | /**
672 | * The coordinates, in pixels, of this DisplayObject within the world.
673 | *
674 | * This property contains the calculated total, based on the positions of all parents of this
675 | * DisplayObject in the display list.
676 | *
677 | * Note: This property is only updated at the end of the `updateTransform` call, once per render. Until
678 | * that happens this property will contain values based on the previous frame. Be mindful of this if
679 | * accessing this property outside of the normal game flow, i.e. from an asynchronous event callback.
680 | */
681 | worldPosition: Point;
682 |
683 | /**
684 | * The global scale of this DisplayObject.
685 | *
686 | * This property contains the calculated total, based on the scales of all parents of this
687 | * DisplayObject in the display list.
688 | *
689 | * Note: This property is only updated at the end of the `updateTransform` call, once per render. Until
690 | * that happens this property will contain values based on the previous frame. Be mindful of this if
691 | * accessing this property outside of the normal game flow, i.e. from an asynchronous event callback.
692 | */
693 | worldScale: Point;
694 |
695 | /**
696 | * The current transform of this DisplayObject.
697 | *
698 | * This property contains the calculated total, based on the transforms of all parents of this
699 | * DisplayObject in the display list.
700 | *
701 | * Note: This property is only updated at the end of the `updateTransform` call, once per render. Until
702 | * that happens this property will contain values based on the previous frame. Be mindful of this if
703 | * accessing this property outside of the normal game flow, i.e. from an asynchronous event callback.
704 | */
705 | worldTransform: Matrix;
706 |
707 | /**
708 | * The rotation, in radians, of this DisplayObject.
709 | *
710 | * This property contains the calculated total, based on the rotations of all parents of this
711 | * DisplayObject in the display list.
712 | *
713 | * Note: This property is only updated at the end of the `updateTransform` call, once per render. Until
714 | * that happens this property will contain values based on the previous frame. Be mindful of this if
715 | * accessing this property outside of the normal game flow, i.e. from an asynchronous event callback.
716 | */
717 | worldRotation: number;
718 |
719 | /**
720 | * Indicates if this DisplayObject is visible, based on it, and all of its parents, `visible` property values.
721 | */
722 | worldVisible: boolean;
723 |
724 | /**
725 | * The horizontal position of the DisplayObject, in pixels, relative to its parent.
726 | * If you need the world position of the DisplayObject, use `DisplayObject.worldPosition` instead.
727 | */
728 | x: number;
729 |
730 | /**
731 | * The vertical position of the DisplayObject, in pixels, relative to its parent.
732 | * If you need the world position of the DisplayObject, use `DisplayObject.worldPosition` instead.
733 | */
734 | y: number;
735 |
736 | click(e: InteractionData): void;
737 | displayObjectUpdateTransform(parent?: DisplayObjectContainer): void;
738 |
739 | /**
740 | * Generates a RenderTexture based on this DisplayObject, which can they be used to texture other Sprites.
741 | * This can be useful if your DisplayObject is static, or complicated, and needs to be reused multiple times.
742 | *
743 | * Please note that no garbage collection takes place on old textures. It is up to you to destroy old textures,
744 | * and references to them, so they don't linger in memory.
745 | *
746 | * @param resolution The resolution of the texture being generated. - Default: 1
747 | * @param scaleMode See {{#crossLink "PIXI/scaleModes:property"}}PIXI.scaleModes{{/crossLink}} for possible values. - Default: PIXI.scaleModes.DEFAULT
748 | * @param renderer The renderer used to generate the texture.
749 | * @return - A RenderTexture containing an image of this DisplayObject at the time it was invoked.
750 | */
751 | generateTexture(resolution?: number, scaleMode?: number, renderer?: PixiRenderer | number): Phaser.RenderTexture;
752 | mousedown(e: InteractionData): void;
753 | mouseout(e: InteractionData): void;
754 | mouseover(e: InteractionData): void;
755 | mouseup(e: InteractionData): void;
756 | mousemove(e: InteractionData): void;
757 | mouseupoutside(e: InteractionData): void;
758 | rightclick(e: InteractionData): void;
759 | rightdown(e: InteractionData): void;
760 | rightup(e: InteractionData): void;
761 | rightupoutside(e: InteractionData): void;
762 | setStageReference(stage: DisplayObjectContainer): void;
763 | tap(e: InteractionData): void;
764 |
765 | /**
766 | * Calculates the global position of this DisplayObject, based on the position given.
767 | *
768 | * @param position The global position to calculate from.
769 | * @return - A point object representing the position of this DisplayObject based on the global position given.
770 | */
771 | toGlobal(position: Point): Point;
772 |
773 | /**
774 | * Calculates the local position of this DisplayObject, relative to another point.
775 | *
776 | * @param position The world origin to calculate from.
777 | * @param from An optional DisplayObject to calculate the global position from.
778 | * @return - A point object representing the position of this DisplayObject based on the global position given.
779 | */
780 | toLocal(position: Point, from: DisplayObject): Point;
781 | touchend(e: InteractionData): void;
782 | touchendoutside(e: InteractionData): void;
783 | touchstart(e: InteractionData): void;
784 | touchmove(e: InteractionData): void;
785 |
786 | /**
787 | * Updates the transform matrix this DisplayObject uses for rendering.
788 | *
789 | * If the object has no parent, and no parent parameter is provided, it will default to
790 | * Phaser.Game.World as the parent transform to use. If that is unavailable the transform fails to take place.
791 | *
792 | * The `parent` parameter has priority over the actual parent. Use it as a parent override.
793 | * Setting it does **not** change the actual parent of this DisplayObject.
794 | *
795 | * Calling this method updates the `worldTransform`, `worldAlpha`, `worldPosition`, `worldScale`
796 | * and `worldRotation` properties.
797 | *
798 | * If a `transformCallback` has been specified, it is called at the end of this method, and is passed
799 | * the new, updated, worldTransform property, along with the parent transform used.
800 | *
801 | * @param parent Optional parent to calculate this DisplayObjects transform from.
802 | * @return - A reference to this DisplayObject.
803 | */
804 | updateTransform(parent?: DisplayObjectContainer): void;
805 |
806 | /**
807 | * If this DisplayObject has a cached Sprite, this method generates and updates it.
808 | * @return - A reference to this DisplayObject.
809 | */
810 | updateCache(): void;
811 |
812 | }
813 |
814 |
815 | /**
816 | * A DisplayObjectContainer represents a collection of display objects.
817 | * It is the base class of all display objects that act as a container for other objects.
818 | */
819 | export class DisplayObjectContainer extends DisplayObject {
820 |
821 |
822 | /**
823 | * A DisplayObjectContainer represents a collection of display objects.
824 | * It is the base class of all display objects that act as a container for other objects.
825 | */
826 | constructor();
827 |
828 |
829 | /**
830 | * [read-only] The array of children of this container.
831 | */
832 | children: DisplayObject[];
833 |
834 | /**
835 | * The height of the displayObjectContainer, setting this will actually modify the scale to achieve the value set
836 | */
837 | height: number;
838 |
839 | /**
840 | * The width of the displayObjectContainer, setting this will actually modify the scale to achieve the value set
841 | */
842 | width: number;
843 |
844 | /**
845 | * If `ignoreChildInput` is `false` it will allow this objects _children_ to be considered as valid for Input events.
846 | *
847 | * If this property is `true` then the children will _not_ be considered as valid for Input events.
848 | *
849 | * Note that this property isn't recursive: only immediate children are influenced, it doesn't scan further down.
850 | */
851 | ignoreChildInput: boolean;
852 |
853 |
854 | /**
855 | * Adds a child to the container.
856 | *
857 | * @param child The DisplayObject to add to the container
858 | * @return The child that was added.
859 | */
860 | addChild(child: DisplayObject): DisplayObject;
861 |
862 | /**
863 | * Adds a child to the container at a specified index. If the index is out of bounds an error will be thrown
864 | *
865 | * @param child The child to add
866 | * @param index The index to place the child in
867 | * @return The child that was added.
868 | */
869 | addChildAt(child: DisplayObject, index: number): DisplayObject;
870 |
871 | /**
872 | * Retrieves the global bounds of the displayObjectContainer as a rectangle. The bounds calculation takes all visible children into consideration.
873 | *
874 | * @param targetCoordinateSpace Returns a rectangle that defines the area of the display object relative to the coordinate system of the targetCoordinateSpace object.
875 | * @return The rectangular bounding area
876 | */
877 | getBounds(targetCoordinateSpace?: DisplayObject | Matrix): Rectangle;
878 |
879 | /**
880 | * Returns the child at the specified index
881 | *
882 | * @param index The index to get the child from
883 | * @return The child at the given index, if any.
884 | */
885 | getChildAt(index: number): DisplayObject;
886 |
887 | /**
888 | * Returns the index position of a child DisplayObject instance
889 | *
890 | * @param child The DisplayObject instance to identify
891 | * @return The index position of the child display object to identify
892 | */
893 | getChildIndex(child: DisplayObject): number;
894 |
895 | /**
896 | * Retrieves the non-global local bounds of the displayObjectContainer as a rectangle without any transformations. The calculation takes all visible children into consideration.
897 | * @return The rectangular bounding area
898 | */
899 | getLocalBounds(): Rectangle;
900 |
901 | /**
902 | * Removes a child from the container.
903 | *
904 | * @param child The DisplayObject to remove
905 | * @return The child that was removed.
906 | */
907 | removeChild(child: DisplayObject): DisplayObject;
908 |
909 | /**
910 | * Removes a child from the specified index position.
911 | *
912 | * @param index The index to get the child from
913 | * @return The child that was removed.
914 | */
915 | removeChildAt(index: number): DisplayObject;
916 |
917 | /**
918 | * Removes all children from this container that are within the begin and end indexes.
919 | *
920 | * @param beginIndex The beginning position. Default value is 0.
921 | * @param endIndex The ending position. Default value is size of the container.
922 | */
923 | removeChildren(beginIndex?: number, endIndex?: number): DisplayObject[];
924 | removeStageReference(): void;
925 |
926 | /**
927 | * Changes the position of an existing child in the display object container
928 | *
929 | * @param child The child DisplayObject instance for which you want to change the index number
930 | * @param index The resulting index number for the child display object
931 | */
932 | setChildIndex(child: DisplayObject, index: number): void;
933 |
934 | /**
935 | * Swaps the position of 2 Display Objects within this container.
936 | *
937 | * @param child
938 | * @param child2
939 | */
940 | swapChildren(child: DisplayObject, child2: DisplayObject): void;
941 |
942 | /**
943 | * Determines whether the specified display object is a child of the DisplayObjectContainer instance or the instance itself.
944 | *
945 | * @param child
946 | */
947 | contains(child: DisplayObject): boolean;
948 |
949 | }
950 |
951 | export class FilterTexture {
952 |
953 |
954 | /**
955 | *
956 | *
957 | * @param gl the current WebGL drawing context
958 | * @param width the horizontal range of the filter
959 | * @param height the vertical range of the filter
960 | * @param scaleMode See {{#crossLink "PIXI/scaleModes:property"}}PIXI.scaleModes{{/crossLink}} for possible values
961 | */
962 | constructor(gl: WebGLRenderingContext, width: number, height: number, scaleMode: scaleModes);
963 |
964 | fragmentSrc: string[];
965 | frameBuffer: WebGLFramebuffer;
966 | gl: WebGLRenderingContext;
967 | program: WebGLProgram;
968 | scaleMode: number;
969 | texture: WebGLTexture;
970 |
971 |
972 | /**
973 | * Clears the filter texture.
974 | */
975 | clear(): void;
976 |
977 | /**
978 | * Resizes the texture to the specified width and height
979 | *
980 | * @param width the new width of the texture
981 | * @param height the new height of the texture
982 | */
983 | resize(width: number, height: number): void;
984 |
985 | /**
986 | * Destroys the filter texture.
987 | */
988 | destroy(): void;
989 |
990 | }
991 |
992 | export class ImageLoader implements Mixin {
993 |
994 | constructor(url: string, crossorigin?: boolean);
995 |
996 | texture: Texture;
997 |
998 | listeners(eventName: string): Function[];
999 | emit(eventName: string, data?: any): boolean;
1000 | dispatchEvent(eventName: string, data?: any): boolean;
1001 | on(eventName: string, fn: Function): Function;
1002 | addEventListener(eventName: string, fn: Function): Function;
1003 | once(eventName: string, fn: Function): Function;
1004 | off(eventName: string, fn: Function): Function;
1005 | removeAllEventListeners(eventName: string): void;
1006 |
1007 | load(): void;
1008 | loadFramedSpriteSheet(frameWidth: number, frameHeight: number, textureName: string): void;
1009 |
1010 | }
1011 |
1012 | export class InteractionData {
1013 |
1014 | global: Point;
1015 | target: Sprite;
1016 | originalEvent: Event;
1017 |
1018 | getLocalPosition(displayObject: DisplayObject, point?: Point, globalPos?: Point): Point;
1019 |
1020 | }
1021 |
1022 | // Phaser.Matrix is used instead
1023 | export class Matrix {
1024 |
1025 | a: number;
1026 | b: number;
1027 | c: number;
1028 | d: number;
1029 | tx: number;
1030 | ty: number;
1031 |
1032 | append(matrix: Matrix): Matrix;
1033 | apply(pos: Point, newPos: Point): Point;
1034 | applyInverse(pos: Point, newPos: Point): Point;
1035 | determineMatrixArrayType(): number[];
1036 | identity(): Matrix;
1037 | rotate(angle: number): Matrix;
1038 | fromArray(array: number[]): void;
1039 | translate(x: number, y: number): Matrix;
1040 | toArray(transpose: boolean): number[];
1041 | scale(x: number, y: number): Matrix;
1042 |
1043 | }
1044 |
1045 | export interface Mixin {
1046 |
1047 | listeners(eventName: string): Function[];
1048 | emit(eventName: string, data?: any): boolean;
1049 | dispatchEvent(eventName: string, data?: any): boolean;
1050 | on(eventName: string, fn: Function): Function;
1051 | addEventListener(eventName: string, fn: Function): Function;
1052 | once(eventName: string, fn: Function): Function;
1053 | off(eventName: string, fn: Function): Function;
1054 | removeAllEventListeners(eventName: string): void;
1055 |
1056 | }
1057 |
1058 | export interface IPixiShader {
1059 |
1060 | fragmentSrc: string[];
1061 | gl: WebGLRenderingContext;
1062 | program: WebGLProgram;
1063 | vertexSrc: string[];
1064 |
1065 | destroy(): void;
1066 | init(): void;
1067 |
1068 | }
1069 |
1070 | export class PixiShader implements IPixiShader {
1071 |
1072 |
1073 | /**
1074 | *
1075 | *
1076 | * @param gl the current WebGL drawing context
1077 | */
1078 | constructor(gl: WebGLRenderingContext);
1079 |
1080 |
1081 | /**
1082 | * Uniform attributes cache.
1083 | */
1084 | attributes: ShaderAttribute[];
1085 |
1086 | /**
1087 | * The Default Vertex shader source.
1088 | */
1089 | defaultVertexSrc: string[];
1090 |
1091 | /**
1092 | * A dirty flag
1093 | */
1094 | dirty: boolean;
1095 |
1096 | /**
1097 | * A local flag
1098 | */
1099 | firstRun: boolean;
1100 |
1101 | /**
1102 | * A local texture counter for multi-texture shaders.
1103 | */
1104 | textureCount: number;
1105 |
1106 | /**
1107 | * The fragment shader.
1108 | */
1109 | fragmentSrc: string[];
1110 | gl: WebGLRenderingContext;
1111 |
1112 | /**
1113 | * The WebGL program.
1114 | */
1115 | program: WebGLProgram;
1116 | vertexSrc: string[];
1117 |
1118 |
1119 | /**
1120 | * Initialises a Sampler2D uniform (which may only be available later on after initUniforms once the texture has loaded)
1121 | */
1122 | initSampler2D(): void;
1123 |
1124 | /**
1125 | * Initialises the shader uniform values.
1126 | *
1127 | * Uniforms are specified in the GLSL_ES Specification: http://www.khronos.org/registry/webgl/specs/latest/1.0/
1128 | * http://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf
1129 | */
1130 | initUniforms(): void;
1131 |
1132 | /**
1133 | * Updates the shader uniform values.
1134 | */
1135 | syncUniforms(): void;
1136 |
1137 |
1138 | /**
1139 | * Destroys the shader.
1140 | */
1141 | destroy(): void;
1142 |
1143 | /**
1144 | * Initialises the shader.
1145 | */
1146 | init(): void;
1147 |
1148 | }
1149 |
1150 | export class PixiFastShader implements IPixiShader {
1151 |
1152 |
1153 | /**
1154 | *
1155 | *
1156 | * @param gl the current WebGL drawing context
1157 | */
1158 | constructor(gl: WebGLRenderingContext);
1159 |
1160 |
1161 | /**
1162 | * A local texture counter for multi-texture shaders.
1163 | */
1164 | textureCount: number;
1165 |
1166 | /**
1167 | * The fragment shader.
1168 | */
1169 | fragmentSrc: string[];
1170 | gl: WebGLRenderingContext;
1171 |
1172 | /**
1173 | * The WebGL program.
1174 | */
1175 | program: WebGLProgram;
1176 |
1177 | /**
1178 | * The vertex shader.
1179 | */
1180 | vertexSrc: string[];
1181 |
1182 |
1183 | /**
1184 | * Destroys the shader.
1185 | */
1186 | destroy(): void;
1187 |
1188 | /**
1189 | * Initialises the shader.
1190 | */
1191 | init(): void;
1192 |
1193 | }
1194 |
1195 | export class PrimitiveShader implements IPixiShader {
1196 |
1197 |
1198 | /**
1199 | *
1200 | *
1201 | * @param gl the current WebGL drawing context
1202 | */
1203 | constructor(gl: WebGLRenderingContext);
1204 |
1205 | /**
1206 | * The fragment shader.
1207 | */
1208 | fragmentSrc: string[];
1209 | gl: WebGLRenderingContext;
1210 |
1211 | /**
1212 | * The WebGL program.
1213 | */
1214 | program: WebGLProgram;
1215 |
1216 | /**
1217 | * The vertex shader.
1218 | */
1219 | vertexSrc: string[];
1220 |
1221 |
1222 | /**
1223 | * Destroys the shader.
1224 | */
1225 | destroy(): void;
1226 |
1227 | /**
1228 | * Initialises the shader.
1229 | */
1230 | init(): void;
1231 |
1232 | }
1233 |
1234 | export class ComplexPrimitiveShader implements IPixiShader {
1235 |
1236 |
1237 | /**
1238 | *
1239 | *
1240 | * @param gl the current WebGL drawing context
1241 | */
1242 | constructor(gl: WebGLRenderingContext);
1243 |
1244 | /**
1245 | * The fragment shader.
1246 | */
1247 | fragmentSrc: string[];
1248 | gl: WebGLRenderingContext;
1249 |
1250 | /**
1251 | * The WebGL program.
1252 | */
1253 | program: WebGLProgram;
1254 |
1255 | /**
1256 | * The vertex shader.
1257 | */
1258 | vertexSrc: string[];
1259 |
1260 |
1261 | /**
1262 | * Destroys the shader.
1263 | */
1264 | destroy(): void;
1265 |
1266 | /**
1267 | * Initialises the shader.
1268 | */
1269 | init(): void;
1270 |
1271 | }
1272 |
1273 | export class StripShader implements IPixiShader {
1274 |
1275 |
1276 | /**
1277 | *
1278 | *
1279 | * @param gl the current WebGL drawing context
1280 | */
1281 | constructor(gl: WebGLRenderingContext);
1282 |
1283 | /**
1284 | * The fragment shader.
1285 | */
1286 | fragmentSrc: string[];
1287 | gl: WebGLRenderingContext;
1288 |
1289 | /**
1290 | * The WebGL program.
1291 | */
1292 | program: WebGLProgram;
1293 |
1294 | /**
1295 | * The vertex shader.
1296 | */
1297 | vertexSrc: string[];
1298 |
1299 |
1300 | /**
1301 | * Destroys the shader.
1302 | */
1303 | destroy(): void;
1304 |
1305 | /**
1306 | * Initialises the shader.
1307 | */
1308 | init(): void;
1309 |
1310 | }
1311 |
1312 | // Overwritten by Phaser.Point
1313 | export class Point {
1314 |
1315 | constructor(x?: number, y?: number);
1316 |
1317 | x: number;
1318 | y: number;
1319 |
1320 | clone(): Point;
1321 | set(x: number, y: number): void;
1322 |
1323 | }
1324 |
1325 | // Overwritten by Phaser.Rectangle
1326 | export class Rectangle implements HitArea {
1327 |
1328 | constructor(x?: number, y?: number, width?: number, height?: number);
1329 |
1330 | bottom: number;
1331 | bottomRight: Phaser.Point;
1332 | bottomLeft: Phaser.Point;
1333 | centerX: number;
1334 | centerY: number;
1335 | empty: boolean;
1336 | halfHeight: number;
1337 | halfWidth: number;
1338 | height: number;
1339 | left: number;
1340 | perimeter: number;
1341 | randomX: number;
1342 | randomY: number;
1343 | right: number;
1344 | top: number;
1345 | topLeft: Phaser.Point;
1346 | topRight: Phaser.Point;
1347 | type: number;
1348 | volume: number;
1349 | width: number;
1350 | x: number;
1351 | y: number;
1352 |
1353 | clone(): Rectangle;
1354 | contains(x: number, y: number): boolean;
1355 |
1356 | }
1357 |
1358 | export class Rope extends Strip {
1359 |
1360 | points: Point[];
1361 | vertices: number[];
1362 |
1363 | constructor(texture: Texture, points: Point[]);
1364 |
1365 | refresh(): void;
1366 | setTexture(texture: Texture): void;
1367 |
1368 | }
1369 |
1370 |
1371 | /**
1372 | * The Sprite object is the base for all textured objects that are rendered to the screen
1373 | */
1374 | export class Sprite extends DisplayObjectContainer {
1375 |
1376 |
1377 | /**
1378 | * The Sprite object is the base for all textured objects that are rendered to the screen
1379 | *
1380 | * @param texture The texture for this sprite
1381 | */
1382 | constructor(texture: Texture);
1383 |
1384 |
1385 | /**
1386 | * The anchor sets the origin point of the texture.
1387 | * The default (0, 0) is the top left.
1388 | * (0.5, 0.5) is the center.
1389 | * (1, 1) is the bottom right.
1390 | *
1391 | * You can modify the default values in PIXI.Sprite.defaultAnchor.
1392 | */
1393 | anchor: Point;
1394 |
1395 | /**
1396 | * The blend mode to be applied to the sprite. Set to PIXI.blendModes.NORMAL to remove any blend mode.
1397 | *
1398 | * Warning: You cannot have a blend mode and a filter active on the same Sprite. Doing so will render the sprite invisible.
1399 | * Default: PIXI.blendModes.NORMAL;
1400 | */
1401 | blendMode: blendModes;
1402 |
1403 | /**
1404 | * Controls if this Sprite is processed by the core Phaser game loops and Group loops (except {@link Phaser.Group#update}).
1405 | * Default: true
1406 | */
1407 | exists: boolean;
1408 |
1409 | /**
1410 | * The shader that will be used to render this Sprite.
1411 | * Set to null to remove a current shader.
1412 | * Default: null
1413 | */
1414 | shader: IPixiShader;
1415 |
1416 | /**
1417 | * The texture that the sprite is using
1418 | */
1419 | texture: Texture;
1420 |
1421 | /**
1422 | * The tint applied to the sprite. This is a hex value. A value of 0xFFFFFF (Phaser.Color.WHITE) will remove any tint effect.
1423 | * Default: 0xFFFFFF
1424 | */
1425 | tint: number;
1426 |
1427 |
1428 | /**
1429 | * A Point-like object.
1430 | * Default: {"x":0,"y":0}
1431 | */
1432 |
1433 | /**
1434 | * The horizontal position of the DisplayObject, in pixels, relative to its parent.
1435 | * If you need the world position of the DisplayObject, use `DisplayObject.worldPosition` instead.
1436 | */
1437 |
1438 | /**
1439 | * The vertical position of the DisplayObject, in pixels, relative to its parent.
1440 | * If you need the world position of the DisplayObject, use `DisplayObject.worldPosition` instead.
1441 | */
1442 | static defaultAnchor: {x: number; y: number};
1443 |
1444 |
1445 | /**
1446 | * Sets the texture of the sprite. Be warned that this doesn't remove or destroy the previous
1447 | * texture this Sprite was using.
1448 | *
1449 | * @param texture The PIXI texture that is displayed by the sprite
1450 | * @param destroy Call Texture.destroy on the current texture before replacing it with the new one?
1451 | */
1452 | setTexture(texture: Texture, destroyBase?: boolean): void;
1453 |
1454 | }
1455 |
1456 | export class SpriteBatch extends DisplayObjectContainer {
1457 |
1458 | constructor(texture?: Texture);
1459 |
1460 | ready: boolean;
1461 | textureThing: Texture;
1462 |
1463 | initWebGL(gl: WebGLRenderingContext): void;
1464 |
1465 | }
1466 |
1467 | export class Strip extends DisplayObjectContainer {
1468 |
1469 | static DrawModes: {
1470 |
1471 | TRIANGLE_STRIP: number;
1472 | TRIANGLES: number;
1473 |
1474 | };
1475 |
1476 | constructor(texture: Texture);
1477 |
1478 | blendMode: number;
1479 | colors: number[];
1480 | dirty: boolean;
1481 | indices: number[];
1482 | canvasPadding: number;
1483 | texture: Texture;
1484 | uvs: number[];
1485 | vertices: number[];
1486 |
1487 | getBounds(matrix?: Matrix): Rectangle;
1488 |
1489 | }
1490 |
1491 |
1492 | /**
1493 | * A texture stores the information that represents an image or part of an image. It cannot be added
1494 | * to the display list directly. Instead use it as the texture for a PIXI.Sprite. If no frame is provided then the whole image is used.
1495 | */
1496 | export class Texture implements Mixin {
1497 |
1498 | static emptyTexture: Texture;
1499 |
1500 |
1501 | /**
1502 | * Helper function that creates a new a Texture based on the given canvas element.
1503 | *
1504 | * @param canvas The canvas element source of the texture
1505 | * @param scaleMode See {{#crossLink "PIXI/scaleModes:property"}}PIXI.scaleModes{{/crossLink}} for possible values
1506 | */
1507 | static fromCanvas(canvas: HTMLCanvasElement, scaleMode?: scaleModes): Texture;
1508 |
1509 |
1510 | /**
1511 | * A texture stores the information that represents an image or part of an image. It cannot be added
1512 | * to the display list directly. Instead use it as the texture for a PIXI.Sprite. If no frame is provided then the whole image is used.
1513 | *
1514 | * @param baseTexture The base texture source to create the texture from
1515 | * @param frame The rectangle frame of the texture to show
1516 | * @param crop The area of original texture
1517 | * @param trim Trimmed texture rectangle
1518 | */
1519 | constructor(baseTexture: BaseTexture, frame?: Rectangle, crop?: Rectangle, trim?: Rectangle);
1520 |
1521 |
1522 | /**
1523 | * The base texture that this texture uses.
1524 | */
1525 | baseTexture: BaseTexture;
1526 |
1527 | /**
1528 | * This is the area of the BaseTexture image to actually copy to the Canvas / WebGL when rendering,
1529 | * irrespective of the actual frame size or placement (which can be influenced by trimmed texture atlases)
1530 | */
1531 | crop: Rectangle;
1532 |
1533 | /**
1534 | * The frame specifies the region of the base texture that this texture uses
1535 | */
1536 | frame: Rectangle;
1537 |
1538 | /**
1539 | * The height of the Texture in pixels.
1540 | */
1541 | height: number;
1542 |
1543 | /**
1544 | * Does this Texture have any frame data assigned to it?
1545 | */
1546 | noFrame: boolean;
1547 |
1548 | /**
1549 | * This will let a renderer know that a texture has been updated (used mainly for webGL uv updates)
1550 | */
1551 | requiresUpdate: boolean;
1552 |
1553 | /**
1554 | * The texture trim data.
1555 | */
1556 | trim: Point;
1557 |
1558 | /**
1559 | * The width of the Texture in pixels.
1560 | */
1561 | width: number;
1562 | scope: any;
1563 |
1564 | /**
1565 | * This will let the renderer know if the texture is valid. If it's not then it cannot be rendered.
1566 | */
1567 | valid: boolean;
1568 |
1569 | /**
1570 | * A flag that controls if this frame is rotated or not.
1571 | * Rotation allows you to use rotated frames in texture atlas packing, it has nothing to do with
1572 | * Sprite rotation.
1573 | */
1574 | rotated: boolean;
1575 |
1576 | listeners(eventName: string): Function[];
1577 | emit(eventName: string, data?: any): boolean;
1578 | dispatchEvent(eventName: string, data?: any): boolean;
1579 | on(eventName: string, fn: Function): Function;
1580 | addEventListener(eventName: string, fn: Function): Function;
1581 | once(eventName: string, fn: Function): Function;
1582 | off(eventName: string, fn: Function): Function;
1583 | removeAllEventListeners(eventName: string): void;
1584 |
1585 |
1586 | /**
1587 | * Destroys this texture
1588 | *
1589 | * @param destroyBase Whether to destroy the base texture as well
1590 | */
1591 | destroy(destroyBase: boolean): void;
1592 |
1593 | /**
1594 | * Specifies the region of the baseTexture that this texture will use.
1595 | *
1596 | * @param frame The frame of the texture to set it to
1597 | */
1598 | setFrame(frame: Rectangle): void;
1599 |
1600 | }
1601 |
1602 | export class TilingSprite extends Sprite {
1603 |
1604 | constructor(texture: Texture, width: number, height: number);
1605 |
1606 | canvasBuffer: PIXI.CanvasBuffer;
1607 | blendMode: number;
1608 | refreshTexture: boolean;
1609 | texture: Texture;
1610 | textureDebug: boolean;
1611 | tint: number;
1612 | tilePosition: Point;
1613 | tilePattern: PIXI.Texture;
1614 | tileScale: Point;
1615 | tileScaleOffset: Point;
1616 |
1617 | destroy(): void;
1618 | generateTilingTexture(forcePowerOfTwo?: boolean): void;
1619 | setTexture(texture: Texture): void;
1620 |
1621 | }
1622 |
1623 | export class VideoTexture extends BaseTexture {
1624 |
1625 | static baseTextureFromVideo(video: HTMLVideoElement, scaleMode: number): BaseTexture;
1626 | static textureFromVideo(video: HTMLVideoElement, scaleMode: number): Texture;
1627 | static fromUrl(videoSrc: string, scaleMode?: number, autoPlay?: boolean, type?: string, loop?: boolean): Texture;
1628 |
1629 | controls: boolean;
1630 | autoUpdate: boolean;
1631 | type: string;
1632 |
1633 | changeSource(src: string, type: string, loop: boolean): void;
1634 | play(): void;
1635 | stop(): void;
1636 |
1637 | destroy(): void;
1638 | updateBound(): void;
1639 | onPlayStart: () => void;
1640 | onPlayStop: () => void;
1641 | onCanPlay: (event: any) => void;
1642 |
1643 | }
1644 |
1645 | export class WebGLBlendModeManager {
1646 |
1647 | currentBlendMode: number;
1648 |
1649 |
1650 | /**
1651 | * Destroys this object.
1652 | */
1653 | destroy(): void;
1654 |
1655 | /**
1656 | * Sets-up the given blendMode from WebGL's point of view.
1657 | *
1658 | * @param blendMode the blendMode, should be a Pixi const, such as PIXI.BlendModes.ADD
1659 | */
1660 | setBlendMode(blendMode: number): boolean;
1661 |
1662 | /**
1663 | * Sets the WebGL Context.
1664 | *
1665 | * @param gl the current WebGL drawing context
1666 | */
1667 | setContext(gl: WebGLRenderingContext): void;
1668 |
1669 | }
1670 |
1671 | export class WebGLFastSpriteBatch {
1672 |
1673 | constructor(gl: CanvasRenderingContext2D);
1674 |
1675 | currentBatchSize: number;
1676 | currentBaseTexture: BaseTexture;
1677 | currentBlendMode: number;
1678 | renderSession: RenderSession;
1679 | drawing: boolean;
1680 | indexBuffer: any;
1681 |
1682 | /**
1683 | * Index data
1684 | */
1685 | indices: number[];
1686 | lastIndexCount: number;
1687 | matrix: Matrix;
1688 | maxSize: number;
1689 | shader: IPixiShader;
1690 | size: number;
1691 | vertexBuffer: any;
1692 |
1693 | /**
1694 | * Vertex data
1695 | */
1696 | vertices: number[];
1697 | vertSize: number;
1698 |
1699 | end(): void;
1700 |
1701 | /**
1702 | *
1703 | *
1704 | * @param spriteBatch
1705 | * @param renderSession
1706 | */
1707 | begin(spriteBatch: SpriteBatch, renderSession: RenderSession): void;
1708 | destroy(removeView?: boolean): void;
1709 | flush(): void;
1710 |
1711 | /**
1712 | *
1713 | *
1714 | * @param spriteBatch
1715 | */
1716 | render(spriteBatch: SpriteBatch): void;
1717 |
1718 | /**
1719 | *
1720 | *
1721 | * @param sprite
1722 | */
1723 | renderSprite(sprite: Sprite): void;
1724 |
1725 | /**
1726 | * Sets the WebGL Context.
1727 | *
1728 | * @param gl the current WebGL drawing context
1729 | */
1730 | setContext(gl: WebGLRenderingContext): void;
1731 | start(): void;
1732 | stop(): void;
1733 |
1734 | }
1735 |
1736 | export class WebGLFilterManager {
1737 |
1738 | filterStack: AbstractFilter[];
1739 | transparent: boolean;
1740 | offsetX: number;
1741 | offsetY: number;
1742 |
1743 |
1744 | /**
1745 | * Applies the filter to the specified area.
1746 | *
1747 | * @param filter the filter that needs to be applied
1748 | * @param filterArea TODO - might need an update
1749 | * @param width the horizontal range of the filter
1750 | * @param height the vertical range of the filter
1751 | */
1752 | applyFilterPass(filter: AbstractFilter, filterArea: Texture, width: number, height: number): void;
1753 |
1754 | /**
1755 | *
1756 | *
1757 | * @param renderSession
1758 | * @param buffer
1759 | */
1760 | begin(renderSession: RenderSession, buffer: ArrayBuffer): void;
1761 |
1762 | /**
1763 | * Destroys the filter and removes it from the filter stack.
1764 | */
1765 | destroy(): void;
1766 |
1767 | /**
1768 | * Initialises the shader buffers.
1769 | */
1770 | initShaderBuffers(): void;
1771 |
1772 | /**
1773 | * Removes the last filter from the filter stack and doesn't return it.
1774 | */
1775 | popFilter(): void;
1776 |
1777 | /**
1778 | * Applies the filter and adds it to the current filter stack.
1779 | *
1780 | * @param filterBlock the filter that will be pushed to the current filter stack
1781 | */
1782 | pushFilter(filterBlock: FilterBlock): void;
1783 |
1784 | /**
1785 | * Initialises the context and the properties.
1786 | *
1787 | * @param gl the current WebGL drawing context
1788 | */
1789 | setContext(gl: WebGLRenderingContext): void;
1790 |
1791 | }
1792 |
1793 |
1794 | /**
1795 | * A set of functions used by the webGL renderer to draw the primitive graphics data
1796 | */
1797 | export class WebGLGraphics {
1798 |
1799 | static graphicsDataPool: any[];
1800 |
1801 |
1802 | /**
1803 | * Renders the graphics object
1804 | *
1805 | * @param graphics
1806 | * @param renderSession
1807 | */
1808 | static renderGraphics(graphics: Phaser.Graphics, renderRession: RenderSession): void;
1809 |
1810 | /**
1811 | * Updates the graphics object
1812 | *
1813 | * @param graphicsData The graphics object to update
1814 | * @param gl the current WebGL drawing context
1815 | */
1816 | static updateGraphics(graphics: Phaser.Graphics, gl: WebGLRenderingContext): void;
1817 |
1818 | /**
1819 | *
1820 | *
1821 | * @param webGL
1822 | * @param type
1823 | */
1824 | static switchMode(webGL: WebGLRenderingContext, type: number): any;
1825 |
1826 | /**
1827 | * Builds a rectangle to draw
1828 | *
1829 | * @param graphicsData The graphics object containing all the necessary properties
1830 | * @param webGLData
1831 | */
1832 | static buildRectangle(graphicsData: Phaser.GraphicsData, webGLData: any): void;
1833 |
1834 | /**
1835 | * Builds a rounded rectangle to draw
1836 | *
1837 | * @param graphicsData The graphics object containing all the necessary properties
1838 | * @param webGLData
1839 | */
1840 | static buildRoundedRectangle(graphicsData: Phaser.GraphicsData, webGLData: any): void;
1841 |
1842 | /**
1843 | * Calculate the points for a quadratic bezier curve. (helper function..)
1844 | * Based on: https://stackoverflow.com/questions/785097/how-do-i-implement-a-bezier-curve-in-c
1845 | *
1846 | * @param fromX Origin point x
1847 | * @param fromY Origin point x
1848 | * @param cpX Control point x
1849 | * @param cpY Control point y
1850 | * @param toX Destination point x
1851 | * @param toY Destination point y
1852 | */
1853 | static quadraticBezierCurve(fromX: number, fromY: number, cpX: number, cpY: number, toX: number, toY: number): number[];
1854 |
1855 | /**
1856 | * Builds a circle to draw
1857 | *
1858 | * @param graphicsData The graphics object to draw
1859 | * @param webGLData
1860 | */
1861 | static buildCircle(graphicsData: Phaser.GraphicsData, webGLData: any): void;
1862 |
1863 | /**
1864 | * Builds a line to draw
1865 | *
1866 | * @param graphicsData The graphics object containing all the necessary properties
1867 | * @param webGLData
1868 | */
1869 | static buildLine(graphicsData: Phaser.GraphicsData, webGLData: any): void;
1870 |
1871 | /**
1872 | * Builds a complex polygon to draw
1873 | *
1874 | * @param graphicsData The graphics object containing all the necessary properties
1875 | * @param webGLData
1876 | */
1877 | static buildComplexPoly(graphicsData: Phaser.GraphicsData, webGLData: any): void;
1878 |
1879 | /**
1880 | * Builds a polygon to draw
1881 | *
1882 | * @param graphicsData The graphics object containing all the necessary properties
1883 | * @param webGLData
1884 | */
1885 | static buildPoly(graphicsData: Phaser.GraphicsData, webGLData: any): boolean;
1886 |
1887 | reset(): void;
1888 | upload(): void;
1889 |
1890 | }
1891 |
1892 | export class WebGLGraphicsData {
1893 |
1894 | constructor(gl: WebGLRenderingContext);
1895 |
1896 | gl: WebGLRenderingContext;
1897 | glPoints: any[];
1898 | color: number[];
1899 | points: any[];
1900 | indices: any[];
1901 | buffer: WebGLBuffer;
1902 | indexBuffer: WebGLBuffer;
1903 | mode: number;
1904 | alpha: number;
1905 | dirty: boolean;
1906 |
1907 | reset(): void;
1908 | upload(): void;
1909 |
1910 | }
1911 |
1912 | export class WebGLMaskManager {
1913 |
1914 |
1915 | /**
1916 | * Destroys the mask stack.
1917 | */
1918 | destroy(): void;
1919 |
1920 | /**
1921 | * Removes the last filter from the filter stack and doesn't return it.
1922 | *
1923 | * @param maskData
1924 | * @param renderSession an object containing all the useful parameters
1925 | */
1926 | popMask(renderSession: RenderSession): void;
1927 |
1928 | /**
1929 | * Applies the Mask and adds it to the current filter stack.
1930 | *
1931 | * @param maskData
1932 | * @param renderSession
1933 | */
1934 | pushMask(maskData: any[], renderSession: RenderSession): void;
1935 |
1936 | /**
1937 | * Sets the drawing context to the one given in parameter.
1938 | *
1939 | * @param gl the current WebGL drawing context
1940 | */
1941 | setContext(gl: WebGLRenderingContext): void;
1942 |
1943 | }
1944 |
1945 |
1946 | /**
1947 | * The WebGLRenderer draws the stage and all its content onto a webGL enabled canvas. This renderer
1948 | * should be used for browsers that support webGL. This Render works by automatically managing webGLBatchs.
1949 | * So no need for Sprite Batches or Sprite Clouds.
1950 | * Don't forget to add the view to your DOM or you will not see anything :)
1951 | */
1952 | export class WebGLRenderer implements PixiRenderer {
1953 |
1954 | static createWebGLTexture(texture: Texture, gl: WebGLRenderingContext): void;
1955 |
1956 |
1957 | /**
1958 | * The WebGLRenderer draws the stage and all its content onto a webGL enabled canvas. This renderer
1959 | * should be used for browsers that support webGL. This Render works by automatically managing webGLBatchs.
1960 | * So no need for Sprite Batches or Sprite Clouds.
1961 | * Don't forget to add the view to your DOM or you will not see anything :)
1962 | *
1963 | * @param game A reference to the Phaser Game instance
1964 | */
1965 | constructor(game: Phaser.Game);
1966 |
1967 |
1968 | /**
1969 | * A reference to the Phaser Game instance.
1970 | */
1971 | game: Phaser.Game;
1972 | type: number;
1973 |
1974 | /**
1975 | * The resolution of the renderer
1976 | * Default: 1
1977 | */
1978 | resolution: number;
1979 |
1980 | /**
1981 | * Whether the render view is transparent
1982 | */
1983 | transparent: boolean;
1984 |
1985 | /**
1986 | * Whether the render view should be resized automatically
1987 | */
1988 | autoResize: boolean;
1989 |
1990 | /**
1991 | * The value of the preserveDrawingBuffer flag affects whether or not the contents of the stencil buffer is retained after rendering.
1992 | */
1993 | preserveDrawingBuffer: boolean;
1994 |
1995 | /**
1996 | * This sets if the WebGLRenderer will clear the context texture or not before the new render pass. If true:
1997 | * If the Stage is NOT transparent, Pixi will clear to alpha (0, 0, 0, 0).
1998 | * If the Stage is transparent, Pixi will clear to the target Stage's background color.
1999 | * Disable this by setting this to false. For example: if your game has a canvas filling background image, you often don't need this set.
2000 | */
2001 | clearBeforeRender: boolean;
2002 |
2003 | /**
2004 | * The width of the canvas view
2005 | */
2006 | width: number;
2007 |
2008 | /**
2009 | * The height of the canvas view
2010 | */
2011 | height: number;
2012 | currentBatchedTextures: string[];
2013 |
2014 | /**
2015 | * The canvas element that everything is drawn to
2016 | */
2017 | view: HTMLCanvasElement;
2018 | projection: Point;
2019 | offset: Point;
2020 |
2021 | /**
2022 | * Deals with managing the shader programs and their attribs
2023 | */
2024 | shaderManager: WebGLShaderManager;
2025 |
2026 | /**
2027 | * Manages the rendering of sprites
2028 | */
2029 | spriteBatch: WebGLSpriteBatch;
2030 |
2031 | /**
2032 | * Manages the masks using the stencil buffer
2033 | */
2034 | maskManager: WebGLMaskManager;
2035 |
2036 | /**
2037 | * Manages the filters
2038 | */
2039 | filterManager: WebGLFilterManager;
2040 |
2041 | /**
2042 | * Manages the stencil buffer
2043 | */
2044 | stencilManager: WebGLStencilManager;
2045 |
2046 | /**
2047 | * Manages the blendModes
2048 | */
2049 | blendModeManager: WebGLBlendModeManager;
2050 | renderSession: RenderSession;
2051 |
2052 | initContext(): void;
2053 |
2054 | /**
2055 | * Renders the stage to its webGL view
2056 | *
2057 | * @param stage the Stage element to be rendered
2058 | */
2059 | render(stage: DisplayObjectContainer): void;
2060 | postRender(): void;
2061 |
2062 | /**
2063 | * Renders a Display Object.
2064 | *
2065 | * @param displayObject The DisplayObject to render
2066 | * @param projection The projection
2067 | * @param buffer a standard WebGL buffer
2068 | */
2069 | renderDisplayObject(displayObject: DisplayObject, projection: Point, buffer: WebGLBuffer): void;
2070 |
2071 | /**
2072 | * Resizes the webGL view to the specified width and height.
2073 | *
2074 | * @param width the new width of the webGL view
2075 | * @param height the new height of the webGL view
2076 | */
2077 | resize(width: number, height: number): void;
2078 |
2079 | /**
2080 | * Updates and Creates a WebGL texture for the renderers context.
2081 | *
2082 | * @param texture the texture to update
2083 | * @return True if the texture was successfully bound, otherwise false.
2084 | */
2085 | updateTexture(texture: Texture): void;
2086 |
2087 | /**
2088 | * Removes everything from the renderer (event listeners, spritebatch, etc...)
2089 | */
2090 | destroy(): void;
2091 |
2092 | /**
2093 | * Maps Pixi blend modes to WebGL blend modes.
2094 | */
2095 | mapBlendModes(): void;
2096 |
2097 | /**
2098 | * If Multi Texture support has been enabled, then calling this method will enable batching on the given
2099 | * textures. The texture collection is an array of keys, that map to Phaser.Cache image entries.
2100 | *
2101 | * The number of textures that can be batched is dependent on hardware. If you provide more textures
2102 | * than can be batched by the GPU, then only those at the start of the array will be used. Generally
2103 | * you shouldn't provide more than 16 textures to this method. You can check the hardware limit via the
2104 | * `maxTextures` property.
2105 | *
2106 | * You can also check the property `currentBatchedTextures` at any time, to see which textures are currently
2107 | * being batched.
2108 | *
2109 | * To stop all textures from being batched, call this method again with an empty array.
2110 | *
2111 | * To change the textures being batched, call this method with a new array of image keys. The old ones
2112 | * will all be purged out and no-longer batched, and the new ones enabled.
2113 | *
2114 | * Note: Throws a warning if you haven't enabled Multiple Texture batching support in the Phaser Game config.
2115 | *
2116 | * @param textureNameCollection An Array of Texture Cache keys to use for multi-texture batching.
2117 | * @return An array containing the texture keys that were enabled for batching.
2118 | */
2119 | setTexturePriority(textureNameCollection: string[]): string[];
2120 |
2121 | }
2122 |
2123 | export class WebGLShaderManager {
2124 |
2125 | maxAttibs: number;
2126 | attribState: any[];
2127 | stack: any[];
2128 | tempAttribState: any[];
2129 |
2130 |
2131 | /**
2132 | * Destroys this object.
2133 | */
2134 | destroy(): void;
2135 |
2136 | /**
2137 | * Takes the attributes given in parameters.
2138 | *
2139 | * @param attribs attribs
2140 | */
2141 | setAttribs(attribs: ShaderAttribute[]): void;
2142 |
2143 | /**
2144 | * Initialises the context and the properties.
2145 | *
2146 | * @param gl the current WebGL drawing context
2147 | */
2148 | setContext(gl: WebGLRenderingContext): void;
2149 |
2150 | /**
2151 | * Sets the current shader.
2152 | *
2153 | * @param shader
2154 | */
2155 | setShader(shader: IPixiShader): boolean;
2156 |
2157 | }
2158 |
2159 | export class WebGLStencilManager {
2160 |
2161 | stencilStack: any[];
2162 | reverse: boolean;
2163 | count: number;
2164 |
2165 |
2166 | /**
2167 | * TODO this does not belong here!
2168 | *
2169 | * @param graphics
2170 | * @param webGLData
2171 | * @param renderSession
2172 | */
2173 | bindGraphics(graphics: Phaser.Graphics, webGLData: any[], renderSession: RenderSession): void;
2174 |
2175 | /**
2176 | * Destroys the mask stack.
2177 | */
2178 | destroy(): void;
2179 |
2180 | /**
2181 | *
2182 | *
2183 | * @param graphics
2184 | * @param webGLData
2185 | * @param renderSession
2186 | */
2187 | popStencil(graphics: Phaser.Graphics, webGLData: any[], renderSession: RenderSession): void;
2188 | pushStencil(graphics: Phaser.Graphics, webGLData: any[], renderSession: RenderSession): void;
2189 |
2190 | /**
2191 | * Sets the drawing context to the one given in parameter.
2192 | *
2193 | * @param gl the current WebGL drawing context
2194 | */
2195 | setContext(gl: WebGLRenderingContext): void;
2196 |
2197 | }
2198 |
2199 | export class WebGLSpriteBatch {
2200 |
2201 | blendModes: number[];
2202 |
2203 | /**
2204 | * View on the vertices as a Uint32Array
2205 | */
2206 | colors: number[];
2207 | currentBatchSize: number;
2208 | currentBaseTexture: Texture;
2209 | defaultShader: AbstractFilter;
2210 | dirty: boolean;
2211 | drawing: boolean;
2212 |
2213 | /**
2214 | * Holds the indices
2215 | */
2216 | indices: number[];
2217 | lastIndexCount: number;
2218 |
2219 | /**
2220 | * View on the vertices as a Float32Array
2221 | */
2222 | positions: number[];
2223 | textures: Texture[];
2224 | shaders: IPixiShader[];
2225 |
2226 | /**
2227 | * The number of images in the SpriteBatch before it flushes
2228 | */
2229 | size: number;
2230 | sprites: any[];
2231 |
2232 | /**
2233 | * Holds the vertices
2234 | */
2235 | vertices: number[];
2236 | vertSize: number;
2237 |
2238 |
2239 | /**
2240 | *
2241 | *
2242 | * @param renderSession The RenderSession object
2243 | */
2244 | begin(renderSession: RenderSession): void;
2245 |
2246 | /**
2247 | * Destroys the SpriteBatch.
2248 | */
2249 | destroy(): void;
2250 | end(): void;
2251 |
2252 | /**
2253 | * Renders the content and empties the current batch.
2254 | */
2255 | flush(shader?: IPixiShader): void;
2256 |
2257 | /**
2258 | *
2259 | *
2260 | * @param sprite the sprite to render when using this spritebatch
2261 | * @param matrix Optional matrix. If provided the Display Object will be rendered using this matrix, otherwise it will use its worldTransform.
2262 | */
2263 | render(sprite: Sprite): void;
2264 |
2265 | /**
2266 | *
2267 | *
2268 | * @param texture
2269 | * @param size
2270 | * @param startIndex
2271 | */
2272 | renderBatch(texture: Texture, size: number, startIndex: number): void;
2273 |
2274 | /**
2275 | * Renders a TilingSprite using the spriteBatch.
2276 | *
2277 | * @param sprite the sprite to render
2278 | */
2279 | renderTilingSprite(sprite: TilingSprite): void;
2280 | setBlendMode(blendMode: blendModes): void;
2281 |
2282 | /**
2283 | *
2284 | *
2285 | * @param gl the current WebGL drawing context
2286 | */
2287 | setContext(gl: WebGLRenderingContext): void;
2288 | start(): void;
2289 | stop(): void;
2290 |
2291 | }
2292 |
2293 | }
2294 |
2295 | declare function requestAnimFrame(callback: Function): void;
2296 |
2297 | declare module PIXI.PolyK {
2298 | export function Triangulate(p: number[]): number[];
2299 | }
2300 |
--------------------------------------------------------------------------------
/tsd/pixi.d.ts:
--------------------------------------------------------------------------------
1 | // Type definitions for PIXI with Phaser Deviations.
2 |
3 | declare module PIXI {
4 |
5 | export var game: Phaser.Game;
6 | export var WEBGL_RENDERER: number;
7 | export var CANVAS_RENDERER: number;
8 | export var VERSION: string;
9 |
10 | export enum blendModes {
11 |
12 | NORMAL,
13 | ADD,
14 | MULTIPLY,
15 | SCREEN,
16 | OVERLAY,
17 | DARKEN,
18 | LIGHTEN,
19 | COLOR_DODGE,
20 | COLOR_BURN,
21 | HARD_LIGHT,
22 | SOFT_LIGHT,
23 | DIFFERENCE,
24 | EXCLUSION,
25 | HUE,
26 | SATURATION,
27 | COLOR,
28 | LUMINOSITY
29 |
30 | }
31 |
32 | export enum scaleModes {
33 |
34 | DEFAULT,
35 | LINEAR,
36 | NEAREST
37 |
38 | }
39 |
40 | export var glContexts: WebGLRenderingContext[];
41 | export var instances: any[];
42 |
43 | export var TextureSilentFail: boolean;
44 |
45 | export function canUseNewCanvasBlendModes(): boolean;
46 |
47 | export function CompileFragmentShader(gl: WebGLRenderingContext, shaderSrc: string[]): any;
48 |
49 | export interface IEventCallback {
50 | (e?: IEvent): void;
51 | }
52 |
53 | export interface IEvent {
54 | type: string;
55 | content: any;
56 | }
57 |
58 | export interface HitArea {
59 | contains(x: number, y: number): boolean;
60 | }
61 |
62 | export interface IInteractionDataCallback {
63 | (interactionData: InteractionData): void;
64 | }
65 |
66 | export interface PixiRenderer {
67 |
68 | autoResize: boolean;
69 | clearBeforeRender: boolean;
70 | height: number;
71 | resolution: number;
72 | transparent: boolean;
73 | type: number;
74 | view: HTMLCanvasElement;
75 | width: number;
76 |
77 | destroy(): void;
78 | render(stage: DisplayObjectContainer): void;
79 | resize(width: number, height: number): void;
80 |
81 | }
82 |
83 | export interface PixiRendererOptions {
84 |
85 | autoResize?: boolean;
86 | antialias?: boolean;
87 | clearBeforeRender?: boolean;
88 | preserveDrawingBuffer?: boolean;
89 | resolution?: number;
90 | transparent?: boolean;
91 | view?: HTMLCanvasElement;
92 |
93 | }
94 |
95 | export interface BitmapTextStyle {
96 |
97 | font?: string;
98 | align?: string;
99 | tint?: string;
100 |
101 | }
102 |
103 | export interface TextStyle {
104 |
105 | align?: string;
106 | dropShadow?: boolean;
107 | dropShadowColor?: string;
108 | dropShadowAngle?: number;
109 | dropShadowDistance?: number;
110 | fill?: string;
111 | font?: string;
112 | lineJoin?: string;
113 | stroke?: string;
114 | strokeThickness?: number;
115 | wordWrap?: boolean;
116 | wordWrapWidth?: number;
117 |
118 | }
119 |
120 | export interface Loader {
121 |
122 | load(): void;
123 |
124 | }
125 |
126 | export interface MaskData {
127 |
128 | alpha: number;
129 | worldTransform: number[];
130 |
131 | }
132 |
133 | export interface RenderSession {
134 |
135 | context: CanvasRenderingContext2D;
136 | maskManager: CanvasMaskManager;
137 | scaleMode: scaleModes;
138 | smoothProperty: string;
139 | roundPixels: boolean;
140 |
141 | }
142 |
143 | export interface ShaderAttribute {
144 | // TODO: Find signature of shader attributes
145 | }
146 |
147 | export interface FilterBlock {
148 |
149 | visible: boolean;
150 | renderable: boolean;
151 |
152 | }
153 |
154 | // Phaser.Filter is used instead
155 | export class AbstractFilter {
156 |
157 | constructor(fragmentSrc: string | string[], uniforms: any);
158 |
159 | dirty: boolean;
160 | padding: number;
161 | uniforms: any;
162 | fragmentSrc: string | string[];
163 |
164 | apply(frameBuffer: WebGLFramebuffer): void;
165 | syncUniforms(): void;
166 |
167 | }
168 |
169 | export class BaseTexture implements Mixin {
170 |
171 | static fromCanvas(canvas: HTMLCanvasElement, scaleMode?: scaleModes): BaseTexture;
172 |
173 | constructor(source: HTMLCanvasElement | HTMLImageElement | HTMLVideoElement, scaleMode: scaleModes, resolution?: number);
174 |
175 | height: number;
176 | hasLoaded: boolean;
177 | mipmap: boolean;
178 | premultipliedAlpha: boolean;
179 | resolution: number;
180 | scaleMode: scaleModes;
181 | skipRender: boolean;
182 | source: HTMLCanvasElement | HTMLImageElement | HTMLVideoElement;
183 | textureIndex: number;
184 | width: number;
185 |
186 | _dirty: boolean[];
187 | _glTextures: WebGLTexture[];
188 |
189 | listeners(eventName: string): Function[];
190 | emit(eventName: string, data?: any): boolean;
191 | dispatchEvent(eventName: string, data?: any): boolean;
192 | on(eventName: string, fn: Function): Function;
193 | addEventListener(eventName: string, fn: Function): Function;
194 | once(eventName: string, fn: Function): Function;
195 | off(eventName: string, fn: Function): Function;
196 | removeAllEventListeners(eventName: string): void;
197 | forceLoaded(width: number, height: number): void;
198 | destroy(): void;
199 | dirty(): void;
200 | unloadFromGPU(): void;
201 |
202 | }
203 |
204 | export class CanvasBuffer {
205 |
206 | constructor(width: number, height: number);
207 |
208 | canvas: HTMLCanvasElement;
209 | context: CanvasRenderingContext2D;
210 | height: number;
211 | width: number;
212 |
213 | destroy(): void;
214 | clear(): void;
215 | resize(width: number, height: number): void;
216 |
217 | }
218 |
219 | export class CanvasMaskManager {
220 |
221 | pushMask(maskData: MaskData, renderSession: RenderSession): void;
222 | popMask(renderSession: RenderSession): void;
223 |
224 | }
225 |
226 | export class CanvasRenderer implements PixiRenderer {
227 |
228 | constructor(game: Phaser.Game);
229 |
230 | game: Phaser.Game;
231 | type: number;
232 | resolution: number;
233 | clearBeforeRender: boolean;
234 | transparent: boolean;
235 | autoResize: boolean;
236 | width: number;
237 | height: number;
238 | view: HTMLCanvasElement;
239 | context: CanvasRenderingContext2D;
240 | refresh: boolean;
241 | count: number;
242 | maskManager: CanvasMaskManager;
243 | renderSession: RenderSession;
244 |
245 | render(stage: DisplayObjectContainer): void;
246 | postRender(): void;
247 | resize(width: number, height: number): void;
248 | setTexturePriority(textureNameCollection: string[]): string[];
249 | destroy(removeView?: boolean): void;
250 |
251 | }
252 |
253 | export class CanvasTinter {
254 |
255 | static getTintedTexture(sprite: Sprite, color: number): HTMLCanvasElement;
256 | static tintWithMultiply(texture: Texture, color: number, canvas: HTMLCanvasElement): void;
257 | static tintWithOverlay(texture: Texture, color: number, canvas: HTMLCanvasElement): void;
258 | static tintWithPerPixel(texture: Texture, color: number, canvas: HTMLCanvasElement): void;
259 |
260 | static canUseMultiply: boolean;
261 | static tintMethod: any;
262 |
263 | }
264 |
265 | export class DisplayObject {
266 |
267 | alpha: number;
268 | buttonMode: boolean;
269 | cacheAsBitmap: boolean;
270 | defaultCursor: string;
271 | filterArea: Rectangle;
272 | filters: AbstractFilter[];
273 | hitArea: HitArea;
274 | interactive: boolean;
275 | mask: Phaser.Graphics;
276 | parent: DisplayObjectContainer;
277 | pivot: Point;
278 | position: Point;
279 | renderable: boolean;
280 | rotation: number;
281 | scale: Point;
282 | stage: DisplayObjectContainer;
283 | visible: boolean;
284 | worldAlpha: number;
285 | worldPosition: Point;
286 | worldScale: Point;
287 | worldTransform: Matrix;
288 | worldRotation: number;
289 | worldVisible: boolean;
290 | x: number;
291 | y: number;
292 |
293 | click(e: InteractionData): void;
294 | displayObjectUpdateTransform(parent?: DisplayObjectContainer): void;
295 | generateTexture(resolution?: number, scaleMode?: number, renderer?: PixiRenderer | number): Phaser.RenderTexture;
296 | mousedown(e: InteractionData): void;
297 | mouseout(e: InteractionData): void;
298 | mouseover(e: InteractionData): void;
299 | mouseup(e: InteractionData): void;
300 | mousemove(e: InteractionData): void;
301 | mouseupoutside(e: InteractionData): void;
302 | rightclick(e: InteractionData): void;
303 | rightdown(e: InteractionData): void;
304 | rightup(e: InteractionData): void;
305 | rightupoutside(e: InteractionData): void;
306 | setStageReference(stage: DisplayObjectContainer): void;
307 | tap(e: InteractionData): void;
308 | toGlobal(position: Point): Point;
309 | toLocal(position: Point, from: DisplayObject): Point;
310 | touchend(e: InteractionData): void;
311 | touchendoutside(e: InteractionData): void;
312 | touchstart(e: InteractionData): void;
313 | touchmove(e: InteractionData): void;
314 | updateTransform(parent?: DisplayObjectContainer): void;
315 | updateCache(): void;
316 |
317 | }
318 |
319 | export class DisplayObjectContainer extends DisplayObject {
320 |
321 | constructor();
322 |
323 | children: DisplayObject[];
324 | height: number;
325 | width: number;
326 | ignoreChildInput: boolean;
327 |
328 | addChild(child: DisplayObject): DisplayObject;
329 | addChildAt(child: DisplayObject, index: number): DisplayObject;
330 | getBounds(targetCoordinateSpace?: DisplayObject | Matrix): Rectangle;
331 | getChildAt(index: number): DisplayObject;
332 | getChildIndex(child: DisplayObject): number;
333 | getLocalBounds(): Rectangle;
334 | removeChild(child: DisplayObject): DisplayObject;
335 | removeChildAt(index: number): DisplayObject;
336 | removeChildren(beginIndex?: number, endIndex?: number): DisplayObject[];
337 | removeStageReference(): void;
338 | setChildIndex(child: DisplayObject, index: number): void;
339 | swapChildren(child: DisplayObject, child2: DisplayObject): void;
340 | contains(child: DisplayObject): boolean;
341 |
342 | }
343 |
344 | export class FilterTexture {
345 |
346 | constructor(gl: WebGLRenderingContext, width: number, height: number, scaleMode: scaleModes);
347 |
348 | fragmentSrc: string[];
349 | frameBuffer: WebGLFramebuffer;
350 | gl: WebGLRenderingContext;
351 | program: WebGLProgram;
352 | scaleMode: number;
353 | texture: WebGLTexture;
354 |
355 | clear(): void;
356 | resize(width: number, height: number): void;
357 | destroy(): void;
358 |
359 | }
360 |
361 | export class ImageLoader implements Mixin {
362 |
363 | constructor(url: string, crossorigin?: boolean);
364 |
365 | texture: Texture;
366 |
367 | listeners(eventName: string): Function[];
368 | emit(eventName: string, data?: any): boolean;
369 | dispatchEvent(eventName: string, data?: any): boolean;
370 | on(eventName: string, fn: Function): Function;
371 | addEventListener(eventName: string, fn: Function): Function;
372 | once(eventName: string, fn: Function): Function;
373 | off(eventName: string, fn: Function): Function;
374 | removeAllEventListeners(eventName: string): void;
375 |
376 | load(): void;
377 | loadFramedSpriteSheet(frameWidth: number, frameHeight: number, textureName: string): void;
378 |
379 | }
380 |
381 | export class InteractionData {
382 |
383 | global: Point;
384 | target: Sprite;
385 | originalEvent: Event;
386 |
387 | getLocalPosition(displayObject: DisplayObject, point?: Point, globalPos?: Point): Point;
388 |
389 | }
390 |
391 | // Phaser.Matrix is used instead
392 | export class Matrix {
393 |
394 | a: number;
395 | b: number;
396 | c: number;
397 | d: number;
398 | tx: number;
399 | ty: number;
400 |
401 | append(matrix: Matrix): Matrix;
402 | apply(pos: Point, newPos: Point): Point;
403 | applyInverse(pos: Point, newPos: Point): Point;
404 | determineMatrixArrayType(): number[];
405 | identity(): Matrix;
406 | rotate(angle: number): Matrix;
407 | fromArray(array: number[]): void;
408 | translate(x: number, y: number): Matrix;
409 | toArray(transpose: boolean): number[];
410 | scale(x: number, y: number): Matrix;
411 |
412 | }
413 |
414 | export interface Mixin {
415 |
416 | listeners(eventName: string): Function[];
417 | emit(eventName: string, data?: any): boolean;
418 | dispatchEvent(eventName: string, data?: any): boolean;
419 | on(eventName: string, fn: Function): Function;
420 | addEventListener(eventName: string, fn: Function): Function;
421 | once(eventName: string, fn: Function): Function;
422 | off(eventName: string, fn: Function): Function;
423 | removeAllEventListeners(eventName: string): void;
424 |
425 | }
426 |
427 | export interface IPixiShader {
428 |
429 | fragmentSrc: string[];
430 | gl: WebGLRenderingContext;
431 | program: WebGLProgram;
432 | vertexSrc: string[];
433 |
434 | destroy(): void;
435 | init(): void;
436 |
437 | }
438 |
439 | export class PixiShader implements IPixiShader {
440 |
441 | constructor(gl: WebGLRenderingContext);
442 |
443 | attributes: ShaderAttribute[];
444 | defaultVertexSrc: string[];
445 | dirty: boolean;
446 | firstRun: boolean;
447 | textureCount: number;
448 | fragmentSrc: string[];
449 | gl: WebGLRenderingContext;
450 | program: WebGLProgram;
451 | vertexSrc: string[];
452 |
453 | initSampler2D(): void;
454 | initUniforms(): void;
455 | syncUniforms(): void;
456 |
457 | destroy(): void;
458 | init(): void;
459 |
460 | }
461 |
462 | export class PixiFastShader implements IPixiShader {
463 |
464 | constructor(gl: WebGLRenderingContext);
465 |
466 | textureCount: number;
467 | fragmentSrc: string[];
468 | gl: WebGLRenderingContext;
469 | program: WebGLProgram;
470 | vertexSrc: string[];
471 |
472 | destroy(): void;
473 | init(): void;
474 |
475 | }
476 |
477 | export class PrimitiveShader implements IPixiShader {
478 |
479 | constructor(gl: WebGLRenderingContext);
480 | fragmentSrc: string[];
481 | gl: WebGLRenderingContext;
482 | program: WebGLProgram;
483 | vertexSrc: string[];
484 |
485 | destroy(): void;
486 | init(): void;
487 |
488 | }
489 |
490 | export class ComplexPrimitiveShader implements IPixiShader {
491 |
492 | constructor(gl: WebGLRenderingContext);
493 | fragmentSrc: string[];
494 | gl: WebGLRenderingContext;
495 | program: WebGLProgram;
496 | vertexSrc: string[];
497 |
498 | destroy(): void;
499 | init(): void;
500 |
501 | }
502 |
503 | export class StripShader implements IPixiShader {
504 |
505 | constructor(gl: WebGLRenderingContext);
506 | fragmentSrc: string[];
507 | gl: WebGLRenderingContext;
508 | program: WebGLProgram;
509 | vertexSrc: string[];
510 |
511 | destroy(): void;
512 | init(): void;
513 |
514 | }
515 |
516 | // Overwritten by Phaser.Point
517 | export class Point {
518 |
519 | constructor(x?: number, y?: number);
520 |
521 | x: number;
522 | y: number;
523 |
524 | clone(): Point;
525 | set(x: number, y: number): void;
526 |
527 | }
528 |
529 | // Overwritten by Phaser.Rectangle
530 | export class Rectangle implements HitArea {
531 |
532 | constructor(x?: number, y?: number, width?: number, height?: number);
533 |
534 | bottom: number;
535 | bottomRight: Phaser.Point;
536 | bottomLeft: Phaser.Point;
537 | centerX: number;
538 | centerY: number;
539 | empty: boolean;
540 | halfHeight: number;
541 | halfWidth: number;
542 | height: number;
543 | left: number;
544 | perimeter: number;
545 | randomX: number;
546 | randomY: number;
547 | right: number;
548 | top: number;
549 | topLeft: Phaser.Point;
550 | topRight: Phaser.Point;
551 | type: number;
552 | volume: number;
553 | width: number;
554 | x: number;
555 | y: number;
556 |
557 | clone(): Rectangle;
558 | contains(x: number, y: number): boolean;
559 |
560 | }
561 |
562 | export class Rope extends Strip {
563 |
564 | points: Point[];
565 | vertices: number[];
566 |
567 | constructor(texture: Texture, points: Point[]);
568 |
569 | refresh(): void;
570 | setTexture(texture: Texture): void;
571 |
572 | }
573 |
574 | export class Sprite extends DisplayObjectContainer {
575 |
576 | constructor(texture: Texture);
577 |
578 | anchor: Point;
579 | blendMode: blendModes;
580 | exists: boolean;
581 | shader: IPixiShader;
582 | texture: Texture;
583 | tint: number;
584 |
585 | static defaultAnchor: {x: number; y: number};
586 |
587 | setTexture(texture: Texture, destroyBase?: boolean): void;
588 |
589 | }
590 |
591 | export class SpriteBatch extends DisplayObjectContainer {
592 |
593 | constructor(texture?: Texture);
594 |
595 | ready: boolean;
596 | textureThing: Texture;
597 |
598 | initWebGL(gl: WebGLRenderingContext): void;
599 |
600 | }
601 |
602 | export class Strip extends DisplayObjectContainer {
603 |
604 | static DrawModes: {
605 |
606 | TRIANGLE_STRIP: number;
607 | TRIANGLES: number;
608 |
609 | };
610 |
611 | constructor(texture: Texture);
612 |
613 | blendMode: number;
614 | colors: number[];
615 | dirty: boolean;
616 | indices: number[];
617 | canvasPadding: number;
618 | texture: Texture;
619 | uvs: number[];
620 | vertices: number[];
621 |
622 | getBounds(matrix?: Matrix): Rectangle;
623 |
624 | }
625 |
626 | export class Texture implements Mixin {
627 |
628 | static emptyTexture: Texture;
629 |
630 | static fromCanvas(canvas: HTMLCanvasElement, scaleMode?: scaleModes): Texture;
631 |
632 | constructor(baseTexture: BaseTexture, frame?: Rectangle, crop?: Rectangle, trim?: Rectangle);
633 |
634 | baseTexture: BaseTexture;
635 | crop: Rectangle;
636 | frame: Rectangle;
637 | height: number;
638 | noFrame: boolean;
639 | requiresUpdate: boolean;
640 | trim: Point;
641 | width: number;
642 | scope: any;
643 | valid: boolean;
644 | rotated: boolean;
645 |
646 | listeners(eventName: string): Function[];
647 | emit(eventName: string, data?: any): boolean;
648 | dispatchEvent(eventName: string, data?: any): boolean;
649 | on(eventName: string, fn: Function): Function;
650 | addEventListener(eventName: string, fn: Function): Function;
651 | once(eventName: string, fn: Function): Function;
652 | off(eventName: string, fn: Function): Function;
653 | removeAllEventListeners(eventName: string): void;
654 |
655 | destroy(destroyBase: boolean): void;
656 | setFrame(frame: Rectangle): void;
657 |
658 | }
659 |
660 | export class TilingSprite extends Sprite {
661 |
662 | constructor(texture: Texture, width: number, height: number);
663 |
664 | canvasBuffer: PIXI.CanvasBuffer;
665 | blendMode: number;
666 | refreshTexture: boolean;
667 | texture: Texture;
668 | textureDebug: boolean;
669 | tint: number;
670 | tilePosition: Point;
671 | tilePattern: PIXI.Texture;
672 | tileScale: Point;
673 | tileScaleOffset: Point;
674 |
675 | destroy(): void;
676 | generateTilingTexture(forcePowerOfTwo?: boolean): void;
677 | setTexture(texture: Texture): void;
678 |
679 | }
680 |
681 | export class VideoTexture extends BaseTexture {
682 |
683 | static baseTextureFromVideo(video: HTMLVideoElement, scaleMode: number): BaseTexture;
684 | static textureFromVideo(video: HTMLVideoElement, scaleMode: number): Texture;
685 | static fromUrl(videoSrc: string, scaleMode?: number, autoPlay?: boolean, type?: string, loop?: boolean): Texture;
686 |
687 | controls: boolean;
688 | autoUpdate: boolean;
689 | type: string;
690 |
691 | changeSource(src: string, type: string, loop: boolean): void;
692 | play(): void;
693 | stop(): void;
694 |
695 | destroy(): void;
696 | updateBound(): void;
697 | onPlayStart: () => void;
698 | onPlayStop: () => void;
699 | onCanPlay: (event: any) => void;
700 |
701 | }
702 |
703 | export class WebGLBlendModeManager {
704 |
705 | currentBlendMode: number;
706 |
707 | destroy(): void;
708 | setBlendMode(blendMode: number): boolean;
709 | setContext(gl: WebGLRenderingContext): void;
710 |
711 | }
712 |
713 | export class WebGLFastSpriteBatch {
714 |
715 | constructor(gl: CanvasRenderingContext2D);
716 |
717 | currentBatchSize: number;
718 | currentBaseTexture: BaseTexture;
719 | currentBlendMode: number;
720 | renderSession: RenderSession;
721 | drawing: boolean;
722 | indexBuffer: any;
723 | indices: number[];
724 | lastIndexCount: number;
725 | matrix: Matrix;
726 | maxSize: number;
727 | shader: IPixiShader;
728 | size: number;
729 | vertexBuffer: any;
730 | vertices: number[];
731 | vertSize: number;
732 |
733 | end(): void;
734 | begin(spriteBatch: SpriteBatch, renderSession: RenderSession): void;
735 | destroy(removeView?: boolean): void;
736 | flush(): void;
737 | render(spriteBatch: SpriteBatch): void;
738 | renderSprite(sprite: Sprite): void;
739 | setContext(gl: WebGLRenderingContext): void;
740 | start(): void;
741 | stop(): void;
742 |
743 | }
744 |
745 | export class WebGLFilterManager {
746 |
747 | filterStack: AbstractFilter[];
748 | transparent: boolean;
749 | offsetX: number;
750 | offsetY: number;
751 |
752 | applyFilterPass(filter: AbstractFilter, filterArea: Texture, width: number, height: number): void;
753 | begin(renderSession: RenderSession, buffer: ArrayBuffer): void;
754 | destroy(): void;
755 | initShaderBuffers(): void;
756 | popFilter(): void;
757 | pushFilter(filterBlock: FilterBlock): void;
758 | setContext(gl: WebGLRenderingContext): void;
759 |
760 | }
761 |
762 | export class WebGLGraphics {
763 |
764 | static graphicsDataPool: any[];
765 |
766 | static renderGraphics(graphics: Phaser.Graphics, renderRession: RenderSession): void;
767 | static updateGraphics(graphics: Phaser.Graphics, gl: WebGLRenderingContext): void;
768 | static switchMode(webGL: WebGLRenderingContext, type: number): any;
769 | static buildRectangle(graphicsData: Phaser.GraphicsData, webGLData: any): void;
770 | static buildRoundedRectangle(graphicsData: Phaser.GraphicsData, webGLData: any): void;
771 | static quadraticBezierCurve(fromX: number, fromY: number, cpX: number, cpY: number, toX: number, toY: number): number[];
772 | static buildCircle(graphicsData: Phaser.GraphicsData, webGLData: any): void;
773 | static buildLine(graphicsData: Phaser.GraphicsData, webGLData: any): void;
774 | static buildComplexPoly(graphicsData: Phaser.GraphicsData, webGLData: any): void;
775 | static buildPoly(graphicsData: Phaser.GraphicsData, webGLData: any): boolean;
776 |
777 | reset(): void;
778 | upload(): void;
779 |
780 | }
781 |
782 | export class WebGLGraphicsData {
783 |
784 | constructor(gl: WebGLRenderingContext);
785 |
786 | gl: WebGLRenderingContext;
787 | glPoints: any[];
788 | color: number[];
789 | points: any[];
790 | indices: any[];
791 | buffer: WebGLBuffer;
792 | indexBuffer: WebGLBuffer;
793 | mode: number;
794 | alpha: number;
795 | dirty: boolean;
796 |
797 | reset(): void;
798 | upload(): void;
799 |
800 | }
801 |
802 | export class WebGLMaskManager {
803 |
804 | destroy(): void;
805 | popMask(renderSession: RenderSession): void;
806 | pushMask(maskData: any[], renderSession: RenderSession): void;
807 | setContext(gl: WebGLRenderingContext): void;
808 |
809 | }
810 |
811 | export class WebGLRenderer implements PixiRenderer {
812 |
813 | static createWebGLTexture(texture: Texture, gl: WebGLRenderingContext): void;
814 |
815 | constructor(game: Phaser.Game);
816 |
817 | game: Phaser.Game;
818 | type: number;
819 | resolution: number;
820 | transparent: boolean;
821 | autoResize: boolean;
822 | preserveDrawingBuffer: boolean;
823 | clearBeforeRender: boolean;
824 | width: number;
825 | height: number;
826 | currentBatchedTextures: string[];
827 | view: HTMLCanvasElement;
828 | projection: Point;
829 | offset: Point;
830 | shaderManager: WebGLShaderManager;
831 | spriteBatch: WebGLSpriteBatch;
832 | maskManager: WebGLMaskManager;
833 | filterManager: WebGLFilterManager;
834 | stencilManager: WebGLStencilManager;
835 | blendModeManager: WebGLBlendModeManager;
836 | renderSession: RenderSession;
837 |
838 | initContext(): void;
839 | render(stage: DisplayObjectContainer): void;
840 | postRender(): void;
841 | renderDisplayObject(displayObject: DisplayObject, projection: Point, buffer: WebGLBuffer): void;
842 | resize(width: number, height: number): void;
843 | updateTexture(texture: Texture): void;
844 | destroy(): void;
845 | mapBlendModes(): void;
846 | setTexturePriority(textureNameCollection: string[]): string[];
847 |
848 | }
849 |
850 | export class WebGLShaderManager {
851 |
852 | maxAttibs: number;
853 | attribState: any[];
854 | stack: any[];
855 | tempAttribState: any[];
856 |
857 | destroy(): void;
858 | setAttribs(attribs: ShaderAttribute[]): void;
859 | setContext(gl: WebGLRenderingContext): void;
860 | setShader(shader: IPixiShader): boolean;
861 |
862 | }
863 |
864 | export class WebGLStencilManager {
865 |
866 | stencilStack: any[];
867 | reverse: boolean;
868 | count: number;
869 |
870 | bindGraphics(graphics: Phaser.Graphics, webGLData: any[], renderSession: RenderSession): void;
871 | destroy(): void;
872 | popStencil(graphics: Phaser.Graphics, webGLData: any[], renderSession: RenderSession): void;
873 | pushStencil(graphics: Phaser.Graphics, webGLData: any[], renderSession: RenderSession): void;
874 | setContext(gl: WebGLRenderingContext): void;
875 |
876 | }
877 |
878 | export class WebGLSpriteBatch {
879 |
880 | blendModes: number[];
881 | colors: number[];
882 | currentBatchSize: number;
883 | currentBaseTexture: Texture;
884 | defaultShader: AbstractFilter;
885 | dirty: boolean;
886 | drawing: boolean;
887 | indices: number[];
888 | lastIndexCount: number;
889 | positions: number[];
890 | textures: Texture[];
891 | shaders: IPixiShader[];
892 | size: number;
893 | sprites: any[];
894 | vertices: number[];
895 | vertSize: number;
896 |
897 | begin(renderSession: RenderSession): void;
898 | destroy(): void;
899 | end(): void;
900 | flush(shader?: IPixiShader): void;
901 | render(sprite: Sprite): void;
902 | renderBatch(texture: Texture, size: number, startIndex: number): void;
903 | renderTilingSprite(sprite: TilingSprite): void;
904 | setBlendMode(blendMode: blendModes): void;
905 | setContext(gl: WebGLRenderingContext): void;
906 | start(): void;
907 | stop(): void;
908 |
909 | }
910 |
911 | }
912 |
913 | declare function requestAnimFrame(callback: Function): void;
914 |
915 | declare module PIXI.PolyK {
916 | export function Triangulate(p: number[]): number[];
917 | }
918 |
--------------------------------------------------------------------------------
/update_phaser.bat:
--------------------------------------------------------------------------------
1 | curl -k ^
2 | -o bin/js/phaser.js https://raw.githubusercontent.com/photonstorm/phaser-ce/master/build/phaser.js ^
3 | -o bin/js/phaser.map https://raw.githubusercontent.com/photonstorm/phaser-ce/master/build/phaser.map ^
4 | -o bin/js/phaser.min.js https://raw.githubusercontent.com/photonstorm/phaser-ce/master/build/phaser.min.js ^
5 | -o tsd/box2d.d.ts https://raw.githubusercontent.com/photonstorm/phaser-ce/master/typescript/box2d.d.ts ^
6 | -o tsd/p2.d.ts https://raw.githubusercontent.com/photonstorm/phaser-ce/master/typescript/p2.d.ts ^
7 | -o tsd/phaser.comments.d.ts https://raw.githubusercontent.com/photonstorm/phaser-ce/master/typescript/phaser.comments.d.ts ^
8 | -o tsd/phaser.d.ts https://raw.githubusercontent.com/photonstorm/phaser-ce/master/typescript/phaser.d.ts ^
9 | -o tsd/phaser_box2d.d.ts https://raw.githubusercontent.com/photonstorm/phaser-ce/master/typescript/phaser_box2d.d.ts ^
10 | -o tsd/pixi.comments.d.ts https://raw.githubusercontent.com/photonstorm/phaser-ce/master/typescript/pixi.comments.d.ts ^
11 | -o tsd/pixi.d.ts https://raw.githubusercontent.com/photonstorm/phaser-ce/master/typescript/pixi.d.ts
12 |
--------------------------------------------------------------------------------
/update_phaser.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | curl -k \
3 | -o bin/js/phaser.js https://raw.githubusercontent.com/photonstorm/phaser-ce/master/build/phaser.js \
4 | -o bin/js/phaser.map https://raw.githubusercontent.com/photonstorm/phaser-ce/master/build/phaser.map \
5 | -o bin/js/phaser.min.js https://raw.githubusercontent.com/photonstorm/phaser-ce/master/build/phaser.min.js \
6 | -o tsd/box2d.d.ts https://raw.githubusercontent.com/photonstorm/phaser-ce/master/typescript/box2d.d.ts \
7 | -o tsd/p2.d.ts https://raw.githubusercontent.com/photonstorm/phaser-ce/master/typescript/p2.d.ts \
8 | -o tsd/phaser.comments.d.ts https://raw.githubusercontent.com/photonstorm/phaser-ce/master/typescript/phaser.comments.d.ts \
9 | -o tsd/phaser.d.ts https://raw.githubusercontent.com/photonstorm/phaser-ce/master/typescript/phaser.d.ts \
10 | -o tsd/phaser_box2d.d.ts https://raw.githubusercontent.com/photonstorm/phaser-ce/master/typescript/phaser_box2d.d.ts \
11 | -o tsd/pixi.comments.d.ts https://raw.githubusercontent.com/photonstorm/phaser-ce/master/typescript/pixi.comments.d.ts \
12 | -o tsd/pixi.d.ts https://raw.githubusercontent.com/photonstorm/phaser-ce/master/typescript/pixi.d.ts
--------------------------------------------------------------------------------