├── src ├── fonts │ └── .gitkeep ├── audio │ ├── sounds │ │ └── .gitkeep │ └── music │ │ └── play.mp3 ├── images │ ├── logo.png │ ├── favicon.png │ ├── level_1.png │ ├── loader.png │ ├── menu_background.jpg │ ├── spritesheet │ │ └── player.png │ └── misc │ │ └── gamepad_indicator.png ├── css │ └── game.css ├── js │ ├── Properties.js │ ├── states │ │ ├── GameState.js │ │ ├── MainMenuState.js │ │ ├── BootState.js │ │ └── PreloaderState.js │ ├── Main.js │ └── prefabs │ │ └── Player.js └── index.html ├── .babelrc ├── toolkit ├── project-templates │ └── empty │ │ ├── fonts │ │ └── .gitkeep │ │ ├── audio │ │ ├── music │ │ │ └── .gitkeep │ │ └── sounds │ │ │ └── .gitkeep │ │ ├── images │ │ ├── misc │ │ │ └── .gitkeep │ │ └── spritesheet │ │ │ └── .gitkeep │ │ ├── js │ │ ├── prefabs │ │ │ └── .gitkeep │ │ ├── Properties.js │ │ ├── states │ │ │ ├── MainMenuState.js │ │ │ ├── GameState.js │ │ │ ├── PreloaderState.js │ │ │ └── BootState.js │ │ └── Main.js │ │ ├── css │ │ └── game.css │ │ └── index.html └── vscode-intellisense │ ├── jsconfig.json │ └── defs │ ├── p2.d.ts │ └── pixi.d.ts ├── gulpfile.js ├── postcss.config.js ├── webpack ├── config.js ├── dev.config.js ├── prod.config.js └── core.config.js ├── gulp ├── index.js ├── tasks │ ├── deploy.js │ ├── project-templates.js │ └── vscode-intellisense.js └── paths.js ├── CONTRIBUTING.md ├── .editorconfig ├── LICENSE ├── package.json ├── .eslintrc.json ├── README.md └── .gitignore /src/fonts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/audio/sounds/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015"] 3 | } 4 | -------------------------------------------------------------------------------- /toolkit/project-templates/empty/fonts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /toolkit/vscode-intellisense/jsconfig.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /toolkit/project-templates/empty/audio/music/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /toolkit/project-templates/empty/audio/sounds/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /toolkit/project-templates/empty/images/misc/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /toolkit/project-templates/empty/js/prefabs/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('./gulp'); 4 | -------------------------------------------------------------------------------- /toolkit/project-templates/empty/images/spritesheet/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = {}; 4 | -------------------------------------------------------------------------------- /src/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brenopolanski/phaser-es6-starter/HEAD/src/images/logo.png -------------------------------------------------------------------------------- /src/images/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brenopolanski/phaser-es6-starter/HEAD/src/images/favicon.png -------------------------------------------------------------------------------- /src/images/level_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brenopolanski/phaser-es6-starter/HEAD/src/images/level_1.png -------------------------------------------------------------------------------- /src/images/loader.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brenopolanski/phaser-es6-starter/HEAD/src/images/loader.png -------------------------------------------------------------------------------- /src/audio/music/play.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brenopolanski/phaser-es6-starter/HEAD/src/audio/music/play.mp3 -------------------------------------------------------------------------------- /src/css/game.css: -------------------------------------------------------------------------------- 1 | html, 2 | body { 3 | display: block; 4 | margin: 0; 5 | padding: 0; 6 | background: #000; 7 | } 8 | -------------------------------------------------------------------------------- /src/images/menu_background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brenopolanski/phaser-es6-starter/HEAD/src/images/menu_background.jpg -------------------------------------------------------------------------------- /src/images/spritesheet/player.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brenopolanski/phaser-es6-starter/HEAD/src/images/spritesheet/player.png -------------------------------------------------------------------------------- /src/images/misc/gamepad_indicator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brenopolanski/phaser-es6-starter/HEAD/src/images/misc/gamepad_indicator.png -------------------------------------------------------------------------------- /webpack/config.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | title: 'Phaser ES6 Starter', 5 | host: 'localhost', 6 | port: 3000 7 | }; 8 | -------------------------------------------------------------------------------- /toolkit/project-templates/empty/css/game.css: -------------------------------------------------------------------------------- 1 | html, 2 | body { 3 | display: block; 4 | margin: 0; 5 | padding: 0; 6 | background: #000; 7 | } 8 | -------------------------------------------------------------------------------- /toolkit/project-templates/empty/js/Properties.js: -------------------------------------------------------------------------------- 1 | // Game properties. 2 | export default { 3 | gameWidth: 800, 4 | gameHeight: 600, 5 | localStorageName: 'phaser_es6_starter' 6 | }; 7 | -------------------------------------------------------------------------------- /src/js/Properties.js: -------------------------------------------------------------------------------- 1 | // Game properties. 2 | export default { 3 | gameWidth: 800, 4 | gameHeight: 600, 5 | fontFamily: ['Press Start 2P'], 6 | localStorageName: 'phaser_es6_starter', 7 | showStats: true, 8 | showDebugSpriteInfo: true 9 | }; 10 | -------------------------------------------------------------------------------- /gulp/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const gulp = require('gulp'); 4 | const fs = require('fs'); 5 | const path = require('path'); 6 | const tasks = fs.readdirSync('./gulp/tasks'); 7 | 8 | tasks.forEach((task) => { 9 | require(path.join(__dirname, 'tasks', task)); 10 | }); 11 | -------------------------------------------------------------------------------- /gulp/tasks/deploy.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Necessary plugins. 4 | const gulp = require('gulp'); 5 | const ghPages = require('gulp-gh-pages'); 6 | const paths = require('../paths'); 7 | 8 | // Deploy to GitHub pages. 9 | module.exports = gulp.task('deploy', () => { 10 | return gulp.src(paths.deploy.pages) 11 | .pipe(ghPages()); 12 | }); 13 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | 1. Fork it! 4 | 2. Create your feature branch: `git checkout -b my-new-feature` 5 | 3. Commit your changes: `git commit -m "Add some feature"` 6 | 4. Push to the branch: `git push origin my-new-feature` 7 | 5. Submit a pull request :) 8 | 9 | English is the universal language nowadays, so please don't create or comment on issues using another language. 10 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # http://editorconfig.org 4 | 5 | root = true 6 | 7 | [*] 8 | indent_style = space 9 | indent_size = 2 10 | end_of_line = lf 11 | charset = utf-8 12 | trim_trailing_whitespace = true 13 | insert_final_newline = true 14 | max_line_length = 80 15 | 16 | [*.md] 17 | trim_trailing_whitespace = false 18 | -------------------------------------------------------------------------------- /toolkit/project-templates/empty/js/states/MainMenuState.js: -------------------------------------------------------------------------------- 1 | import Phaser from 'phaser'; 2 | 3 | class MainMenuState extends Phaser.State { 4 | init() { 5 | // Honestly, just about anything could go here. 6 | // It's YOUR game after all. Eat your heart out! 7 | } 8 | 9 | create() { 10 | // Honestly, just about anything could go here. 11 | // It's YOUR game after all. Eat your heart out! 12 | } 13 | } 14 | 15 | export default MainMenuState; 16 | -------------------------------------------------------------------------------- /toolkit/project-templates/empty/js/states/GameState.js: -------------------------------------------------------------------------------- 1 | import Phaser from 'phaser'; 2 | 3 | class GameState extends Phaser.State { 4 | init() { 5 | // Honestly, just about anything could go here. 6 | // It's YOUR game after all. Eat your heart out! 7 | } 8 | 9 | create() { 10 | // Honestly, just about anything could go here. 11 | // It's YOUR game after all. Eat your heart out! 12 | } 13 | 14 | render() { 15 | // Honestly, just about anything could go here. 16 | // It's YOUR game after all. Eat your heart out! 17 | } 18 | } 19 | 20 | export default GameState; 21 | -------------------------------------------------------------------------------- /toolkit/project-templates/empty/js/states/PreloaderState.js: -------------------------------------------------------------------------------- 1 | import Phaser from 'phaser'; 2 | 3 | class PreloaderState extends Phaser.State { 4 | init() { 5 | // Honestly, just about anything could go here. 6 | // It's YOUR game after all. Eat your heart out! 7 | } 8 | 9 | preload() { 10 | // Honestly, just about anything could go here. 11 | // It's YOUR game after all. Eat your heart out! 12 | } 13 | 14 | create() { 15 | // Honestly, just about anything could go here. 16 | // It's YOUR game after all. Eat your heart out! 17 | } 18 | } 19 | 20 | export default PreloaderState; 21 | -------------------------------------------------------------------------------- /gulp/tasks/project-templates.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Necessary Plugins. 4 | const gulp = require('gulp'); 5 | const plumber = require('gulp-plumber'); 6 | const del = require('del'); 7 | const paths = require('../paths'); 8 | 9 | // Clear the `src/` folder. 10 | gulp.task('clean:src', () => { 11 | return del(paths.srcRoot); 12 | }); 13 | 14 | // Call to create an empty game project template in `src/` folder. 15 | gulp.task('empty', ['clean:src'], () => { 16 | gulp.src(paths.toolkit.projectTemplates.empty.files.copy) 17 | .pipe(plumber()) 18 | .pipe(gulp.dest(paths.toolkit.projectTemplates.empty.files.to)); 19 | }); 20 | 21 | module.exports = gulp.task('template:empty', ['clean:src', 'empty']); 22 | -------------------------------------------------------------------------------- /webpack/dev.config.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const webpack = require('webpack'); 4 | const merge = require('webpack-merge'); 5 | const BrowserSyncPlugin = require('browser-sync-webpack-plugin'); 6 | const core = require('./core.config'); 7 | const config = require('./config'); 8 | 9 | const definePlugin = new webpack.DefinePlugin({ 10 | __DEV__: JSON.stringify(JSON.parse(process.env.BUILD_DEV || 'true')) 11 | }); 12 | 13 | module.exports = merge.smart(core, { 14 | devtool: 'cheap-source-map', 15 | output: { 16 | pathinfo: true, 17 | publicPath: '' 18 | }, 19 | watch: true, 20 | plugins: [ 21 | definePlugin, 22 | new BrowserSyncPlugin({ 23 | host: process.env.IP || config.host, 24 | port: process.env.PORT || config.port, 25 | server: { 26 | baseDir: ['./game/'] 27 | } 28 | }) 29 | ] 30 | }); 31 | -------------------------------------------------------------------------------- /gulp/paths.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | srcRoot: './src/**/*', 5 | 6 | toolkit: { 7 | vscodeIntellisense: { 8 | files: { 9 | copy: { 10 | nodeDir: [ 11 | './node_modules/phaser-ce/typescript/p2.d.ts', 12 | './node_modules/phaser-ce/typescript/phaser.comments.d.ts', 13 | './node_modules/phaser-ce/typescript/pixi.d.ts' 14 | ], 15 | jsConfig: './toolkit/vscode-intellisense/jsconfig.json', 16 | default: './toolkit/vscode-intellisense/**/*' 17 | }, 18 | to: './src/js/' 19 | } 20 | }, 21 | projectTemplates: { 22 | empty: { 23 | files: { 24 | copy: './toolkit/project-templates/empty/**/*', 25 | to: './src/' 26 | } 27 | } 28 | } 29 | }, 30 | 31 | deploy: { 32 | pages: './game/**/*' 33 | } 34 | }; 35 | -------------------------------------------------------------------------------- /webpack/prod.config.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const webpack = require('webpack'); 4 | const FaviconsWebpackPlugin = require('favicons-webpack-plugin'); 5 | const merge = require('webpack-merge'); 6 | const core = require('./core.config'); 7 | const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); 8 | 9 | const definePlugin = new webpack.DefinePlugin({ 10 | __DEV__: JSON.stringify(JSON.parse(process.env.BUILD_DEV || 'false')) 11 | }); 12 | 13 | module.exports = merge.smart(core, { 14 | plugins: [ 15 | definePlugin, 16 | new FaviconsWebpackPlugin('./src/images/favicon.png'), 17 | new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/), 18 | new webpack.optimize.UglifyJsPlugin({ 19 | compress: true, 20 | drop_console: true, 21 | minimize: true, 22 | output: { 23 | comments: false 24 | } 25 | }) 26 | ].concat( 27 | process.env.ANALYZER ? new BundleAnalyzerPlugin() : [] 28 | ) 29 | }); 30 | -------------------------------------------------------------------------------- /toolkit/project-templates/empty/js/Main.js: -------------------------------------------------------------------------------- 1 | import 'pixi'; 2 | import 'p2'; 3 | import Phaser from 'phaser'; 4 | import '../css/game.css'; 5 | 6 | import Properties from './Properties'; 7 | import BootState from './states/BootState'; 8 | import PreloaderState from './states/PreloaderState'; 9 | import MainMenuState from './states/MainMenuState'; 10 | import GameState from './states/GameState'; 11 | 12 | class Game extends Phaser.Game { 13 | constructor() { 14 | const { 15 | gameWidth, 16 | gameHeight, 17 | showStats 18 | } = Properties; 19 | 20 | // Create your Phaser game and inject it into the `#game-container` div. 21 | super(gameWidth, gameHeight, Phaser.CANVAS, 'game-container'); 22 | 23 | // Add the States your game has. 24 | this.state.add('BootState', BootState); 25 | this.state.add('PreloaderState', PreloaderState); 26 | this.state.add('MainMenuState', MainMenuState); 27 | this.state.add('GameState', GameState); 28 | 29 | // Now start the Boot state. 30 | this.state.start('BootState'); 31 | } 32 | } 33 | 34 | window.game = new Game(); 35 | -------------------------------------------------------------------------------- /gulp/tasks/vscode-intellisense.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Necessary Plugins. 4 | const gulp = require('gulp'); 5 | const plumber = require('gulp-plumber'); 6 | const { resolve } = require('path'); 7 | const pathExists = require('path-exists'); 8 | const paths = require('../paths'); 9 | 10 | const NODE_DIR = resolve(__dirname, '../../node_modules/'); 11 | 12 | // Call VSCode Intellisense for Phaser. 13 | module.exports = gulp.task('vscode', () => { 14 | pathExists(NODE_DIR).then(exists => { 15 | if (exists) { 16 | gulp.src(paths.toolkit.vscodeIntellisense.files.copy.nodeDir) 17 | .pipe(plumber()) 18 | .pipe(gulp.dest(`${paths.toolkit.vscodeIntellisense.files.to}/defs/`)); 19 | gulp.src(paths.toolkit.vscodeIntellisense.files.copy.jsConfig) 20 | .pipe(plumber()) 21 | .pipe(gulp.dest(paths.toolkit.vscodeIntellisense.files.to)); 22 | } 23 | else { 24 | return gulp.src(paths.toolkit.vscodeIntellisense.files.copy.default) 25 | .pipe(plumber()) 26 | .pipe(gulp.dest(paths.toolkit.vscodeIntellisense.files.to)); 27 | } 28 | }); 29 | }); 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Breno Polanski 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 | -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | <%= htmlWebpackPlugin.options.title %> 11 | 12 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /toolkit/project-templates/empty/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | <%= htmlWebpackPlugin.options.title %> 11 | 12 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/js/states/GameState.js: -------------------------------------------------------------------------------- 1 | import Phaser from 'phaser'; 2 | 3 | import Properties from '../Properties'; 4 | import Player from '../prefabs/Player'; 5 | 6 | /** 7 | * Setup and display the main game state. 8 | */ 9 | class GameState extends Phaser.State { 10 | /** 11 | * Setup variables or objects before the preloading starts. 12 | */ 13 | init() { 14 | this.background = null; 15 | this.music = null; 16 | this.player = null; 17 | } 18 | 19 | /** 20 | * Add background to level 1, external font, music and player Simon. 21 | */ 22 | create() { 23 | this.backgroundLevel1 = this.add.sprite(0, 0, 'level1'); 24 | 25 | const { fontFamily } = Properties; 26 | const levelText = 'Level 1'; 27 | const text = this.add.text(this.game.width - 120, 15, levelText); 28 | 29 | text.font = fontFamily[0]; 30 | text.fontSize = 15; 31 | text.fill = '#fff'; 32 | text.align = 'center'; 33 | 34 | this.music = this.add.audio('music', 1, false); 35 | this.music.play(); 36 | 37 | this.player = new Player(this.game, 130, 284); 38 | } 39 | 40 | /** 41 | * Show the debug sprite info. 42 | */ 43 | render() { 44 | const { showDebugSpriteInfo } = Properties; 45 | 46 | // Handle debug mode. 47 | if (__DEV__ && showDebugSpriteInfo) { 48 | this.game.debug.spriteInfo(this.player, 35, 500); 49 | } 50 | } 51 | } 52 | 53 | export default GameState; 54 | -------------------------------------------------------------------------------- /toolkit/project-templates/empty/js/states/BootState.js: -------------------------------------------------------------------------------- 1 | import Phaser from 'phaser'; 2 | 3 | import Properties from '../Properties'; 4 | 5 | class BootState extends Phaser.State { 6 | init() { 7 | // Unless you specifically know your game needs to support 8 | // multi-touch, I would recommend setting this to 1. 9 | this.input.maxPointers = 1; 10 | 11 | // Phaser will automatically pause if the browser tab the game 12 | // is in loses focus. You can disable that here: 13 | this.stage.disableVisibilityChange = true; 14 | 15 | if (this.game.device.desktop) { 16 | // If you have any desktop specific settings, they can go in here: 17 | this.scale.pageAlignHorizontally = true; 18 | } 19 | else { 20 | const { gameWidth, gameHeight } = Properties; 21 | 22 | // Same goes for mobile settings. 23 | // In this case we're saying scale the game, 24 | // no lower than 480x260 and no higher than 800x600. 25 | this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; 26 | this.scale.setMinMax(480, 260, gameWidth, gameHeight); 27 | this.scale.forceLandscape = true; 28 | this.scale.pageAlignHorizontally = true; 29 | } 30 | } 31 | 32 | preload() { 33 | // Honestly, just about anything could go here. 34 | // It's YOUR game after all. Eat your heart out! 35 | } 36 | 37 | create() { 38 | // Honestly, just about anything could go here. 39 | // It's YOUR game after all. Eat your heart out! 40 | } 41 | } 42 | 43 | export default BootState; 44 | -------------------------------------------------------------------------------- /src/js/states/MainMenuState.js: -------------------------------------------------------------------------------- 1 | import Phaser from 'phaser'; 2 | 3 | /** 4 | * Show menu background and logo. 5 | */ 6 | class MainMenuState extends Phaser.State { 7 | /** 8 | * Setup variables or objects before the preloading starts. 9 | */ 10 | init() { 11 | this.background = null; 12 | this.logo = null; 13 | } 14 | 15 | /** 16 | * A couple of Sprites, tweens to make them appear. Then the game waits 17 | * for an input event before fading out and starting the Game class. 18 | */ 19 | create() { 20 | this.background = this.add.sprite(0, 0, 'menuBackground'); 21 | this.background.alpha = 0; 22 | 23 | this.logo = this.add.sprite(this.world.centerX, -300, 'logo'); 24 | this.logo.anchor.setTo(0.5, 0.5); 25 | 26 | this.add.tween(this.background).to( 27 | { alpha: 1 }, 2000, Phaser.Easing.Bounce.InOut, true 28 | ); 29 | 30 | this.add.tween(this.logo).to( 31 | { y: 220 }, 2000, Phaser.Easing.Elastic.Out, true, 2000 32 | ); 33 | 34 | this.input.onDown.addOnce(this.fadeOut, this); 35 | } 36 | 37 | /** 38 | * Hide background and move logo. 39 | */ 40 | fadeOut() { 41 | const tween = this.add.tween(this.logo).to( 42 | { y: 800 }, 2000, Phaser.Easing.Linear.None, true 43 | ); 44 | 45 | this.add.tween(this.background).to( 46 | { alpha: 0 }, 2000, Phaser.Easing.Linear.None, true 47 | ); 48 | 49 | tween.onComplete.add(this.startGame, this); 50 | } 51 | 52 | /** 53 | * Move on to the game state. 54 | */ 55 | startGame() { 56 | this.state.start('GameState'); 57 | } 58 | } 59 | 60 | export default MainMenuState; 61 | -------------------------------------------------------------------------------- /src/js/Main.js: -------------------------------------------------------------------------------- 1 | import 'pixi'; 2 | import 'p2'; 3 | import Phaser from 'phaser'; 4 | import Stats from 'stats.js'; 5 | import '../css/game.css'; 6 | 7 | import Properties from './Properties'; 8 | import BootState from './states/BootState'; 9 | import PreloaderState from './states/PreloaderState'; 10 | import MainMenuState from './states/MainMenuState'; 11 | import GameState from './states/GameState'; 12 | 13 | /** 14 | * Setup the root class for the whole game. 15 | */ 16 | class Game extends Phaser.Game { 17 | constructor() { 18 | const { 19 | gameWidth, 20 | gameHeight, 21 | showStats 22 | } = Properties; 23 | 24 | // Create your Phaser game and inject it into the `#game-container` div. 25 | super(gameWidth, gameHeight, Phaser.CANVAS, 'game-container'); 26 | 27 | // Add the States your game has. 28 | this.state.add('BootState', BootState); 29 | this.state.add('PreloaderState', PreloaderState); 30 | this.state.add('MainMenuState', MainMenuState); 31 | this.state.add('GameState', GameState); 32 | 33 | // Now start the Boot state. 34 | this.state.start('BootState'); 35 | 36 | // Handle debug mode. 37 | if (__DEV__ && showStats) { 38 | this.setupStats(); 39 | } 40 | } 41 | 42 | /** 43 | * Display the FPS and MS using Stats.js. 44 | */ 45 | setupStats() { 46 | // Setup the new stats panel. 47 | const stats = new Stats(); 48 | 49 | document.body.appendChild(stats.dom); 50 | 51 | // Monkey-patch the update loop so we can track the timing. 52 | const updateLoop = this.update; 53 | 54 | this.update = (...args) => { 55 | stats.begin(); 56 | updateLoop.apply(this, args); 57 | stats.end(); 58 | }; 59 | } 60 | } 61 | 62 | window.game = new Game(); 63 | -------------------------------------------------------------------------------- /src/js/states/BootState.js: -------------------------------------------------------------------------------- 1 | import Phaser from 'phaser'; 2 | 3 | import Properties from '../Properties'; 4 | import preloadBar from '../../images/loader.png'; 5 | 6 | /** 7 | * Setup the pre-game boot sequence. 8 | */ 9 | class BootState extends Phaser.State { 10 | /** 11 | * Setup variables or objects before the preloading starts. 12 | */ 13 | init() { 14 | // Unless you specifically know your game needs to support 15 | // multi-touch, I would recommend setting this to 1. 16 | this.input.maxPointers = 1; 17 | 18 | // Phaser will automatically pause if the browser tab the game 19 | // is in loses focus. You can disable that here: 20 | this.stage.disableVisibilityChange = true; 21 | 22 | if (this.game.device.desktop) { 23 | // If you have any desktop specific settings, they can go in here: 24 | this.scale.pageAlignHorizontally = true; 25 | } 26 | else { 27 | const { gameWidth, gameHeight } = Properties; 28 | 29 | // Same goes for mobile settings. 30 | // In this case we're saying scale the game, 31 | // no lower than 480x260 and no higher than 800x600. 32 | this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; 33 | this.scale.setMinMax(480, 260, gameWidth, gameHeight); 34 | this.scale.forceLandscape = true; 35 | this.scale.pageAlignHorizontally = true; 36 | } 37 | } 38 | 39 | /** 40 | * Preload any assets needed for the preload state. 41 | */ 42 | preload() { 43 | // Here we load the assets required for our preloader 44 | // (in this case a background and a loading bar). 45 | this.load.image('preloadBar', preloadBar); 46 | } 47 | 48 | /** 49 | * Setup anything that is needed before the preload state begins. 50 | */ 51 | create() { 52 | // By this point the preloader assets have loaded to the cache, 53 | // we've set the game settings. 54 | // So now let's start the real preloader going. 55 | this.state.start('PreloaderState'); 56 | } 57 | } 58 | 59 | export default BootState; 60 | -------------------------------------------------------------------------------- /src/js/states/PreloaderState.js: -------------------------------------------------------------------------------- 1 | import Phaser from 'phaser'; 2 | import WebFont from 'webfontloader'; 3 | 4 | import Properties from '../Properties'; 5 | import menuBackground from '../../images/menu_background.jpg'; 6 | import logo from '../../images/logo.png'; 7 | import level1 from '../../images/level_1.png'; 8 | import gamepadIndicator from '../../images/misc/gamepad_indicator.png'; 9 | import player from '../../images/spritesheet/player.png'; 10 | import music from '../../audio/music/play.mp3'; 11 | 12 | /** 13 | * Preload the game and display the loading screen. 14 | */ 15 | class PreloaderState extends Phaser.State { 16 | /** 17 | * Setup variables or objects before the preloading starts. 18 | */ 19 | init() { 20 | this.preloadBar = null; 21 | } 22 | 23 | /** 24 | * Preload any assets needed for the main menu state. 25 | */ 26 | preload() { 27 | const { fontFamily } = Properties; 28 | 29 | // Setup our preloader sprite. 30 | this.preloadBar = this.add.sprite(200, 250, 'preloadBar'); 31 | this.load.setPreloadSprite(this.preloadBar); 32 | 33 | // Load our actual games assets. 34 | this.load.image('menuBackground', menuBackground); 35 | this.load.image('logo', logo); 36 | this.load.audio('music', music, true); 37 | this.load.spritesheet('gamepadIndicator', gamepadIndicator, 16, 16); 38 | this.load.spritesheet('player', player, 58, 96, 5); 39 | this.load.image('level1', level1); 40 | 41 | // Load external font. 42 | WebFont.load({ 43 | google: { 44 | families: fontFamily 45 | } 46 | }); 47 | } 48 | 49 | /** 50 | * When the load is finished the create function is called, 51 | * which is when we fade the preload bar away. 52 | * On completion of that tween we start the main menu. 53 | */ 54 | create() { 55 | const tween = this.add.tween(this.preloadBar).to( 56 | { alpha: 0 }, 1000, Phaser.Easing.Linear.None, true 57 | ); 58 | 59 | tween.onComplete.add(this.startMainMenuState, this); 60 | } 61 | 62 | /** 63 | * Move on to the main menu state. 64 | */ 65 | startMainMenuState() { 66 | this.state.start('MainMenuState'); 67 | } 68 | } 69 | 70 | export default PreloaderState; 71 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "phaser-es6-starter", 3 | "description": "A template for writing Phaser Games based ECMAScript 2015 (ES6) + Webpack + Progressive Web Apps and more.", 4 | "homepage": "https://github.com/brenopolanski/phaser-es6-starter#readme", 5 | "version": "0.1.0", 6 | "author": { 7 | "name": "Breno Polanski", 8 | "email": "breno.polanski@gmail.com", 9 | "web": "http://brenopolanski.com", 10 | "twitter": "@brenopolanski" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/brenopolanski/phaser-es6-starter.git" 15 | }, 16 | "license": "MIT", 17 | "keywords": [ 18 | "phaser", 19 | "phaser-boilerplate", 20 | "phaser-es6-webpack", 21 | "game", 22 | "webpack", 23 | "html5", 24 | "canvas", 25 | "javascript" 26 | ], 27 | "bugs": { 28 | "url": "https://github.com/brenopolanski/phaser-es6-starter/issues" 29 | }, 30 | "scripts": { 31 | "start": "yarn clean:folder && yarn dev", 32 | "dev": "webpack --display-error-details --config ./webpack/dev.config", 33 | "build": "yarn clean:folder && yarn build:webpack", 34 | "build:webpack": "cross-env NODE_ENV=production BABEL_ENV=production webpack --progress --config ./webpack/prod.config -p", 35 | "build:analyzer": "cross-env ANALYZER=true yarn build", 36 | "clean:folder": "rimraf game" 37 | }, 38 | "dependencies": { 39 | "phaser-ce": "^2.8.4", 40 | "webfontloader": "^1.6.28" 41 | }, 42 | "devDependencies": { 43 | "autoprefixer": "^7.1.2", 44 | "babel-core": "^6.26.0", 45 | "babel-eslint": "^7.2.3", 46 | "babel-loader": "^7.1.2", 47 | "babel-polyfill": "^6.26.0", 48 | "babel-preset-es2015": "^6.24.1", 49 | "browser-sync": "^2.18.13", 50 | "browser-sync-webpack-plugin": "^1.2.0", 51 | "cross-env": "^5.0.5", 52 | "css-loader": "^0.28.5", 53 | "del": "^3.0.0", 54 | "eslint": "^4.5.0", 55 | "eslint-loader": "^1.9.0", 56 | "expose-loader": "^0.7.3", 57 | "favicons-webpack-plugin": "0.0.7", 58 | "file-loader": "^0.11.2", 59 | "gulp": "^3.9.1", 60 | "gulp-gh-pages": "^0.5.4", 61 | "gulp-plumber": "^1.1.0", 62 | "html-webpack-plugin": "^2.30.1", 63 | "json-loader": "^0.5.7", 64 | "path-exists": "^3.0.0", 65 | "postcss-loader": "^2.0.6", 66 | "rimraf": "^2.6.1", 67 | "stats.js": "^0.17.0", 68 | "style-loader": "^0.18.2", 69 | "url-loader": "^0.5.9", 70 | "webpack": "^3.5.5", 71 | "webpack-bundle-analyzer": "^2.9.0", 72 | "webpack-merge": "^4.1.0" 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/js/prefabs/Player.js: -------------------------------------------------------------------------------- 1 | import Phaser from 'phaser'; 2 | 3 | /** 4 | * Setup and control base player. 5 | */ 6 | class Player extends Phaser.Sprite { 7 | constructor(game, x, y) { 8 | super(game, x, y, 'player', 0); 9 | 10 | this.anchor.setTo(0.5, 0); 11 | 12 | this.animations.add('walk', [0, 1, 2, 3, 4], 10, true); 13 | 14 | game.add.existing(this); 15 | 16 | game.physics.enable(this, Phaser.Physics.ARCADE); 17 | 18 | game.input.gamepad.start(); 19 | 20 | this.gamepadIndicator = game.add.sprite(10, 10, 'gamepadIndicator'); 21 | this.gamepadIndicator.scale.x = 2; 22 | this.gamepadIndicator.scale.y = 2; 23 | this.gamepadIndicator.animations.frame = 1; 24 | 25 | // Setup a Phaser controller for keyboard input. 26 | this.cursors = game.input.keyboard.createCursorKeys(); 27 | 28 | // Setup a Phaser controller for gamepad input. 29 | // To listen to buttons from a specific pad listen directly on 30 | // that pad game.input.gamepad.padX, where X = pad 1-4. 31 | this.gamePad1 = game.input.gamepad.pad1; 32 | } 33 | 34 | /** 35 | * Handle actions in the main game loop. 36 | */ 37 | update() { 38 | this.body.velocity.x = 0; 39 | 40 | // Gamepad "connected or not" indicator. 41 | if (this.game.input.gamepad.supported && 42 | this.game.input.gamepad.active && 43 | this.gamePad1.connected) { 44 | 45 | this.gamepadIndicator.animations.frame = 0; 46 | 47 | // Gamepad controls. 48 | if (this.gamePad1.isDown(Phaser.Gamepad.XBOX360_DPAD_LEFT) || 49 | this.gamePad1.axis(Phaser.Gamepad.XBOX360_STICK_LEFT_X) < -0.1) { 50 | 51 | this.walkToLeft(); 52 | } 53 | else if (this.gamePad1.isDown(Phaser.Gamepad.XBOX360_DPAD_RIGHT) || 54 | this.gamePad1.axis(Phaser.Gamepad.XBOX360_STICK_LEFT_X) > 0.1) { 55 | 56 | this.walkToRight(); 57 | } 58 | else { 59 | this.animations.frame = 0; 60 | } 61 | } 62 | else { 63 | this.gamepadIndicator.animations.frame = 1; 64 | 65 | // Keyboard controls. 66 | if (this.cursors.left.isDown) { 67 | this.walkToLeft(); 68 | } 69 | else if (this.cursors.right.isDown) { 70 | this.walkToRight(); 71 | } 72 | else { 73 | this.animations.frame = 0; 74 | } 75 | } 76 | } 77 | 78 | /** 79 | * Player moves left. 80 | */ 81 | walkToLeft() { 82 | this.body.velocity.x = -150; 83 | this.animations.play('walk'); 84 | 85 | if (this.scale.x === 1) { 86 | this.scale.x = -1; 87 | } 88 | } 89 | 90 | /** 91 | * Player moves right. 92 | */ 93 | walkToRight() { 94 | this.body.velocity.x = 150; 95 | this.animations.play('walk'); 96 | 97 | if (this.scale.x === -1) { 98 | this.scale.x = 1; 99 | } 100 | } 101 | } 102 | 103 | export default Player; 104 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "es6": true, 5 | "commonjs": true 6 | }, 7 | "parserOptions": { 8 | "sourceType": "module" 9 | }, 10 | "extends": "eslint:recommended", 11 | "globals": { 12 | "Phaser": true, 13 | "PIXI": true, 14 | "p2": true, 15 | "__DEV__": true 16 | }, 17 | "rules": { 18 | "no-cond-assign": ["error", "except-parens"], 19 | "no-duplicate-case": ["error"], 20 | "accessor-pairs": "error", 21 | "curly": "error", 22 | "eqeqeq": ["error", "smart"], 23 | "no-alert": "error", 24 | "no-caller": "error", 25 | "no-console": ["error", { "allow": ["warn", "log"] }], 26 | "no-floating-decimal": "error", 27 | "no-invalid-this": "error", 28 | "no-multi-spaces": "error", 29 | "no-multi-str": "error", 30 | "no-new-func": "error", 31 | "no-new-wrappers": "error", 32 | "no-redeclare": "error", 33 | "no-self-assign": "error", 34 | "no-self-compare": "error", 35 | "yoda": [ "error", "never" ], 36 | "array-bracket-spacing": ["error", "never", { "objectsInArrays": false }], 37 | "block-spacing": ["error", "always"], 38 | "brace-style": ["error", "stroustrup"], 39 | "camelcase": "error", 40 | "comma-dangle": ["error", "never"], 41 | "comma-style": ["error", "last"], 42 | "computed-property-spacing": ["error", "never"], 43 | "consistent-this": ["error", "_this"], 44 | "eol-last": ["error"], 45 | "func-call-spacing": ["error", "never"], 46 | "indent": ["error", 2, { "SwitchCase": 1 }], 47 | "key-spacing": ["error", { "beforeColon": false, "afterColon": true }], 48 | "linebreak-style": ["off"], 49 | "lines-around-comment": ["error", { "beforeBlockComment": true, "allowBlockStart": true, "allowObjectStart": true, "allowArrayStart": true, "beforeLineComment": true, "allowBlockEnd": true }], 50 | "max-len": [2, 80, 4], 51 | "new-parens": "error", 52 | "no-array-constructor": "error", 53 | "no-lonely-if": "error", 54 | "no-mixed-operators": [ "error", { 55 | "groups": [ 56 | ["+", "-", "*", "/", "%", "**"], 57 | ["&", "|", "^", "~", "<<", ">>", ">>>"], 58 | ["==", "!=", "===", "!==", ">", ">=", "<", "<="], 59 | ["&&", "||"], 60 | ["in", "instanceof"] 61 | ], 62 | "allowSamePrecedence": true 63 | }], 64 | "no-mixed-spaces-and-tabs": "error", 65 | "no-plusplus": "off", 66 | "no-trailing-spaces": ["error", { "skipBlankLines": true }], 67 | "no-underscore-dangle": "off", 68 | "no-whitespace-before-property": "error", 69 | // "object-curly-newline": ["error", { "multiline": true, "minProperties": 0 }], 70 | "one-var-declaration-per-line": ["error", "initializations"], 71 | "quote-props": ["error", "as-needed"], 72 | "quotes": ["error", "single"], 73 | "semi-spacing": ["error", { "before": false, "after": true }], 74 | "semi": ["error", "always"], 75 | "space-before-blocks": "error", 76 | "space-before-function-paren": ["error", "never"], 77 | "space-in-parens": ["error", "never"], 78 | "space-infix-ops": ["error", { "int32Hint": true }], 79 | "wrap-regex": "error" 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /webpack/core.config.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const webpack = require('webpack'); 4 | const HtmlWebpackPlugin = require('html-webpack-plugin'); 5 | const autoprefixer = require('autoprefixer'); 6 | const path = require('path'); 7 | const config = require('./config'); 8 | 9 | const phaserModule = path.join(__dirname, '../node_modules/phaser-ce/'); 10 | const phaser = path.join(phaserModule, 'build/custom/phaser-split.js'); 11 | const pixi = path.join(phaserModule, 'build/custom/pixi.js'); 12 | const p2 = path.join(phaserModule, 'build/custom/p2.js'); 13 | 14 | module.exports = { 15 | entry: { 16 | app: [ 17 | 'babel-polyfill', 18 | path.resolve(__dirname, '../src/js/Main.js') 19 | ], 20 | vendor: ['pixi', 'p2', 'phaser', 'webfontloader'] 21 | }, 22 | output: { 23 | path: path.resolve(__dirname, '../game'), 24 | filename: 'game-[chunkhash].js' 25 | }, 26 | plugins: [ 27 | new HtmlWebpackPlugin({ 28 | title: config.title, 29 | template: path.join(__dirname, '../src', 'index.html') 30 | }), 31 | new webpack.LoaderOptionsPlugin({ 32 | options: { 33 | eslint: { 34 | useEslintrc: true 35 | }, 36 | postcss: () => { 37 | return [autoprefixer]; 38 | } 39 | } 40 | }), 41 | new webpack.optimize.CommonsChunkPlugin({ 42 | name: 'vendor', 43 | filename: '[name]-[chunkhash].js' 44 | }) 45 | ], 46 | module: { 47 | rules: [ 48 | { 49 | enforce: 'pre', 50 | test: /\.js$/, 51 | include: path.join(__dirname, '../src'), 52 | use: 'eslint-loader' 53 | }, 54 | { 55 | test: /\.js$/, 56 | include: path.join(__dirname, '../src'), 57 | use: 'babel-loader' 58 | }, 59 | { 60 | test: /\.css$/, 61 | include: path.join(__dirname, '../src'), 62 | use: [ 63 | 'style-loader', 64 | 'css-loader', 65 | 'postcss-loader' 66 | ] 67 | }, 68 | { 69 | test: /phaser-split\.js$/, 70 | use: 'expose-loader?Phaser' 71 | }, 72 | { 73 | test: /pixi\.js/, 74 | use: 'expose-loader?PIXI' 75 | }, 76 | { 77 | test: /p2\.js/, 78 | use: 'expose-loader?p2' 79 | }, 80 | { 81 | test: /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|txt)(\?.*)?$/, 82 | include: path.join(__dirname, '../src'), 83 | use: { 84 | loader: 'file-loader', 85 | query: { 86 | name: 'media/[name].[hash:8].[ext]' 87 | } 88 | } 89 | }, 90 | { 91 | test: /\.(mp4|webm|wav|mp3|m4a|aac|oga)(\?.*)?$/, 92 | include: path.join(__dirname, '../src'), 93 | use: { 94 | loader: 'url-loader', 95 | query: { 96 | limit: 10000, 97 | name: 'media/[name].[hash:8].[ext]' 98 | } 99 | } 100 | }, 101 | { 102 | test: /\.json$/, 103 | include: path.join(__dirname, '../src'), 104 | use: 'json-loader' 105 | } 106 | ] 107 | }, 108 | node: { 109 | dns: 'empty', 110 | fs: 'empty', 111 | net: 'empty', 112 | tls: 'empty' 113 | }, 114 | resolve: { 115 | alias: { 116 | 'phaser': phaser, 117 | 'pixi': pixi, 118 | 'p2': p2 119 | } 120 | } 121 | }; 122 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

4 | 5 | ![div](https://raw.githubusercontent.com/brenopolanski/phaser-es6-starter/gh-assets/div.png) 6 | 7 |
8 | 9 | [![Phaser](https://raw.githubusercontent.com/brenopolanski/phaser-es6-starter/gh-assets/icon-phaser.png)](http://phaser.io/) 10 | [![ES6](https://raw.githubusercontent.com/brenopolanski/phaser-es6-starter/gh-assets/icon-js.png)](https://www.ecma-international.org/ecma-262/6.0/) 11 | [![Webpack](https://raw.githubusercontent.com/brenopolanski/phaser-es6-starter/gh-assets/icon-webpack.png)](https://webpack.github.io/) 12 | [![ESLint](https://raw.githubusercontent.com/brenopolanski/phaser-es6-starter/gh-assets/icon-eslint.png)](http://eslint.org/) 13 | [![Yarn](https://raw.githubusercontent.com/brenopolanski/phaser-es6-starter/gh-assets/icon-yarn.png)](https://yarnpkg.com/) 14 | [![PWA](https://raw.githubusercontent.com/brenopolanski/phaser-es6-starter/gh-assets/icon-pwa.png)](https://developers.google.com/web/progressive-web-apps/) 15 | 16 | A template for writing [Phaser](http://phaser.io/) Games based on [ECMAScript 2015 (ES6)](https://www.ecma-international.org/ecma-262/6.0/) + [Webpack](https://webpack.github.io/) + [Progressive Web Apps](https://developers.google.com/web/progressive-web-apps/) for rapid game development. 17 | 18 | Invite me to a coffee [![donate-paypal](https://raw.githubusercontent.com/brenopolanski/phaser-es6-starter/gh-assets/btn_donate_paypal.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WNXA4YYGQCJZG) 19 | 20 | ## Getting Started 21 | 22 | ### Installation 23 | 24 | First of all, install the dependencies to run this boilerplate. 25 | 26 | - [NodeJS](http://nodejs.org/) 27 | - [GulpJS](http://gulpjs.com/) 28 | 29 | ```bash 30 | # Clone this repository 31 | $ git clone git@github.com:brenopolanski/phaser-es6-starter.git my-game 32 | $ cd my-game 33 | 34 | # install dependencies 35 | $ yarn (or npm i) 36 | # run game 37 | $ yarn start (or npm start) 38 | ``` 39 | 40 | ### Game Demo 41 | 42 | [![game-demo](https://raw.githubusercontent.com/brenopolanski/phaser-es6-starter/gh-assets/game-demo.png)](http://brenopolanski.com/phaser-es6-starter/) 43 | 44 | > [Check it live](http://brenopolanski.com/phaser-es6-starter/) or see the tutorial: [Advanced Phaser and TypeScript Projects](http://www.photonstorm.com/phaser/advanced-phaser-and-typescript-projects) by [Richard Davey](https://github.com/photonstorm) at [www.photonstorm.com](http://www.photonstorm.com/). 45 | 46 | ### :heart: Found this project useful? 47 | 48 | If you found this project useful, then please consider giving it a :star: on Github and sharing it with your friends via social media. 49 | 50 | ## Scripts 51 | 52 | - `yarn dev (or npm run dev)`: Starts the game on development mode; 53 | - `yarn build (or npm run build)`: Build game to production; 54 | - `yarn build:analyzer (or npm run build:analyzer)`: Build game to production and open bundle analyzer on `8888` port; 55 | - `yarn start (or npm start)`: Special script reserved to run production code. Change as you wish. For now, it is the same as `yarn dev`. 56 | 57 | ## Tasks 58 | 59 | - `gulp template:empty`: Call to create an empty game project template in `src/` folder; 60 | - `gulp vscode`: Call [VSCode Intellisense for Phaser](http://www.html5gamedevs.com/topic/27418-visual-studio-code-intellisense-for-phaserjs/); 61 | - `gulp deploy`: Deploy compiled files at `game` folder to `github` on branch `gh-pages`. 62 | 63 | ## Editor Configuration 64 | 65 | **Atom** 66 | 67 | ```bash 68 | apm install editorconfig es6-javascript atom-ternjs javascript-snippets linter linter-eslint language-babel autocomplete-modules file-icons 69 | ``` 70 | 71 | **VSCode** 72 | 73 | - [Editorconfig](https://github.com/editorconfig/editorconfig-vscode) 74 | - [ESLint](https://github.com/Microsoft/vscode-eslint) 75 | - [Babel](https://github.com/dzannotti/vscode-babel) 76 | - [ES6 Snippets](https://marketplace.visualstudio.com/items?itemName=xabikos.JavaScriptSnippets) 77 | 78 | **Sublime** 79 | 80 | - [Editorconfig Integration](https://github.com/sindresorhus/editorconfig-sublime#readme) 81 | - [Linting](https://github.com/SublimeLinter/SublimeLinter3) 82 | - [ESLint Integration](https://github.com/roadhump/SublimeLinter-eslint) 83 | - [Syntax Highlighting](https://github.com/babel/babel-sublime) 84 | - [Autocompletion](https://github.com/ternjs/tern_for_sublime) 85 | - [Node Snippets](https://packagecontrol.io/packages/JavaScript%20%26%20NodeJS%20Snippets) 86 | - [ES6 Snippets](https://packagecontrol.io/packages/ES6-Toolkit) 87 | 88 | **Others** 89 | 90 | - [Editorconfig](http://editorconfig.org/#download) 91 | - [ESLint](http://eslint.org/docs/user-guide/integrations#editors) 92 | - [Babel Syntax Plugin](https://babeljs.io/docs/plugins/) 93 | 94 | ## Technologies 95 | 96 | Phaser ES6 Starter offers a rich development experience using the following technologies: 97 | 98 | | **Tech** | **Description** |**Learn More**| 99 | |----------|-----------------|--------------| 100 | | [Phaser](http://phaser.io/) | A fast, fun and free open source HTML5 game framework. | [Learn Phaser](http://phaser.io/learn) | 101 | | [Babel](http://babeljs.io) | Compiles ES6 to ES5. Enjoy the new version of JavaScript today. | [ES6 REPL](https://babeljs.io/repl/), [ES6 vs ES5](http://es6-features.org), [ES6 Katas](http://es6katas.org) | 102 | | [Webpack](http://webpack.github.io) | Bundles npm packages and our JS into a single file. Includes hot reloading via [react-transform-hmr](https://www.npmjs.com/package/react-transform-hmr). | [Quick Webpack How-to](https://github.com/petehunt/webpack-howto) | 103 | | [Browsersync](https://www.browsersync.io/) | Lightweight development HTTP server that supports synchronized testing and debugging on multiple devices. | [Intro vid](https://www.youtube.com/watch?time_continue=1&v=heNWfzc7ufQ) | 104 | | [ESLint](http://eslint.org/)| Lint JS. Reports syntax and style issues. Using [eslint-plugin-react](https://github.com/yannickcr/eslint-plugin-react) for additional React specific linting rules. | | 105 | | [PostCSS](https://github.com/postcss/postcss) | Transform styles with JS plugins. Used to autoprefix CSS | | 106 | | [Stats.js](https://github.com/mrdoob/stats.js) | For displaying FPS/MS. | | 107 | | [Editor Config](http://editorconfig.org) | Enforce consistent editor settings (spaces vs tabs, etc). | [IDE Plugins](http://editorconfig.org/#download) | 108 | | [npm Scripts](https://docs.npmjs.com/misc/scripts)| Glues all this together in a handy automated build. | [Why not Gulp?](https://medium.com/@housecor/why-i-left-gulp-and-grunt-for-npm-scripts-3d6853dd22b8#.vtaziro8n) | 109 | 110 | ## Contributing 111 | 112 | If you want to help, please read the [Contributing](https://github.com/brenopolanski/phaser-es6-starter/blob/master/CONTRIBUTING.md) guide. 113 | 114 | ## History 115 | 116 | For detailed changelog, see [Releases](https://github.com/brenopolanski/phaser-es6-starter/releases). 117 | 118 | ## Credits 119 | 120 | Phaser is a free and open source software developed and owned by [Richard Davey](https://github.com/photonstorm) at [www.photonstorm.com](http://www.photonstorm.com/). You can visit [their funding page](http://phaser.io/community/donate) and help them to make Phaser even better. 121 | 122 | ## Donations 123 | 124 | Donations would be more than welcome :) 125 | 126 | [![donate-paypal](https://raw.githubusercontent.com/brenopolanski/phaser-es6-starter/gh-assets/btn_donate_paypal.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WNXA4YYGQCJZG) 127 | 128 | ## License 129 | 130 | [MIT License](https://brenopolanski.mit-license.org/) © Breno Polanski 131 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### phaser-es6-starter ### 2 | game/ 3 | .publish/ 4 | firefox_root/ 5 | 6 | # Created by https://www.gitignore.io/api/node,webstorm,sublimetext,visualstudio,visualstudiocode,cloud9,git,vim,macos,linux,windows 7 | 8 | ### Cloud9 ### 9 | # Cloud9 IDE - http://c9.io 10 | .c9revisions 11 | .c9 12 | 13 | ### Git ### 14 | *.orig 15 | 16 | ### Linux ### 17 | *~ 18 | 19 | # temporary files which can be created if a process still has a handle open of a deleted file 20 | .fuse_hidden* 21 | 22 | # KDE directory preferences 23 | .directory 24 | 25 | # Linux trash folder which might appear on any partition or disk 26 | .Trash-* 27 | 28 | # .nfs files are created when an open file is removed but is still being accessed 29 | .nfs* 30 | 31 | ### macOS ### 32 | *.DS_Store 33 | .AppleDouble 34 | .LSOverride 35 | 36 | # Icon must end with two \r 37 | Icon 38 | 39 | # Thumbnails 40 | ._* 41 | 42 | # Files that might appear in the root of a volume 43 | .DocumentRevisions-V100 44 | .fseventsd 45 | .Spotlight-V100 46 | .TemporaryItems 47 | .Trashes 48 | .VolumeIcon.icns 49 | .com.apple.timemachine.donotpresent 50 | 51 | # Directories potentially created on remote AFP share 52 | .AppleDB 53 | .AppleDesktop 54 | Network Trash Folder 55 | Temporary Items 56 | .apdisk 57 | 58 | ### Node ### 59 | # Logs 60 | logs 61 | *.log 62 | npm-debug.log* 63 | yarn-debug.log* 64 | yarn-error.log* 65 | 66 | # Runtime data 67 | pids 68 | *.pid 69 | *.seed 70 | *.pid.lock 71 | 72 | # Directory for instrumented libs generated by jscoverage/JSCover 73 | lib-cov 74 | 75 | # Coverage directory used by tools like istanbul 76 | coverage 77 | 78 | # nyc test coverage 79 | .nyc_output 80 | 81 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 82 | .grunt 83 | 84 | # Bower dependency directory (https://bower.io/) 85 | bower_components 86 | 87 | # node-waf configuration 88 | .lock-wscript 89 | 90 | # Compiled binary addons (http://nodejs.org/api/addons.html) 91 | build/Release 92 | 93 | # Dependency directories 94 | node_modules/ 95 | jspm_packages/ 96 | 97 | # Typescript v1 declaration files 98 | typings/ 99 | 100 | # Optional npm cache directory 101 | .npm 102 | 103 | # Optional eslint cache 104 | .eslintcache 105 | 106 | # Optional REPL history 107 | .node_repl_history 108 | 109 | # Output of 'npm pack' 110 | *.tgz 111 | 112 | # Yarn Integrity file 113 | .yarn-integrity 114 | 115 | # dotenv environment variables file 116 | .env 117 | 118 | 119 | ### SublimeText ### 120 | # cache files for sublime text 121 | *.tmlanguage.cache 122 | *.tmPreferences.cache 123 | *.stTheme.cache 124 | 125 | # workspace files are user-specific 126 | *.sublime-workspace 127 | 128 | # project files should be checked into the repository, unless a significant 129 | # proportion of contributors will probably not be using SublimeText 130 | # *.sublime-project 131 | 132 | # sftp configuration file 133 | sftp-config.json 134 | 135 | # Package control specific files 136 | Package Control.last-run 137 | Package Control.ca-list 138 | Package Control.ca-bundle 139 | Package Control.system-ca-bundle 140 | Package Control.cache/ 141 | Package Control.ca-certs/ 142 | Package Control.merged-ca-bundle 143 | Package Control.user-ca-bundle 144 | oscrypto-ca-bundle.crt 145 | bh_unicode_properties.cache 146 | 147 | # Sublime-github package stores a github token in this file 148 | # https://packagecontrol.io/packages/sublime-github 149 | GitHub.sublime-settings 150 | 151 | ### Vim ### 152 | # swap 153 | [._]*.s[a-v][a-z] 154 | [._]*.sw[a-p] 155 | [._]s[a-v][a-z] 156 | [._]sw[a-p] 157 | # session 158 | Session.vim 159 | # temporary 160 | .netrwhist 161 | # auto-generated tag files 162 | tags 163 | 164 | ### VisualStudioCode ### 165 | .vscode/* 166 | !.vscode/settings.json 167 | !.vscode/tasks.json 168 | !.vscode/launch.json 169 | !.vscode/extensions.json 170 | 171 | ### WebStorm ### 172 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 173 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 174 | 175 | # User-specific stuff: 176 | .idea/**/workspace.xml 177 | .idea/**/tasks.xml 178 | .idea/dictionaries 179 | 180 | # Sensitive or high-churn files: 181 | .idea/**/dataSources/ 182 | .idea/**/dataSources.ids 183 | .idea/**/dataSources.xml 184 | .idea/**/dataSources.local.xml 185 | .idea/**/sqlDataSources.xml 186 | .idea/**/dynamic.xml 187 | .idea/**/uiDesigner.xml 188 | 189 | # Gradle: 190 | .idea/**/gradle.xml 191 | .idea/**/libraries 192 | 193 | # CMake 194 | cmake-build-debug/ 195 | 196 | # Mongo Explorer plugin: 197 | .idea/**/mongoSettings.xml 198 | 199 | ## File-based project format: 200 | *.iws 201 | 202 | ## Plugin-specific files: 203 | 204 | # IntelliJ 205 | /out/ 206 | 207 | # mpeltonen/sbt-idea plugin 208 | .idea_modules/ 209 | 210 | # JIRA plugin 211 | atlassian-ide-plugin.xml 212 | 213 | # Cursive Clojure plugin 214 | .idea/replstate.xml 215 | 216 | # Crashlytics plugin (for Android Studio and IntelliJ) 217 | com_crashlytics_export_strings.xml 218 | crashlytics.properties 219 | crashlytics-build.properties 220 | fabric.properties 221 | 222 | ### WebStorm Patch ### 223 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 224 | 225 | # *.iml 226 | # modules.xml 227 | # .idea/misc.xml 228 | # *.ipr 229 | 230 | # Sonarlint plugin 231 | .idea/sonarlint 232 | 233 | ### Windows ### 234 | # Windows thumbnail cache files 235 | Thumbs.db 236 | ehthumbs.db 237 | ehthumbs_vista.db 238 | 239 | # Folder config file 240 | Desktop.ini 241 | 242 | # Recycle Bin used on file shares 243 | $RECYCLE.BIN/ 244 | 245 | # Windows Installer files 246 | *.cab 247 | *.msi 248 | *.msm 249 | *.msp 250 | 251 | # Windows shortcuts 252 | *.lnk 253 | 254 | ### VisualStudio ### 255 | ## Ignore Visual Studio temporary files, build results, and 256 | ## files generated by popular Visual Studio add-ons. 257 | ## 258 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 259 | 260 | # User-specific files 261 | *.suo 262 | *.user 263 | *.userosscache 264 | *.sln.docstates 265 | 266 | # User-specific files (MonoDevelop/Xamarin Studio) 267 | *.userprefs 268 | 269 | # Build results 270 | [Dd]ebug/ 271 | [Dd]ebugPublic/ 272 | [Rr]elease/ 273 | [Rr]eleases/ 274 | x64/ 275 | x86/ 276 | bld/ 277 | [Bb]in/ 278 | [Oo]bj/ 279 | [Ll]og/ 280 | 281 | # Visual Studio 2015 cache/options directory 282 | .vs/ 283 | # Uncomment if you have tasks that create the project's static files in wwwroot 284 | #wwwroot/ 285 | 286 | # MSTest test Results 287 | [Tt]est[Rr]esult*/ 288 | [Bb]uild[Ll]og.* 289 | 290 | # NUNIT 291 | *.VisualState.xml 292 | TestResult.xml 293 | 294 | # Build Results of an ATL Project 295 | [Dd]ebugPS/ 296 | [Rr]eleasePS/ 297 | dlldata.c 298 | 299 | # .NET Core 300 | project.lock.json 301 | project.fragment.lock.json 302 | artifacts/ 303 | **/Properties/launchSettings.json 304 | 305 | *_i.c 306 | *_p.c 307 | *_i.h 308 | *.ilk 309 | *.meta 310 | *.obj 311 | *.pch 312 | *.pdb 313 | *.pgc 314 | *.pgd 315 | *.rsp 316 | *.sbr 317 | *.tlb 318 | *.tli 319 | *.tlh 320 | *.tmp 321 | *.tmp_proj 322 | *.vspscc 323 | *.vssscc 324 | .builds 325 | *.pidb 326 | *.svclog 327 | *.scc 328 | 329 | # Chutzpah Test files 330 | _Chutzpah* 331 | 332 | # Visual C++ cache files 333 | ipch/ 334 | *.aps 335 | *.ncb 336 | *.opendb 337 | *.opensdf 338 | *.sdf 339 | *.cachefile 340 | *.VC.db 341 | *.VC.VC.opendb 342 | 343 | # Visual Studio profiler 344 | *.psess 345 | *.vsp 346 | *.vspx 347 | *.sap 348 | 349 | # TFS 2012 Local Workspace 350 | $tf/ 351 | 352 | # Guidance Automation Toolkit 353 | *.gpState 354 | 355 | # ReSharper is a .NET coding add-in 356 | _ReSharper*/ 357 | *.[Rr]e[Ss]harper 358 | *.DotSettings.user 359 | 360 | # JustCode is a .NET coding add-in 361 | .JustCode 362 | 363 | # TeamCity is a build add-in 364 | _TeamCity* 365 | 366 | # DotCover is a Code Coverage Tool 367 | *.dotCover 368 | 369 | # Visual Studio code coverage results 370 | *.coverage 371 | *.coveragexml 372 | 373 | # NCrunch 374 | _NCrunch_* 375 | .*crunch*.local.xml 376 | nCrunchTemp_* 377 | 378 | # MightyMoose 379 | *.mm.* 380 | AutoTest.Net/ 381 | 382 | # Web workbench (sass) 383 | .sass-cache/ 384 | 385 | # Installshield output folder 386 | [Ee]xpress/ 387 | 388 | # DocProject is a documentation generator add-in 389 | DocProject/buildhelp/ 390 | DocProject/Help/*.HxT 391 | DocProject/Help/*.HxC 392 | DocProject/Help/*.hhc 393 | DocProject/Help/*.hhk 394 | DocProject/Help/*.hhp 395 | DocProject/Help/Html2 396 | DocProject/Help/html 397 | 398 | # Click-Once directory 399 | publish/ 400 | 401 | # Publish Web Output 402 | *.[Pp]ublish.xml 403 | *.azurePubxml 404 | # TODO: Comment the next line if you want to checkin your web deploy settings 405 | # but database connection strings (with potential passwords) will be unencrypted 406 | *.pubxml 407 | *.publishproj 408 | 409 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 410 | # checkin your Azure Web App publish settings, but sensitive information contained 411 | # in these scripts will be unencrypted 412 | PublishScripts/ 413 | 414 | # NuGet Packages 415 | *.nupkg 416 | # The packages folder can be ignored because of Package Restore 417 | **/packages/* 418 | # except build/, which is used as an MSBuild target. 419 | !**/packages/build/ 420 | # Uncomment if necessary however generally it will be regenerated when needed 421 | #!**/packages/repositories.config 422 | # NuGet v3's project.json files produces more ignorable files 423 | *.nuget.props 424 | *.nuget.targets 425 | 426 | # Microsoft Azure Build Output 427 | csx/ 428 | *.build.csdef 429 | 430 | # Microsoft Azure Emulator 431 | ecf/ 432 | rcf/ 433 | 434 | # Windows Store app package directories and files 435 | AppPackages/ 436 | BundleArtifacts/ 437 | Package.StoreAssociation.xml 438 | _pkginfo.txt 439 | 440 | # Visual Studio cache files 441 | # files ending in .cache can be ignored 442 | *.[Cc]ache 443 | # but keep track of directories ending in .cache 444 | !*.[Cc]ache/ 445 | 446 | # Others 447 | ClientBin/ 448 | ~$* 449 | *.dbmdl 450 | *.dbproj.schemaview 451 | *.jfm 452 | *.pfx 453 | *.publishsettings 454 | orleans.codegen.cs 455 | 456 | # Since there are multiple workflows, uncomment next line to ignore bower_components 457 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 458 | #bower_components/ 459 | 460 | # RIA/Silverlight projects 461 | Generated_Code/ 462 | 463 | # Backup & report files from converting an old project file 464 | # to a newer Visual Studio version. Backup files are not needed, 465 | # because we have git ;-) 466 | _UpgradeReport_Files/ 467 | Backup*/ 468 | UpgradeLog*.XML 469 | UpgradeLog*.htm 470 | 471 | # SQL Server files 472 | *.mdf 473 | *.ldf 474 | *.ndf 475 | 476 | # Business Intelligence projects 477 | *.rdl.data 478 | *.bim.layout 479 | *.bim_*.settings 480 | 481 | # Microsoft Fakes 482 | FakesAssemblies/ 483 | 484 | # GhostDoc plugin setting file 485 | *.GhostDoc.xml 486 | 487 | # Node.js Tools for Visual Studio 488 | .ntvs_analysis.dat 489 | 490 | # Typescript v1 declaration files 491 | 492 | # Visual Studio 6 build log 493 | *.plg 494 | 495 | # Visual Studio 6 workspace options file 496 | *.opt 497 | 498 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 499 | *.vbw 500 | 501 | # Visual Studio LightSwitch build output 502 | **/*.HTMLClient/GeneratedArtifacts 503 | **/*.DesktopClient/GeneratedArtifacts 504 | **/*.DesktopClient/ModelManifest.xml 505 | **/*.Server/GeneratedArtifacts 506 | **/*.Server/ModelManifest.xml 507 | _Pvt_Extensions 508 | 509 | # Paket dependency manager 510 | .paket/paket.exe 511 | paket-files/ 512 | 513 | # FAKE - F# Make 514 | .fake/ 515 | 516 | # JetBrains Rider 517 | .idea/ 518 | *.sln.iml 519 | 520 | # CodeRush 521 | .cr/ 522 | 523 | # Python Tools for Visual Studio (PTVS) 524 | __pycache__/ 525 | *.pyc 526 | 527 | # Cake - Uncomment if you are using it 528 | # tools/** 529 | # !tools/packages.config 530 | 531 | # Telerik's JustMock configuration file 532 | *.jmconfig 533 | 534 | # BizTalk build output 535 | *.btp.cs 536 | *.btm.cs 537 | *.odx.cs 538 | *.xsd.cs 539 | 540 | # End of https://www.gitignore.io/api/node,webstorm,sublimetext,visualstudio,visualstudiocode,cloud9,git,vim,macos,linux,windows 541 | -------------------------------------------------------------------------------- /toolkit/vscode-intellisense/defs/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 | frictionStuffness: 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 class 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: number; 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(vertices: number[][], axes: number[]); 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 class Shape { 650 | 651 | static idCounter: number; 652 | static CIRCLE: number; 653 | static PARTICLE: number; 654 | static PLANE: number; 655 | static CONVEX: number; 656 | static LINE: number; 657 | static RECTANGLE: number; 658 | static CAPSULE: number; 659 | static HEIGHTFIELD: number; 660 | 661 | constructor(type: number); 662 | 663 | type: number; 664 | id: number; 665 | boundingRadius: number; 666 | collisionGroup: number; 667 | collisionMask: number; 668 | material: Material; 669 | area: number; 670 | sensor: boolean; 671 | 672 | computeMomentOfInertia(mass: number): number; 673 | updateBoundingRadius(): number; 674 | updateArea(): void; 675 | computeAABB(out: AABB, position: number[], angle: number): void; 676 | 677 | } 678 | 679 | export class Line extends Shape { 680 | 681 | constructor(length?: number); 682 | 683 | length: number; 684 | 685 | } 686 | 687 | export class Particle extends Shape { 688 | 689 | } 690 | 691 | export class Plane extends Shape { 692 | 693 | } 694 | 695 | export class Rectangle extends Shape { 696 | 697 | static sameDimensions(a: Rectangle, b: Rectangle): boolean; 698 | 699 | constructor(width?: number, height?: number); 700 | 701 | width: number; 702 | height: number; 703 | 704 | } 705 | 706 | export class Solver extends EventEmitter { 707 | 708 | static GS: number; 709 | static ISLAND: number; 710 | 711 | constructor(options?: {}, type?: number); 712 | 713 | type: number; 714 | equations: Equation[]; 715 | equationSortFunction: Equation; //Equation | boolean 716 | 717 | solve(dy: number, world: World): void; 718 | solveIsland(dy: number, island: Island): void; 719 | sortEquations(): void; 720 | addEquation(eq: Equation): void; 721 | addEquations(eqs: Equation[]): void; 722 | removeEquation(eq: Equation): void; 723 | removeAllEquations(): void; 724 | 725 | } 726 | 727 | export class GSSolver extends Solver { 728 | 729 | constructor(options?: { 730 | iterations?: number; 731 | tolerance?: number; 732 | }); 733 | 734 | iterations: number; 735 | tolerance: number; 736 | useZeroRHS: boolean; 737 | frictionIterations: number; 738 | usedIterations: number; 739 | 740 | solve(h: number, world: World): void; 741 | 742 | } 743 | 744 | export class OverlapKeeper { 745 | 746 | constructor(bodyA: Body, shapeA: Shape, bodyB: Body, shapeB: Shape); 747 | 748 | shapeA: Shape; 749 | shapeB: Shape; 750 | bodyA: Body; 751 | bodyB: Body; 752 | 753 | tick(): void; 754 | setOverlapping(bodyA: Body, shapeA: Shape, bodyB: Body, shapeB: Body): void; 755 | bodiesAreOverlapping(bodyA: Body, bodyB: Body): boolean; 756 | set(bodyA: Body, shapeA: Shape, bodyB: Body, shapeB: Shape): void; 757 | 758 | } 759 | 760 | export class TupleDictionary { 761 | 762 | data: number[]; 763 | keys: number[]; 764 | 765 | getKey(id1: number, id2: number): string; 766 | getByKey(key: number): number; 767 | get(i: number, j: number): number; 768 | set(i: number, j: number, value: number): number; 769 | reset(): void; 770 | copy(dict: TupleDictionary): void; 771 | 772 | } 773 | 774 | export class Utils { 775 | 776 | static appendArray(a: Array, b: Array): Array; 777 | static chanceRoll(chance: number): boolean; 778 | static defaults(options: any, defaults: any): any; 779 | static extend(a: any, b: any): void; 780 | static randomChoice(choice1: any, choice2: any): any; 781 | static rotateArray(matrix: any[], direction: any): any[]; 782 | static splice(array: Array, index: number, howMany: number): void; 783 | static shuffle(array: T[]): T[]; 784 | static transposeArray(array: T[]): T[]; 785 | 786 | } 787 | 788 | export class Island { 789 | 790 | equations: Equation[]; 791 | bodies: Body[]; 792 | 793 | reset(): void; 794 | getBodies(result: any): Body[]; 795 | wantsToSleep(): boolean; 796 | sleep(): boolean; 797 | 798 | } 799 | 800 | export class IslandManager extends Solver { 801 | 802 | static getUnvisitedNode(nodes: Node[]): IslandNode; // IslandNode | boolean 803 | 804 | equations: Equation[]; 805 | islands: Island[]; 806 | nodes: IslandNode[]; 807 | 808 | visit(node: IslandNode, bds: Body[], eqs: Equation[]): void; 809 | bfs(root: IslandNode, bds: Body[], eqs: Equation[]): void; 810 | split(world: World): Island[]; 811 | 812 | } 813 | 814 | export class IslandNode { 815 | 816 | constructor(body: Body); 817 | 818 | body: Body; 819 | neighbors: IslandNode[]; 820 | equations: Equation[]; 821 | visited: boolean; 822 | 823 | reset(): void; 824 | 825 | } 826 | 827 | export class World extends EventEmitter { 828 | 829 | postStepEvent: { 830 | type: string; 831 | }; 832 | 833 | addBodyEvent: { 834 | type: string; 835 | }; 836 | 837 | removeBodyEvent: { 838 | type: string; 839 | }; 840 | 841 | addSpringEvent: { 842 | type: string; 843 | }; 844 | 845 | impactEvent: { 846 | type: string; 847 | bodyA: Body; 848 | bodyB: Body; 849 | shapeA: Shape; 850 | shapeB: Shape; 851 | contactEquation: ContactEquation; 852 | }; 853 | 854 | postBroadphaseEvent: { 855 | type: string; 856 | pairs: Body[]; 857 | }; 858 | 859 | beginContactEvent: { 860 | type: string; 861 | shapeA: Shape; 862 | shapeB: Shape; 863 | bodyA: Body; 864 | bodyB: Body; 865 | contactEquations: ContactEquation[]; 866 | }; 867 | 868 | endContactEvent: { 869 | type: string; 870 | shapeA: Shape; 871 | shapeB: Shape; 872 | bodyA: Body; 873 | bodyB: Body; 874 | }; 875 | 876 | preSolveEvent: { 877 | type: string; 878 | contactEquations: ContactEquation[]; 879 | frictionEquations: FrictionEquation[]; 880 | }; 881 | 882 | static NO_SLEEPING: number; 883 | static BODY_SLEEPING: number; 884 | static ISLAND_SLEEPING: number; 885 | 886 | static integrateBody(body: Body, dy: number): void; 887 | 888 | constructor(options?: { 889 | solver?: Solver; 890 | gravity?: number[]; 891 | broadphase?: Broadphase; 892 | islandSplit?: boolean; 893 | doProfiling?: boolean; 894 | }); 895 | 896 | springs: Spring[]; 897 | bodies: Body[]; 898 | solver: Solver; 899 | narrowphase: Narrowphase; 900 | islandManager: IslandManager; 901 | gravity: number[]; 902 | frictionGravity: number; 903 | useWorldGravityAsFrictionGravity: boolean; 904 | useFrictionGravityOnZeroGravity: boolean; 905 | doProfiling: boolean; 906 | lastStepTime: number; 907 | broadphase: Broadphase; 908 | constraints: Constraint[]; 909 | defaultMaterial: Material; 910 | defaultContactMaterial: ContactMaterial; 911 | lastTimeStep: number; 912 | applySpringForces: boolean; 913 | applyDamping: boolean; 914 | applyGravity: boolean; 915 | solveConstraints: boolean; 916 | contactMaterials: ContactMaterial[]; 917 | time: number; 918 | stepping: boolean; 919 | islandSplit: boolean; 920 | emitImpactEvent: boolean; 921 | sleepMode: number; 922 | 923 | addConstraint(c: Constraint): void; 924 | addContactMaterial(contactMaterial: ContactMaterial): void; 925 | removeContactMaterial(cm: ContactMaterial): void; 926 | getContactMaterial(materialA: Material, materialB: Material): ContactMaterial; // ContactMaterial | boolean 927 | removeConstraint(c: Constraint): void; 928 | step(dy: number, timeSinceLastCalled?: number, maxSubSteps?: number): void; 929 | runNarrowphase(np: Narrowphase, bi: Body, si: Shape, xi: any[], ai: number, bj: Body, sj: Shape, xj: any[], aj: number, cm: number, glen: number): void; 930 | addSpring(s: Spring): void; 931 | removeSpring(s: Spring): void; 932 | addBody(body: Body): void; 933 | removeBody(body: Body): void; 934 | getBodyByID(id: number): Body; //Body | boolean 935 | disableBodyCollision(bodyA: Body, bodyB: Body): void; 936 | enableBodyCollision(bodyA: Body, bodyB: Body): void; 937 | clear(): void; 938 | clone(): World; 939 | hitTest(worldPoint: number[], bodies: Body[], precision: number): Body[]; 940 | setGlobalEquationParameters(parameters: { 941 | relaxation?: number; 942 | stiffness?: number; 943 | }): void; 944 | setGlobalStiffness(stiffness: number): void; 945 | setGlobalRelaxation(relaxation: number): void; 946 | } 947 | 948 | } 949 | -------------------------------------------------------------------------------- /toolkit/vscode-intellisense/defs/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 defaultRenderOptions: PixiRendererOptions; 41 | 42 | export var INTERACTION_REQUENCY: number; 43 | export var AUTO_PREVENT_DEFAULT: boolean; 44 | 45 | export var PI_2: number; 46 | export var RAD_TO_DEG: number; 47 | export var DEG_TO_RAD: number; 48 | 49 | export var RETINA_PREFIX: string; 50 | export var identityMatrix: Matrix; 51 | export var glContexts: WebGLRenderingContext[]; 52 | export var instances: any[]; 53 | 54 | export var TextureSilentFail: boolean; 55 | export var BitmapText: { fonts: {} }; 56 | 57 | export function isPowerOfTwo(width: number, height: number): boolean; 58 | 59 | export function rgb2hex(rgb: number[]): string; 60 | export function hex2rgb(hex: string): number[]; 61 | 62 | export function autoDetectRenderer(width?: number, height?: number, options?: PixiRendererOptions): PixiRenderer; 63 | export function autoDetectRecommendedRenderer(width?: number, height?: number, options?: PixiRendererOptions): PixiRenderer; 64 | 65 | export function canUseNewCanvasBlendModes(): boolean; 66 | export function getNextPowerOfTwo(value: number): number; 67 | 68 | export function AjaxRequest(): XMLHttpRequest; 69 | 70 | export function CompileFragmentShader(gl: WebGLRenderingContext, shaderSrc: string[]): any; 71 | export function CompileProgram(gl: WebGLRenderingContext, vertexSrc: string[], fragmentSrc: string[]): any; 72 | 73 | 74 | export interface IEventCallback { 75 | (e?: IEvent): void; 76 | } 77 | 78 | export interface IEvent { 79 | type: string; 80 | content: any; 81 | } 82 | 83 | export interface HitArea { 84 | contains(x: number, y: number): boolean; 85 | } 86 | 87 | export interface IInteractionDataCallback { 88 | (interactionData: InteractionData): void; 89 | } 90 | 91 | export interface PixiRenderer { 92 | 93 | autoResize: boolean; 94 | clearBeforeRender: boolean; 95 | height: number; 96 | resolution: number; 97 | transparent: boolean; 98 | type: number; 99 | view: HTMLCanvasElement; 100 | width: number; 101 | 102 | destroy(): void; 103 | render(stage: DisplayObjectContainer): void; 104 | resize(width: number, height: number): void; 105 | 106 | } 107 | 108 | export interface PixiRendererOptions { 109 | 110 | autoResize?: boolean; 111 | antialias?: boolean; 112 | clearBeforeRender?: boolean; 113 | preserveDrawingBuffer?: boolean; 114 | resolution?: number; 115 | transparent?: boolean; 116 | view?: HTMLCanvasElement; 117 | 118 | } 119 | 120 | export interface BitmapTextStyle { 121 | 122 | font?: string; 123 | align?: string; 124 | tint?: string; 125 | 126 | } 127 | 128 | export interface TextStyle { 129 | 130 | align?: string; 131 | dropShadow?: boolean; 132 | dropShadowColor?: string; 133 | dropShadowAngle?: number; 134 | dropShadowDistance?: number; 135 | fill?: string; 136 | font?: string; 137 | lineJoin?: string; 138 | stroke?: string; 139 | strokeThickness?: number; 140 | wordWrap?: boolean; 141 | wordWrapWidth?: number; 142 | 143 | } 144 | 145 | export interface Loader { 146 | 147 | load(): void; 148 | 149 | } 150 | 151 | export interface MaskData { 152 | 153 | alpha: number; 154 | worldTransform: number[]; 155 | 156 | } 157 | 158 | export interface RenderSession { 159 | 160 | context: CanvasRenderingContext2D; 161 | maskManager: CanvasMaskManager; 162 | scaleMode: scaleModes; 163 | smoothProperty: string; 164 | roundPixels: boolean; 165 | 166 | } 167 | 168 | export interface ShaderAttribute { 169 | // TODO: Find signature of shader attributes 170 | } 171 | 172 | export interface FilterBlock { 173 | 174 | visible: boolean; 175 | renderable: boolean; 176 | 177 | } 178 | 179 | export class AbstractFilter { 180 | 181 | constructor(fragmentSrc: string | string[], uniforms: any); 182 | 183 | dirty: boolean; 184 | padding: number; 185 | uniforms: any; 186 | fragmentSrc: string | string[]; 187 | 188 | apply(frameBuffer: WebGLFramebuffer): void; 189 | syncUniforms(): void; 190 | 191 | } 192 | 193 | export class AlphaMaskFilter extends AbstractFilter { 194 | 195 | constructor(texture: Texture); 196 | 197 | map: Texture; 198 | 199 | onTextureLoaded(): void; 200 | 201 | } 202 | 203 | export class AsciiFilter extends AbstractFilter { 204 | 205 | size: number; 206 | 207 | } 208 | 209 | export class AssetLoader implements Mixin { 210 | 211 | assetURLs: string[]; 212 | crossorigin: boolean; 213 | loadersByType: { [key: string]: Loader }; 214 | 215 | constructor(assetURLs: string[], crossorigin: boolean); 216 | 217 | listeners(eventName: string): Function[]; 218 | emit(eventName: string, data?: any): boolean; 219 | dispatchEvent(eventName: string, data?: any): boolean; 220 | on(eventName: string, fn: Function): Function; 221 | addEventListener(eventName: string, fn: Function): Function; 222 | once(eventName: string, fn: Function): Function; 223 | off(eventName: string, fn: Function): Function; 224 | removeAllEventListeners(eventName: string): void; 225 | 226 | load(): void; 227 | 228 | 229 | } 230 | 231 | export class AtlasLoader implements Mixin { 232 | 233 | url: string; 234 | baseUrl: string; 235 | crossorigin: boolean; 236 | loaded: boolean; 237 | 238 | constructor(url: string, crossorigin: boolean); 239 | 240 | listeners(eventName: string): Function[]; 241 | emit(eventName: string, data?: any): boolean; 242 | dispatchEvent(eventName: string, data?: any): boolean; 243 | on(eventName: string, fn: Function): Function; 244 | addEventListener(eventName: string, fn: Function): Function; 245 | once(eventName: string, fn: Function): Function; 246 | off(eventName: string, fn: Function): Function; 247 | removeAllEventListeners(eventName: string): void; 248 | 249 | load(): void; 250 | 251 | } 252 | 253 | export class BaseTexture implements Mixin { 254 | 255 | static fromCanvas(canvas: HTMLCanvasElement, scaleMode?: scaleModes): BaseTexture; 256 | 257 | constructor(source: HTMLImageElement, scaleMode: scaleModes); 258 | constructor(source: HTMLCanvasElement, scaleMode: scaleModes); 259 | 260 | height: number; 261 | hasLoaded: boolean; 262 | mipmap: boolean; 263 | premultipliedAlpha: boolean; 264 | resolution: number; 265 | scaleMode: scaleModes; 266 | skipRender: boolean; 267 | source: HTMLImageElement; 268 | textureIndex: number; 269 | width: number; 270 | 271 | listeners(eventName: string): Function[]; 272 | emit(eventName: string, data?: any): boolean; 273 | dispatchEvent(eventName: string, data?: any): boolean; 274 | on(eventName: string, fn: Function): Function; 275 | addEventListener(eventName: string, fn: Function): Function; 276 | once(eventName: string, fn: Function): Function; 277 | off(eventName: string, fn: Function): Function; 278 | removeAllEventListeners(eventName: string): void; 279 | forceLoaded(width: number, height: number): void; 280 | destroy(): void; 281 | dirty(): void; 282 | unloadFromGPU(): void; 283 | 284 | } 285 | 286 | export class BitmapFontLoader implements Mixin { 287 | 288 | constructor(url: string, crossorigin: boolean); 289 | 290 | baseUrl: string; 291 | crossorigin: boolean; 292 | texture: Texture; 293 | url: string; 294 | 295 | listeners(eventName: string): Function[]; 296 | emit(eventName: string, data?: any): boolean; 297 | dispatchEvent(eventName: string, data?: any): boolean; 298 | on(eventName: string, fn: Function): Function; 299 | addEventListener(eventName: string, fn: Function): Function; 300 | once(eventName: string, fn: Function): Function; 301 | off(eventName: string, fn: Function): Function; 302 | removeAllEventListeners(eventName: string): void; 303 | 304 | load(): void; 305 | 306 | } 307 | 308 | export class BlurFilter extends AbstractFilter { 309 | 310 | blur: number; 311 | blurX: number; 312 | blurY: number; 313 | 314 | } 315 | 316 | export class BlurXFilter extends AbstractFilter { 317 | 318 | blur: number; 319 | 320 | } 321 | 322 | export class BlurYFilter extends AbstractFilter { 323 | 324 | blur: number; 325 | 326 | } 327 | 328 | export class CanvasBuffer { 329 | 330 | constructor(width: number, height: number); 331 | 332 | canvas: HTMLCanvasElement; 333 | context: CanvasRenderingContext2D; 334 | height: number; 335 | width: number; 336 | 337 | destroy(): void; 338 | clear(): void; 339 | resize(width: number, height: number): void; 340 | 341 | } 342 | 343 | export class CanvasPool { 344 | 345 | static create(parent: HTMLElement, width?: number, height?: number): HTMLCanvasElement; 346 | static getFirst(): HTMLCanvasElement; 347 | static remove(parent: HTMLElement): void; 348 | static removeByCanvas(canvas: HTMLCanvasElement): HTMLCanvasElement; 349 | static getTotal(): number; 350 | static getFree(): number; 351 | 352 | } 353 | 354 | export class CanvasMaskManager { 355 | 356 | pushMask(maskData: MaskData, renderSession: RenderSession): void; 357 | popMask(renderSession: RenderSession): void; 358 | 359 | } 360 | 361 | export class CanvasRenderer implements PixiRenderer { 362 | 363 | constructor(game: Phaser.Game); 364 | 365 | game: Phaser.Game; 366 | type: number; 367 | resolution: number; 368 | clearBeforeRender: boolean; 369 | transparent: boolean; 370 | autoResize: boolean; 371 | width: number; 372 | height: number; 373 | view: HTMLCanvasElement; 374 | context: CanvasRenderingContext2D; 375 | refresh: boolean; 376 | count: number; 377 | maskManager: CanvasMaskManager; 378 | renderSession: RenderSession; 379 | 380 | render(stage: DisplayObjectContainer): void; 381 | resize(width: number, height: number): void; 382 | destroy(removeView?: boolean): void; 383 | 384 | } 385 | 386 | export class CanvasTinter { 387 | 388 | static getTintedTexture(sprite: Sprite, color: number): HTMLCanvasElement; 389 | static tintWithMultiply(texture: Texture, color: number, canvas: HTMLCanvasElement): void; 390 | static tintWithOverlay(texture: Texture, color: number, canvas: HTMLCanvasElement): void; 391 | static tintWithPerPixel(texture: Texture, color: number, canvas: HTMLCanvasElement): void; 392 | 393 | static canUseMultiply: boolean; 394 | static tintMethod: any; 395 | 396 | } 397 | 398 | export class Circle implements HitArea { 399 | 400 | constructor(x: number, y: number, radius: number); 401 | 402 | x: number; 403 | y: number; 404 | radius: number; 405 | 406 | clone(): Circle; 407 | contains(x: number, y: number): boolean; 408 | getBounds(): Rectangle; 409 | 410 | } 411 | 412 | export class ColorMatrixFilter extends AbstractFilter { 413 | 414 | constructor(); 415 | 416 | matrix: number[]; 417 | 418 | } 419 | 420 | export class ColorStepFilter extends AbstractFilter { 421 | 422 | step: number; 423 | 424 | } 425 | 426 | export class ConvolutionFilter extends AbstractFilter { 427 | 428 | constructor(matrix: number[], width: number, height: number); 429 | 430 | matrix: Matrix; 431 | width: number; 432 | height: number; 433 | 434 | } 435 | 436 | export class CrossHatchFilter extends AbstractFilter { 437 | 438 | blur: number; 439 | 440 | } 441 | 442 | export class DisplacementFilter extends AbstractFilter { 443 | 444 | constructor(texture: Texture); 445 | 446 | map: Texture; 447 | offset: Point; 448 | scale: Point; 449 | 450 | } 451 | 452 | export class DotScreenFilter extends AbstractFilter { 453 | 454 | angle: number; 455 | scale: Point; 456 | 457 | } 458 | 459 | export class DisplayObject { 460 | 461 | alpha: number; 462 | buttonMode: boolean; 463 | cacheAsBitmap: boolean; 464 | defaultCursor: string; 465 | filterArea: Rectangle; 466 | filters: AbstractFilter[]; 467 | hitArea: HitArea; 468 | interactive: boolean; 469 | mask: Graphics; 470 | parent: DisplayObjectContainer; 471 | pivot: Point; 472 | position: Point; 473 | renderable: boolean; 474 | rotation: number; 475 | scale: Point; 476 | stage: DisplayObjectContainer; 477 | visible: boolean; 478 | worldAlpha: number; 479 | worldPosition: Point; 480 | worldScale: Point; 481 | worldTransform: Matrix; 482 | worldRotation: number; 483 | worldVisible: boolean; 484 | x: number; 485 | y: number; 486 | 487 | click(e: InteractionData): void; 488 | displayObjectUpdateTransform(parent?: DisplayObjectContainer): void; 489 | generateTexture(resolution?: number, scaleMode?: number, renderer?: PixiRenderer | number): RenderTexture; 490 | mousedown(e: InteractionData): void; 491 | mouseout(e: InteractionData): void; 492 | mouseover(e: InteractionData): void; 493 | mouseup(e: InteractionData): void; 494 | mousemove(e: InteractionData): void; 495 | mouseupoutside(e: InteractionData): void; 496 | rightclick(e: InteractionData): void; 497 | rightdown(e: InteractionData): void; 498 | rightup(e: InteractionData): void; 499 | rightupoutside(e: InteractionData): void; 500 | setStageReference(stage: DisplayObjectContainer): void; 501 | tap(e: InteractionData): void; 502 | toGlobal(position: Point): Point; 503 | toLocal(position: Point, from: DisplayObject): Point; 504 | touchend(e: InteractionData): void; 505 | touchendoutside(e: InteractionData): void; 506 | touchstart(e: InteractionData): void; 507 | touchmove(e: InteractionData): void; 508 | updateTransform(parent?: DisplayObjectContainer): void; 509 | 510 | } 511 | 512 | export class DisplayObjectContainer extends DisplayObject { 513 | 514 | constructor(); 515 | 516 | children: DisplayObject[]; 517 | height: number; 518 | width: number; 519 | ignoreChildInput: boolean; 520 | 521 | addChild(child: DisplayObject): DisplayObject; 522 | addChildAt(child: DisplayObject, index: number): DisplayObject; 523 | getBounds(targetCoordinateSpace?: DisplayObject | Matrix): Rectangle; 524 | getChildAt(index: number): DisplayObject; 525 | getChildIndex(child: DisplayObject): number; 526 | getLocalBounds(): Rectangle; 527 | removeChild(child: DisplayObject): DisplayObject; 528 | removeChildAt(index: number): DisplayObject; 529 | removeChildren(beginIndex?: number, endIndex?: number): DisplayObject[]; 530 | removeStageReference(): void; 531 | setChildIndex(child: DisplayObject, index: number): void; 532 | swapChildren(child: DisplayObject, child2: DisplayObject): void; 533 | contains(child: DisplayObject): boolean; 534 | 535 | } 536 | 537 | export class Ellipse implements HitArea { 538 | 539 | constructor(x: number, y: number, width: number, height: number); 540 | 541 | x: number; 542 | y: number; 543 | width: number; 544 | height: number; 545 | 546 | clone(): Ellipse; 547 | contains(x: number, y: number): boolean; 548 | getBounds(): Rectangle; 549 | 550 | } 551 | 552 | export class Event { 553 | 554 | constructor(target: any, name: string, data: any); 555 | 556 | target: any; 557 | type: string; 558 | data: any; 559 | timeStamp: number; 560 | 561 | stopPropagation(): void; 562 | preventDefault(): void; 563 | stopImmediatePropagation(): void; 564 | 565 | } 566 | 567 | export class EventTarget { 568 | 569 | static mixin(obj: any): void; 570 | 571 | } 572 | 573 | export class FilterTexture { 574 | 575 | constructor(gl: WebGLRenderingContext, width: number, height: number, scaleMode: scaleModes); 576 | 577 | fragmentSrc: string[]; 578 | frameBuffer: WebGLFramebuffer; 579 | gl: WebGLRenderingContext; 580 | program: WebGLProgram; 581 | scaleMode: number; 582 | texture: WebGLTexture; 583 | 584 | clear(): void; 585 | resize(width: number, height: number): void; 586 | destroy(): void; 587 | 588 | } 589 | 590 | export class GraphicsData { 591 | 592 | constructor(lineWidth?: number, lineColor?: number, lineAlpha?: number, fillColor?: number, fillAlpha?: number, fill?: boolean, shape?: any); 593 | 594 | lineWidth: number; 595 | lineColor: number; 596 | lineAlpha: number; 597 | fillColor: number; 598 | fillAlpha: number; 599 | fill: boolean; 600 | shape: any; 601 | type: number; 602 | 603 | } 604 | 605 | export class Graphics extends DisplayObjectContainer { 606 | 607 | static POLY: number; 608 | static RECT: number; 609 | static CIRC: number; 610 | static ELIP: number; 611 | static RREC: number; 612 | 613 | blendMode: number; 614 | boundsPadding: number; 615 | fillAlpha: number; 616 | isMask: boolean; 617 | lineWidth: number; 618 | lineColor: number; 619 | tint: number; 620 | worldAlpha: number; 621 | 622 | arc(cx: number, cy: number, radius: number, startAngle: number, endAngle: number, anticlockwise: boolean): Graphics; 623 | arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): Graphics; 624 | beginFill(color?: number, alpha?: number): Graphics; 625 | bezierCurveTo(cpX: number, cpY: number, cpX2: number, cpY2: number, toX: number, toY: number): Graphics; 626 | clear(): Graphics; 627 | destroyCachedSprite(): void; 628 | drawCircle(x: number, y: number, diameter: number): Graphics; 629 | drawEllipse(x: number, y: number, width: number, height: number): Graphics; 630 | drawPolygon(...path: any[]): Graphics; 631 | drawRect(x: number, y: number, width: number, height: number): Graphics; 632 | drawRoundedRect(x: number, y: number, width: number, height: number, radius: number): Graphics; 633 | drawShape(shape: Circle): GraphicsData; 634 | drawShape(shape: Rectangle): GraphicsData; 635 | drawShape(shape: Ellipse): GraphicsData; 636 | drawShape(shape: Polygon): GraphicsData; 637 | endFill(): Graphics; 638 | generateTexture(resolution?: number, scaleMode?: number, padding?: number): RenderTexture; 639 | lineStyle(lineWidth?: number, color?: number, alpha?: number): Graphics; 640 | lineTo(x: number, y: number): Graphics; 641 | moveTo(x: number, y: number): Graphics; 642 | quadraticCurveTo(cpX: number, cpY: number, toX: number, toY: number): Graphics; 643 | 644 | } 645 | 646 | export class GrayFilter extends AbstractFilter { 647 | 648 | gray: number; 649 | 650 | } 651 | 652 | export class ImageLoader implements Mixin { 653 | 654 | constructor(url: string, crossorigin?: boolean); 655 | 656 | texture: Texture; 657 | 658 | listeners(eventName: string): Function[]; 659 | emit(eventName: string, data?: any): boolean; 660 | dispatchEvent(eventName: string, data?: any): boolean; 661 | on(eventName: string, fn: Function): Function; 662 | addEventListener(eventName: string, fn: Function): Function; 663 | once(eventName: string, fn: Function): Function; 664 | off(eventName: string, fn: Function): Function; 665 | removeAllEventListeners(eventName: string): void; 666 | 667 | load(): void; 668 | loadFramedSpriteSheet(frameWidth: number, frameHeight: number, textureName: string): void; 669 | 670 | } 671 | 672 | export class InteractionData { 673 | 674 | global: Point; 675 | target: Sprite; 676 | originalEvent: Event; 677 | 678 | getLocalPosition(displayObject: DisplayObject, point?: Point, globalPos?: Point): Point; 679 | 680 | } 681 | 682 | export class InteractionManager { 683 | 684 | currentCursorStyle: string; 685 | last: number; 686 | mouse: InteractionData; 687 | mouseOut: boolean; 688 | mouseoverEnabled: boolean; 689 | onMouseMove: Function; 690 | onMouseDown: Function; 691 | onMouseOut: Function; 692 | onMouseUp: Function; 693 | onTouchStart: Function; 694 | onTouchEnd: Function; 695 | onTouchMove: Function; 696 | pool: InteractionData[]; 697 | resolution: number; 698 | stage: DisplayObjectContainer; 699 | touches: { [id: string]: InteractionData }; 700 | 701 | constructor(stage: DisplayObjectContainer); 702 | } 703 | 704 | export class InvertFilter extends AbstractFilter { 705 | 706 | invert: number; 707 | 708 | } 709 | 710 | export class JsonLoader implements Mixin { 711 | 712 | constructor(url: string, crossorigin?: boolean); 713 | 714 | baseUrl: string; 715 | crossorigin: boolean; 716 | loaded: boolean; 717 | url: string; 718 | 719 | listeners(eventName: string): Function[]; 720 | emit(eventName: string, data?: any): boolean; 721 | dispatchEvent(eventName: string, data?: any): boolean; 722 | on(eventName: string, fn: Function): Function; 723 | addEventListener(eventName: string, fn: Function): Function; 724 | once(eventName: string, fn: Function): Function; 725 | off(eventName: string, fn: Function): Function; 726 | removeAllEventListeners(eventName: string): void; 727 | 728 | load(): void; 729 | 730 | } 731 | 732 | export class Matrix { 733 | 734 | a: number; 735 | b: number; 736 | c: number; 737 | d: number; 738 | tx: number; 739 | ty: number; 740 | 741 | append(matrix: Matrix): Matrix; 742 | apply(pos: Point, newPos: Point): Point; 743 | applyInverse(pos: Point, newPos: Point): Point; 744 | determineMatrixArrayType(): number[]; 745 | identity(): Matrix; 746 | rotate(angle: number): Matrix; 747 | fromArray(array: number[]): void; 748 | translate(x: number, y: number): Matrix; 749 | toArray(transpose: boolean): number[]; 750 | scale(x: number, y: number): Matrix; 751 | 752 | } 753 | 754 | export interface Mixin { 755 | 756 | listeners(eventName: string): Function[]; 757 | emit(eventName: string, data?: any): boolean; 758 | dispatchEvent(eventName: string, data?: any): boolean; 759 | on(eventName: string, fn: Function): Function; 760 | addEventListener(eventName: string, fn: Function): Function; 761 | once(eventName: string, fn: Function): Function; 762 | off(eventName: string, fn: Function): Function; 763 | removeAllEventListeners(eventName: string): void; 764 | 765 | } 766 | 767 | export class NoiseFilter extends AbstractFilter { 768 | 769 | noise: number; 770 | 771 | } 772 | 773 | export class NormalMapFilter extends AbstractFilter { 774 | 775 | map: Texture; 776 | offset: Point; 777 | scale: Point; 778 | 779 | } 780 | 781 | export class PixelateFilter extends AbstractFilter { 782 | 783 | size: number; 784 | 785 | } 786 | 787 | export interface IPixiShader { 788 | 789 | fragmentSrc: string[]; 790 | gl: WebGLRenderingContext; 791 | program: WebGLProgram; 792 | vertexSrc: string[]; 793 | 794 | destroy(): void; 795 | init(): void; 796 | 797 | } 798 | 799 | export class PixiShader implements IPixiShader { 800 | 801 | constructor(gl: WebGLRenderingContext); 802 | 803 | attributes: ShaderAttribute[]; 804 | defaultVertexSrc: string[]; 805 | dirty: boolean; 806 | firstRun: boolean; 807 | textureCount: number; 808 | fragmentSrc: string[]; 809 | gl: WebGLRenderingContext; 810 | program: WebGLProgram; 811 | vertexSrc: string[]; 812 | 813 | initSampler2D(): void; 814 | initUniforms(): void; 815 | syncUniforms(): void; 816 | 817 | destroy(): void; 818 | init(): void; 819 | 820 | } 821 | 822 | export class PixiFastShader implements IPixiShader { 823 | 824 | constructor(gl: WebGLRenderingContext); 825 | 826 | textureCount: number; 827 | fragmentSrc: string[]; 828 | gl: WebGLRenderingContext; 829 | program: WebGLProgram; 830 | vertexSrc: string[]; 831 | 832 | destroy(): void; 833 | init(): void; 834 | 835 | } 836 | 837 | export class PrimitiveShader implements IPixiShader { 838 | 839 | constructor(gl: WebGLRenderingContext); 840 | fragmentSrc: string[]; 841 | gl: WebGLRenderingContext; 842 | program: WebGLProgram; 843 | vertexSrc: string[]; 844 | 845 | destroy(): void; 846 | init(): void; 847 | 848 | } 849 | 850 | export class ComplexPrimitiveShader implements IPixiShader { 851 | 852 | constructor(gl: WebGLRenderingContext); 853 | fragmentSrc: string[]; 854 | gl: WebGLRenderingContext; 855 | program: WebGLProgram; 856 | vertexSrc: string[]; 857 | 858 | destroy(): void; 859 | init(): void; 860 | 861 | } 862 | 863 | export class StripShader implements IPixiShader { 864 | 865 | constructor(gl: WebGLRenderingContext); 866 | fragmentSrc: string[]; 867 | gl: WebGLRenderingContext; 868 | program: WebGLProgram; 869 | vertexSrc: string[]; 870 | 871 | destroy(): void; 872 | init(): void; 873 | 874 | } 875 | 876 | export class Point { 877 | 878 | constructor(x?: number, y?: number); 879 | 880 | x: number; 881 | y: number; 882 | 883 | clone(): Point; 884 | set(x: number, y: number): void; 885 | 886 | } 887 | 888 | export class Polygon implements HitArea { 889 | 890 | constructor(points: Point[]); 891 | constructor(points: number[]); 892 | constructor(...points: Point[]); 893 | constructor(...points: number[]); 894 | 895 | points: any[]; 896 | 897 | clone(): Polygon; 898 | contains(x: number, y: number): boolean; 899 | 900 | } 901 | 902 | export class Rectangle implements HitArea { 903 | 904 | constructor(x?: number, y?: number, width?: number, height?: number); 905 | 906 | x: number; 907 | y: number; 908 | width: number; 909 | height: number; 910 | 911 | clone(): Rectangle; 912 | contains(x: number, y: number): boolean; 913 | 914 | } 915 | 916 | export class RGBSplitFilter extends AbstractFilter { 917 | 918 | red: Point; 919 | green: Point; 920 | blue: Point; 921 | 922 | } 923 | 924 | export class Rope extends Strip { 925 | 926 | points: Point[]; 927 | vertices: number[]; 928 | 929 | constructor(texture: Texture, points: Point[]); 930 | 931 | refresh(): void; 932 | setTexture(texture: Texture): void; 933 | 934 | } 935 | 936 | export class RoundedRectangle implements HitArea { 937 | 938 | constructor(x?: number, y?: number, width?: number, height?: number, radius?: number); 939 | 940 | x: number; 941 | y: number; 942 | width: number; 943 | height: number; 944 | radius: number; 945 | 946 | clone(): RoundedRectangle; 947 | contains(x: number, y: number): boolean; 948 | 949 | } 950 | 951 | export class SepiaFilter extends AbstractFilter { 952 | 953 | sepia: number; 954 | 955 | } 956 | 957 | export class SmartBlurFilter extends AbstractFilter { 958 | 959 | blur: number; 960 | 961 | } 962 | 963 | export class SpineLoader implements Mixin { 964 | 965 | url: string; 966 | crossorigin: boolean; 967 | loaded: boolean; 968 | 969 | constructor(url: string, crossOrigin: boolean); 970 | 971 | listeners(eventName: string): Function[]; 972 | emit(eventName: string, data?: any): boolean; 973 | dispatchEvent(eventName: string, data?: any): boolean; 974 | on(eventName: string, fn: Function): Function; 975 | addEventListener(eventName: string, fn: Function): Function; 976 | once(eventName: string, fn: Function): Function; 977 | off(eventName: string, fn: Function): Function; 978 | removeAllEventListeners(eventName: string): void; 979 | 980 | load(): void; 981 | 982 | } 983 | 984 | export class SpineTextureLoader { 985 | 986 | constructor(basePath: string, crossorigin: boolean); 987 | 988 | load(page: AtlasPage, file: string): void; 989 | unload(texture: BaseTexture): void; 990 | 991 | } 992 | 993 | export class Sprite extends DisplayObjectContainer { 994 | 995 | constructor(texture: Texture); 996 | 997 | anchor: Point; 998 | blendMode: blendModes; 999 | exists: boolean; 1000 | shader: IPixiShader; 1001 | texture: Texture; 1002 | tint: number; 1003 | 1004 | setTexture(texture: Texture, destroyBase?: boolean): void; 1005 | 1006 | } 1007 | 1008 | export class SpriteBatch extends DisplayObjectContainer { 1009 | 1010 | constructor(texture?: Texture); 1011 | 1012 | ready: boolean; 1013 | textureThing: Texture; 1014 | 1015 | initWebGL(gl: WebGLRenderingContext): void; 1016 | 1017 | } 1018 | 1019 | export class SpriteSheetLoader implements Mixin { 1020 | 1021 | constructor(url: string, crossorigin?: boolean); 1022 | 1023 | baseUrl: string; 1024 | crossorigin: boolean; 1025 | frames: any; 1026 | texture: Texture; 1027 | url: string; 1028 | 1029 | listeners(eventName: string): Function[]; 1030 | emit(eventName: string, data?: any): boolean; 1031 | dispatchEvent(eventName: string, data?: any): boolean; 1032 | on(eventName: string, fn: Function): Function; 1033 | addEventListener(eventName: string, fn: Function): Function; 1034 | once(eventName: string, fn: Function): Function; 1035 | off(eventName: string, fn: Function): Function; 1036 | removeAllEventListeners(eventName: string): void; 1037 | 1038 | load(): void; 1039 | 1040 | } 1041 | 1042 | export class Strip extends DisplayObjectContainer { 1043 | 1044 | static DrawModes: { 1045 | 1046 | TRIANGLE_STRIP: number; 1047 | TRIANGLES: number; 1048 | 1049 | }; 1050 | 1051 | constructor(texture: Texture); 1052 | 1053 | blendMode: number; 1054 | colors: number[]; 1055 | dirty: boolean; 1056 | indices: number[]; 1057 | canvasPadding: number; 1058 | texture: Texture; 1059 | uvs: number[]; 1060 | vertices: number[]; 1061 | 1062 | getBounds(matrix?: Matrix): Rectangle; 1063 | 1064 | } 1065 | 1066 | export class Texture implements Mixin { 1067 | 1068 | static emptyTexture: Texture; 1069 | 1070 | static fromCanvas(canvas: HTMLCanvasElement, scaleMode?: scaleModes): Texture; 1071 | 1072 | constructor(baseTexture: BaseTexture, frame?: Rectangle, crop?: Rectangle, trim?: Rectangle); 1073 | 1074 | baseTexture: BaseTexture; 1075 | crop: Rectangle; 1076 | frame: Rectangle; 1077 | height: number; 1078 | noFrame: boolean; 1079 | requiresUpdate: boolean; 1080 | trim: Point; 1081 | width: number; 1082 | scope: any; 1083 | valid: boolean; 1084 | rotated: boolean; 1085 | 1086 | listeners(eventName: string): Function[]; 1087 | emit(eventName: string, data?: any): boolean; 1088 | dispatchEvent(eventName: string, data?: any): boolean; 1089 | on(eventName: string, fn: Function): Function; 1090 | addEventListener(eventName: string, fn: Function): Function; 1091 | once(eventName: string, fn: Function): Function; 1092 | off(eventName: string, fn: Function): Function; 1093 | removeAllEventListeners(eventName: string): void; 1094 | 1095 | destroy(destroyBase: boolean): void; 1096 | setFrame(frame: Rectangle): void; 1097 | 1098 | } 1099 | 1100 | export class TilingSprite extends Sprite { 1101 | 1102 | constructor(texture: Texture, width: number, height: number); 1103 | 1104 | canvasBuffer: PIXI.CanvasBuffer; 1105 | blendMode: number; 1106 | refreshTexture: boolean; 1107 | texture: Texture; 1108 | textureDebug: boolean; 1109 | tint: number; 1110 | tilePosition: Point; 1111 | tilePattern: PIXI.Texture; 1112 | tileScale: Point; 1113 | tileScaleOffset: Point; 1114 | 1115 | destroy(): void; 1116 | generateTilingTexture(forcePowerOfTwo?: boolean): void; 1117 | setTexture(texture: Texture): void; 1118 | 1119 | } 1120 | 1121 | export class TiltShiftFilter extends AbstractFilter { 1122 | 1123 | blur: number; 1124 | gradientBlur: number; 1125 | start: number; 1126 | end: number; 1127 | 1128 | } 1129 | 1130 | export class TiltShiftXFilter extends AbstractFilter { 1131 | 1132 | blur: number; 1133 | gradientBlur: number; 1134 | start: number; 1135 | end: number; 1136 | 1137 | updateDelta(): void; 1138 | 1139 | } 1140 | 1141 | export class TiltShiftYFilter extends AbstractFilter { 1142 | 1143 | blur: number; 1144 | gradientBlur: number; 1145 | start: number; 1146 | end: number; 1147 | 1148 | updateDelta(): void; 1149 | 1150 | } 1151 | 1152 | export class TwistFilter extends AbstractFilter { 1153 | 1154 | angle: number; 1155 | offset: Point; 1156 | radius: number; 1157 | 1158 | } 1159 | 1160 | export class VideoTexture extends BaseTexture { 1161 | 1162 | static baseTextureFromVideo(video: HTMLVideoElement, scaleMode: number): BaseTexture; 1163 | static textureFromVideo(video: HTMLVideoElement, scaleMode: number): Texture; 1164 | static fromUrl(videoSrc: string, scaleMode?: number, autoPlay?: boolean, type?: string, loop?: boolean): Texture; 1165 | 1166 | controls: boolean; 1167 | autoUpdate: boolean; 1168 | type: string; 1169 | 1170 | changeSource(src: string, type: string, loop: boolean): void; 1171 | play(): void; 1172 | stop(): void; 1173 | 1174 | destroy(): void; 1175 | updateBound(): void; 1176 | onPlayStart: () => void; 1177 | onPlayStop: () => void; 1178 | onCanPlay: (event: any) => void; 1179 | 1180 | } 1181 | 1182 | export class WebGLBlendModeManager { 1183 | 1184 | currentBlendMode: number; 1185 | 1186 | destroy(): void; 1187 | setBlendMode(blendMode: number): boolean; 1188 | setContext(gl: WebGLRenderingContext): void; 1189 | 1190 | } 1191 | 1192 | export class WebGLFastSpriteBatch { 1193 | 1194 | constructor(gl: CanvasRenderingContext2D); 1195 | 1196 | currentBatchSize: number; 1197 | currentBaseTexture: BaseTexture; 1198 | currentBlendMode: number; 1199 | renderSession: RenderSession; 1200 | drawing: boolean; 1201 | indexBuffer: any; 1202 | indices: number[]; 1203 | lastIndexCount: number; 1204 | matrix: Matrix; 1205 | maxSize: number; 1206 | shader: IPixiShader; 1207 | size: number; 1208 | vertexBuffer: any; 1209 | vertices: number[]; 1210 | vertSize: number; 1211 | 1212 | end(): void; 1213 | begin(spriteBatch: SpriteBatch, renderSession: RenderSession): void; 1214 | destroy(removeView?: boolean): void; 1215 | flush(): void; 1216 | render(spriteBatch: SpriteBatch): void; 1217 | renderSprite(sprite: Sprite): void; 1218 | setContext(gl: WebGLRenderingContext): void; 1219 | start(): void; 1220 | stop(): void; 1221 | 1222 | } 1223 | 1224 | export class WebGLFilterManager { 1225 | 1226 | filterStack: AbstractFilter[]; 1227 | transparent: boolean; 1228 | offsetX: number; 1229 | offsetY: number; 1230 | 1231 | applyFilterPass(filter: AbstractFilter, filterArea: Texture, width: number, height: number): void; 1232 | begin(renderSession: RenderSession, buffer: ArrayBuffer): void; 1233 | destroy(): void; 1234 | initShaderBuffers(): void; 1235 | popFilter(): void; 1236 | pushFilter(filterBlock: FilterBlock): void; 1237 | setContext(gl: WebGLRenderingContext): void; 1238 | 1239 | } 1240 | 1241 | export class WebGLGraphics { 1242 | 1243 | static graphicsDataPool: any[]; 1244 | 1245 | static renderGraphics(graphics: Graphics, renderRession: RenderSession): void; 1246 | static updateGraphics(graphics: Graphics, gl: WebGLRenderingContext): void; 1247 | static switchMode(webGL: WebGLRenderingContext, type: number): any; 1248 | static buildRectangle(graphicsData: GraphicsData, webGLData: any): void; 1249 | static buildRoundedRectangle(graphicsData: GraphicsData, webGLData: any): void; 1250 | static quadraticBezierCurve(fromX: number, fromY: number, cpX: number, cpY: number, toX: number, toY: number): number[]; 1251 | static buildCircle(graphicsData: GraphicsData, webGLData: any): void; 1252 | static buildLine(graphicsData: GraphicsData, webGLData: any): void; 1253 | static buildComplexPoly(graphicsData: GraphicsData, webGLData: any): void; 1254 | static buildPoly(graphicsData: GraphicsData, webGLData: any): boolean; 1255 | 1256 | reset(): void; 1257 | upload(): void; 1258 | 1259 | } 1260 | 1261 | export class WebGLGraphicsData { 1262 | 1263 | constructor(gl: WebGLRenderingContext); 1264 | 1265 | gl: WebGLRenderingContext; 1266 | glPoints: any[]; 1267 | color: number[]; 1268 | points: any[]; 1269 | indices: any[]; 1270 | buffer: WebGLBuffer; 1271 | indexBuffer: WebGLBuffer; 1272 | mode: number; 1273 | alpha: number; 1274 | dirty: boolean; 1275 | 1276 | reset(): void; 1277 | upload(): void; 1278 | 1279 | } 1280 | 1281 | export class WebGLMaskManager { 1282 | 1283 | destroy(): void; 1284 | popMask(renderSession: RenderSession): void; 1285 | pushMask(maskData: any[], renderSession: RenderSession): void; 1286 | setContext(gl: WebGLRenderingContext): void; 1287 | 1288 | } 1289 | 1290 | export class WebGLRenderer implements PixiRenderer { 1291 | 1292 | static createWebGLTexture(texture: Texture, gl: WebGLRenderingContext): void; 1293 | 1294 | constructor(game: Phaser.Game); 1295 | 1296 | game: Phaser.Game; 1297 | type: number; 1298 | resolution: number; 1299 | transparent: boolean; 1300 | autoResize: boolean; 1301 | preserveDrawingBuffer: boolean; 1302 | clearBeforeRender: boolean; 1303 | width: number; 1304 | height: number; 1305 | currentBatchedTextures: string[]; 1306 | view: HTMLCanvasElement; 1307 | projection: Point; 1308 | offset: Point; 1309 | shaderManager: WebGLShaderManager; 1310 | spriteBatch: WebGLSpriteBatch; 1311 | maskManager: WebGLMaskManager; 1312 | filterManager: WebGLFilterManager; 1313 | stencilManager: WebGLStencilManager; 1314 | blendModeManager: WebGLBlendModeManager; 1315 | renderSession: RenderSession; 1316 | 1317 | initContext(): void; 1318 | render(stage: DisplayObjectContainer): void; 1319 | renderDisplayObject(displayObject: DisplayObject, projection: Point, buffer: WebGLBuffer): void; 1320 | resize(width: number, height: number): void; 1321 | updateTexture(texture: Texture): void; 1322 | destroy(): void; 1323 | mapBlendModes(): void; 1324 | setTexturePriority(textureNameCollection: string[]): string[]; 1325 | 1326 | } 1327 | 1328 | export class WebGLShaderManager { 1329 | 1330 | maxAttibs: number; 1331 | attribState: any[]; 1332 | stack: any[]; 1333 | tempAttribState: any[]; 1334 | 1335 | destroy(): void; 1336 | setAttribs(attribs: ShaderAttribute[]): void; 1337 | setContext(gl: WebGLRenderingContext): void; 1338 | setShader(shader: IPixiShader): boolean; 1339 | 1340 | } 1341 | 1342 | export class WebGLStencilManager { 1343 | 1344 | stencilStack: any[]; 1345 | reverse: boolean; 1346 | count: number; 1347 | 1348 | bindGraphics(graphics: Graphics, webGLData: any[], renderSession: RenderSession): void; 1349 | destroy(): void; 1350 | popStencil(graphics: Graphics, webGLData: any[], renderSession: RenderSession): void; 1351 | pushStencil(graphics: Graphics, webGLData: any[], renderSession: RenderSession): void; 1352 | setContext(gl: WebGLRenderingContext): void; 1353 | 1354 | } 1355 | 1356 | export class WebGLSpriteBatch { 1357 | 1358 | blendModes: number[]; 1359 | colors: number[]; 1360 | currentBatchSize: number; 1361 | currentBaseTexture: Texture; 1362 | defaultShader: AbstractFilter; 1363 | dirty: boolean; 1364 | drawing: boolean; 1365 | indices: number[]; 1366 | lastIndexCount: number; 1367 | positions: number[]; 1368 | textures: Texture[]; 1369 | shaders: IPixiShader[]; 1370 | size: number; 1371 | sprites: any[]; 1372 | vertices: number[]; 1373 | vertSize: number; 1374 | 1375 | begin(renderSession: RenderSession): void; 1376 | destroy(): void; 1377 | end(): void; 1378 | flush(shader?: IPixiShader): void; 1379 | render(sprite: Sprite): void; 1380 | renderBatch(texture: Texture, size: number, startIndex: number): void; 1381 | renderTilingSprite(sprite: TilingSprite): void; 1382 | setBlendMode(blendMode: blendModes): void; 1383 | setContext(gl: WebGLRenderingContext): void; 1384 | start(): void; 1385 | stop(): void; 1386 | 1387 | } 1388 | 1389 | export class RenderTexture extends Texture { 1390 | 1391 | constructor(width?: number, height?: number, renderer?: PixiRenderer, scaleMode?: scaleModes, resolution?: number); 1392 | 1393 | frame: Rectangle; 1394 | baseTexture: BaseTexture; 1395 | renderer: PixiRenderer; 1396 | resolution: number; 1397 | valid: boolean; 1398 | 1399 | clear(): void; 1400 | getBase64(): string; 1401 | getCanvas(): HTMLCanvasElement; 1402 | getImage(): HTMLImageElement; 1403 | resize(width: number, height: number, updateBase: boolean): void; 1404 | render(displayObject: DisplayObject, matrix?: Matrix, clear?: boolean): void; 1405 | 1406 | } 1407 | 1408 | // SPINE 1409 | 1410 | export class BoneData { 1411 | 1412 | constructor(name: string, parent?: any); 1413 | 1414 | name: string; 1415 | parent: any; 1416 | length: number; 1417 | x: number; 1418 | y: number; 1419 | rotation: number; 1420 | scaleX: number; 1421 | scaleY: number; 1422 | 1423 | } 1424 | 1425 | export class SlotData { 1426 | 1427 | constructor(name: string, boneData: BoneData); 1428 | 1429 | name: string; 1430 | boneData: BoneData; 1431 | r: number; 1432 | g: number; 1433 | b: number; 1434 | a: number; 1435 | attachmentName: string; 1436 | 1437 | } 1438 | 1439 | export class Bone { 1440 | 1441 | constructor(boneData: BoneData, parent?: any); 1442 | 1443 | data: BoneData; 1444 | parent: any; 1445 | yDown: boolean; 1446 | x: number; 1447 | y: number; 1448 | rotation: number; 1449 | scaleX: number; 1450 | scaleY: number; 1451 | worldRotation: number; 1452 | worldScaleX: number; 1453 | worldScaleY: number; 1454 | 1455 | updateWorldTransform(flipX: boolean, flip: boolean): void; 1456 | setToSetupPose(): void; 1457 | 1458 | } 1459 | 1460 | export class Slot { 1461 | 1462 | constructor(slotData: SlotData, skeleton: Skeleton, bone: Bone); 1463 | 1464 | data: SlotData; 1465 | skeleton: Skeleton; 1466 | bone: Bone; 1467 | r: number; 1468 | g: number; 1469 | b: number; 1470 | a: number; 1471 | attachment: RegionAttachment; 1472 | setAttachment(attachment: RegionAttachment): void; 1473 | setAttachmentTime(time: number): void; 1474 | getAttachmentTime(): number; 1475 | setToSetupPose(): void; 1476 | 1477 | } 1478 | 1479 | export class Skin { 1480 | 1481 | constructor(name: string); 1482 | 1483 | name: string; 1484 | attachments: any; 1485 | 1486 | addAttachment(slotIndex: number, name: string, attachment: RegionAttachment): void; 1487 | getAttachment(slotIndex: number, name: string): void; 1488 | 1489 | } 1490 | 1491 | export class Animation { 1492 | 1493 | constructor(name: string, timelines: ISpineTimeline[], duration: number); 1494 | 1495 | name: string; 1496 | timelines: ISpineTimeline[]; 1497 | duration: number; 1498 | apply(skeleton: Skeleton, time: number, loop: boolean): void; 1499 | min(skeleton: Skeleton, time: number, loop: boolean, alpha: number): void; 1500 | 1501 | } 1502 | 1503 | export class Curves { 1504 | 1505 | constructor(frameCount: number); 1506 | 1507 | curves: number[]; 1508 | 1509 | setLinear(frameIndex: number): void; 1510 | setStepped(frameIndex: number): void; 1511 | setCurve(frameIndex: number, cx1: number, cy1: number, cx2: number, cy2: number): void; 1512 | getCurvePercent(frameIndex: number, percent: number): number; 1513 | 1514 | } 1515 | 1516 | export interface ISpineTimeline { 1517 | 1518 | curves: Curves; 1519 | frames: number[]; 1520 | 1521 | getFrameCount(): number; 1522 | apply(skeleton: Skeleton, time: number, alpha: number): void; 1523 | 1524 | } 1525 | 1526 | export class RotateTimeline implements ISpineTimeline { 1527 | 1528 | constructor(frameCount: number); 1529 | 1530 | curves: Curves; 1531 | frames: number[]; 1532 | boneIndex: number; 1533 | 1534 | getFrameCount(): number; 1535 | setFrame(frameIndex: number, time: number, angle: number): void; 1536 | apply(skeleton: Skeleton, time: number, alpha: number): void; 1537 | 1538 | } 1539 | 1540 | export class TranslateTimeline implements ISpineTimeline { 1541 | 1542 | constructor(frameCount: number); 1543 | 1544 | curves: Curves; 1545 | frames: number[]; 1546 | boneIndex: number; 1547 | 1548 | getFrameCount(): number; 1549 | setFrame(frameIndex: number, time: number, x: number, y: number): void; 1550 | apply(skeleton: Skeleton, time: number, alpha: number): void; 1551 | 1552 | } 1553 | 1554 | export class ScaleTimeline implements ISpineTimeline { 1555 | 1556 | constructor(frameCount: number); 1557 | 1558 | curves: Curves; 1559 | frames: number[]; 1560 | boneIndex: number; 1561 | 1562 | getFrameCount(): number; 1563 | setFrame(frameIndex: number, time: number, x: number, y: number): void; 1564 | apply(skeleton: Skeleton, time: number, alpha: number): void; 1565 | 1566 | } 1567 | 1568 | export class ColorTimeline implements ISpineTimeline { 1569 | 1570 | constructor(frameCount: number); 1571 | 1572 | curves: Curves; 1573 | frames: number[]; 1574 | boneIndex: number; 1575 | 1576 | getFrameCount(): number; 1577 | setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number): void; 1578 | apply(skeleton: Skeleton, time: number, alpha: number): void; 1579 | 1580 | } 1581 | 1582 | export class AttachmentTimeline implements ISpineTimeline { 1583 | 1584 | constructor(frameCount: number); 1585 | 1586 | curves: Curves; 1587 | frames: number[]; 1588 | attachmentNames: string[]; 1589 | slotIndex: number; 1590 | 1591 | getFrameCount(): number; 1592 | setFrame(frameIndex: number, time: number, attachmentName: string): void; 1593 | apply(skeleton: Skeleton, time: number, alpha: number): void; 1594 | 1595 | } 1596 | 1597 | export class SkeletonData { 1598 | 1599 | bones: Bone[]; 1600 | slots: Slot[]; 1601 | skins: Skin[]; 1602 | animations: Animation[]; 1603 | defaultSkin: Skin; 1604 | 1605 | findBone(boneName: string): Bone; 1606 | findBoneIndex(boneName: string): number; 1607 | findSlot(slotName: string): Slot; 1608 | findSlotIndex(slotName: string): number; 1609 | findSkin(skinName: string): Skin; 1610 | findAnimation(animationName: string): Animation; 1611 | 1612 | } 1613 | 1614 | export class Skeleton { 1615 | 1616 | constructor(skeletonData: SkeletonData); 1617 | 1618 | data: SkeletonData; 1619 | bones: Bone[]; 1620 | slots: Slot[]; 1621 | drawOrder: any[]; 1622 | x: number; 1623 | y: number; 1624 | skin: Skin; 1625 | r: number; 1626 | g: number; 1627 | b: number; 1628 | a: number; 1629 | time: number; 1630 | flipX: boolean; 1631 | flipY: boolean; 1632 | 1633 | updateWorldTransform(): void; 1634 | setToSetupPose(): void; 1635 | setBonesToSetupPose(): void; 1636 | setSlotsToSetupPose(): void; 1637 | getRootBone(): Bone; 1638 | findBone(boneName: string): Bone; 1639 | fineBoneIndex(boneName: string): number; 1640 | findSlot(slotName: string): Slot; 1641 | findSlotIndex(slotName: string): number; 1642 | setSkinByName(skinName: string): void; 1643 | setSkin(newSkin: Skin): void; 1644 | getAttachmentBySlotName(slotName: string, attachmentName: string): RegionAttachment; 1645 | getAttachmentBySlotIndex(slotIndex: number, attachmentName: string): RegionAttachment; 1646 | setAttachment(slotName: string, attachmentName: string): void; 1647 | update(data: number): void; 1648 | 1649 | } 1650 | 1651 | export class RegionAttachment { 1652 | 1653 | offset: number[]; 1654 | uvs: number[]; 1655 | x: number; 1656 | y: number; 1657 | rotation: number; 1658 | scaleX: number; 1659 | scaleY: number; 1660 | width: number; 1661 | height: number; 1662 | rendererObject: any; 1663 | regionOffsetX: number; 1664 | regionOffsetY: number; 1665 | regionWidth: number; 1666 | regionHeight: number; 1667 | regionOriginalWidth: number; 1668 | regionOriginalHeight: number; 1669 | 1670 | setUVs(u: number, v: number, u2: number, v2: number, rotate: number): void; 1671 | updateOffset(): void; 1672 | computeVertices(x: number, y: number, bone: Bone, vertices: number[]): void; 1673 | 1674 | } 1675 | 1676 | export class AnimationStateData { 1677 | 1678 | constructor(skeletonData: SkeletonData); 1679 | 1680 | skeletonData: SkeletonData; 1681 | animationToMixTime: any; 1682 | defaultMix: number; 1683 | 1684 | setMixByName(fromName: string, toName: string, duration: number): void; 1685 | setMix(from: string, to: string): number; 1686 | 1687 | } 1688 | 1689 | export class AnimationState { 1690 | 1691 | constructor(stateData: any); 1692 | 1693 | animationSpeed: number; 1694 | current: any; 1695 | previous: any; 1696 | currentTime: number; 1697 | previousTime: number; 1698 | currentLoop: boolean; 1699 | previousLoop: boolean; 1700 | mixTime: number; 1701 | mixDuration: number; 1702 | queue: Animation[]; 1703 | 1704 | update(delta: number): void; 1705 | apply(skeleton: any): void; 1706 | clearAnimation(): void; 1707 | setAnimation(animation: any, loop: boolean): void; 1708 | setAnimationByName(animationName: string, loop: boolean): void; 1709 | addAnimationByName(animationName: string, loop: boolean, delay: number): void; 1710 | addAnimation(animation: any, loop: boolean, delay: number): void; 1711 | isComplete(): number; 1712 | 1713 | } 1714 | 1715 | export class SkeletonJson { 1716 | 1717 | constructor(attachmentLoader: AtlasAttachmentLoader); 1718 | 1719 | attachmentLoader: AtlasAttachmentLoader; 1720 | scale: number; 1721 | 1722 | readSkeletonData(root: any): SkeletonData; 1723 | readAttachment(skin: Skin, name: string, map: any): RegionAttachment; 1724 | readAnimation(name: string, map: any, skeletonData: SkeletonData): void; 1725 | readCurve(timeline: ISpineTimeline, frameIndex: number, valueMap: any): void; 1726 | toColor(hexString: string, colorIndex: number): number; 1727 | 1728 | } 1729 | 1730 | export class Atlas { 1731 | 1732 | static FORMAT: { 1733 | 1734 | alpha: number; 1735 | intensity: number; 1736 | luminanceAlpha: number; 1737 | rgb565: number; 1738 | rgba4444: number; 1739 | rgb888: number; 1740 | rgba8888: number; 1741 | 1742 | }; 1743 | 1744 | static TextureFilter: { 1745 | 1746 | nearest: number; 1747 | linear: number; 1748 | mipMap: number; 1749 | mipMapNearestNearest: number; 1750 | mipMapLinearNearest: number; 1751 | mipMapNearestLinear: number; 1752 | mipMapLinearLinear: number; 1753 | 1754 | }; 1755 | 1756 | static textureWrap: { 1757 | 1758 | mirroredRepeat: number; 1759 | clampToEdge: number; 1760 | repeat: number; 1761 | 1762 | }; 1763 | 1764 | constructor(atlasText: string, textureLoader: AtlasLoader); 1765 | 1766 | textureLoader: AtlasLoader; 1767 | pages: AtlasPage[]; 1768 | regions: AtlasRegion[]; 1769 | 1770 | findRegion(name: string): AtlasRegion; 1771 | dispose(): void; 1772 | updateUVs(page: AtlasPage): void; 1773 | 1774 | } 1775 | 1776 | export class AtlasPage { 1777 | 1778 | name: string; 1779 | format: number; 1780 | minFilter: number; 1781 | magFilter: number; 1782 | uWrap: number; 1783 | vWrap: number; 1784 | rendererObject: any; 1785 | width: number; 1786 | height: number; 1787 | 1788 | } 1789 | 1790 | export class AtlasRegion { 1791 | 1792 | page: AtlasPage; 1793 | name: string; 1794 | x: number; 1795 | y: number; 1796 | width: number; 1797 | height: number; 1798 | u: number; 1799 | v: number; 1800 | u2: number; 1801 | v2: number; 1802 | offsetX: number; 1803 | offsetY: number; 1804 | originalWidth: number; 1805 | originalHeight: number; 1806 | index: number; 1807 | rotate: boolean; 1808 | splits: any[]; 1809 | pads: any[]; 1810 | 1811 | } 1812 | 1813 | export class AtlasReader { 1814 | 1815 | constructor(text: string); 1816 | 1817 | lines: string[]; 1818 | index: number; 1819 | 1820 | trim(value: string): string; 1821 | readLine(): string; 1822 | readValue(): string; 1823 | readTuple(tuple: number): number; 1824 | 1825 | } 1826 | 1827 | export class AtlasAttachmentLoader { 1828 | 1829 | constructor(atlas: Atlas); 1830 | 1831 | atlas: Atlas; 1832 | 1833 | newAttachment(skin: Skin, type: number, name: string): RegionAttachment; 1834 | 1835 | } 1836 | 1837 | export class Spine extends DisplayObjectContainer { 1838 | 1839 | constructor(url: string); 1840 | 1841 | autoUpdate: boolean; 1842 | spineData: any; 1843 | skeleton: Skeleton; 1844 | stateData: AnimationStateData; 1845 | state: AnimationState; 1846 | slotContainers: DisplayObjectContainer[]; 1847 | 1848 | createSprite(slot: Slot, descriptor: { name: string }): Sprite[]; 1849 | update(dt: number): void; 1850 | 1851 | } 1852 | 1853 | } 1854 | 1855 | declare function requestAnimFrame(callback: Function): void; 1856 | 1857 | declare module PIXI.PolyK { 1858 | export function Triangulate(p: number[]): number[]; 1859 | } 1860 | --------------------------------------------------------------------------------