Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Niklas Berg 2018-02-23 23:45:11 +01:00
commit 25aa3263ed
120 changed files with 16978 additions and 16646 deletions

View file

@ -1,8 +1,10 @@
merge/Intro.js
merge/Outro.js
merge/plugins/path/
merge/physics/p2/p2.js
merge/animation/creature/
src/physics/matter-js/
src/renderer/webgl/renderers/shapebatch/earcut.js
webpack.*.js
src/phaser-arcade-physics.js
src/animations/config.json
src/physics/matter-js/lib/
src/physics/matter-js/poly-decomp/
src/polyfills/
src/renderer/webgl/shaders/
src/geom/polygon/Earcut.js
src/utils/array/StableSort.js
src/utils/object/Extend.js
src/structs/RTree.js

View file

@ -1,4 +1,5 @@
{
"root": true,
"env": {
"browser": true,
"es6": true,
@ -10,6 +11,7 @@
"CANVAS_RENDERER": true,
"Phaser": true,
"p2": true,
"process": true,
"ActiveXObject": true
},
"rules": {

View file

@ -14,7 +14,7 @@ Before contributing, please read the [code of conduct](https://github.com/photon
**3. Create an isolated and reproducible test case.** If you are reporting a bug, make sure you also have a minimal, runnable, code example that reproduces the problem you have.
**4. Include a live example.** After narrowing your code down to only the problem areas, make use of [jsFiddle][1], [jsBin][2], or a link to your live site so that we can view a live example of the problem.
**4. Include a live example.** After narrowing your code down to only the problem areas, make use of [jsFiddle][1], [jsBin][2], [CodePen][5], or a link to your live site so that we can view a live example of the problem.
**5. Share as much information as possible.** Include browser version affected, your OS, version of the library, steps to reproduce, etc. "X isn't working!!!1!" will probably just be closed.
@ -74,3 +74,4 @@ Thanks to Chad for creating the original Pixi.js Contributing file which we adap
[2]: http://jsbin.com/
[3]: http://nodejs.org
[4]: http://www.html5gamedevs.com/forum/14-phaser/
[5]: https://codepen.io/pen?template=YeEWom "Phaser 3 game template"

View file

@ -10,7 +10,7 @@ This Issue is about (delete as applicable)
* An error on the web site
* A problem with my own code
API errors must include example code showing what happens, and why you don't believe this is the expected behavior. Issues posted without code take _far_ longer to get resolved, _if ever_. Feel free to use a site such as jsbin to demo the problem. If we can run it, and see the error, we can usually fix it.
API errors must include example code showing what happens, and why you don't believe this is the expected behavior. Issues posted without code take _far_ longer to get resolved, _if ever_. Feel free to use a site such as jsBin or [CodePen](https://codepen.io/pen?template=YeEWom) to demo the problem. If we can run it, and see the error, we can usually fix it.
If your Issue contains _any_ form of hostility it will be instantly closed.

78
CHANGELOG.md Normal file
View file

@ -0,0 +1,78 @@
# Change Log
## Version 3.2.0 - In Development
### New Features
### Bug Fixes
### Updates
## Version 3.1.2 - 23rd February 2018
### Updates
* Hundreds of JSDoc fixes across the whole API.
* Tween.updateTweenData will now check to see if the Tween target still exists before trying to update its properties.
* If you try to use a local data URI in the Loader it now console warns instead of logs (thanks @samme)
### Bug Fixes
* The KeyCode `FORWAD_SLASH` had a typo and has been changed to `FORWARD_SLASH`. Fix #3271 (thanks @josedarioxyz)
* Fixed issue with vertex buffer creation on Static Tilemap Layer, causing tilemap layers to appear black. Fix #3266 (thanks @akleemans)
* Implemented Static Tilemap Layer scaling and Tile alpha support.
* Fixed issue with null texture on Particle Emitter batch generation. This would manifest if you had particles with blend modes on-top of other images not appearing.
* Added missing data parameter to ScenePlugin. Fixes #3810 (thanks @AleBles)
## Version 3.1.1 - 20th February 2018
### Updates
* The entire codebase now passes our eslint config (which helped highlight a few errors), if you're submitting a PR, please ensure your PR passes the config too.
* The Web Audio Context is now suspended instead of closed to allow for prevention of 'Failed to construct AudioContext: maximum number of hardware contexts reached' errors from Chrome in a hot reload environment. We still strongly recommend reusing the same context in a production environment. See [this example](http://labs.phaser.io/view.html?src=src%5Caudio%5CWeb%20Audio%5CReuse%20AudioContext.js) for details. Fixes #3238 (thanks @z0y1 @Ziao)
* The Webpack shell plugin now fires on `onBuildExit`, meaning it'll update the examples if you use `webpack watch` (thanks @rblopes)
* Added `root: true` flag to the eslint config to stop it scanning further-up the filesystem.
### Bug Fixes
* Math.Fuzzy.Floor had an incorrect method signature.
* Arcade Physics World didn't import GetOverlapX or GetOverlapY, causing `separateCircle` to break.
* TileSprite was missing a gl reference, causing it to fail during a context loss and restore.
* The Mesh Game Object Factory entry had incorrect arguments passed to Mesh constructor.
* Removed unused `_queue` property from `ScenePlugin` class (thanks @rblopes)
* The variable `static` is no longer used in Arcade Physics, fixing the 'static is a reserved word' in strict mode error (thanks @samme)
* Fixed `Set.union`, `Set.intersect` and `Set.difference` (thanks @yupaul)
* The corner tints were being applied in the wrong order. Fixes #3252 (thanks @Rybar)
* BitmapText objects would ignore calls to setOrigin. Fixes #3249 (thanks @amkazan)
* Fixed a 1px camera jitter and bleeding issue in the renderer. Fixes #3245 (thanks @bradharms)
* Fixed the error `WebGL: INVALID_ENUM: blendEquation: invalid mode.` that would arise on iOS. Fixes #3244 (thanks @Ziao)
* The `drawBlitter` function would crash if `roundPixels` was true. Fixes #3243 (thanks @Jerenaux and @vulcanoidlogic)
## Version 3.1.0 - Onishi - 16th February 2018
### Updates
* Vertex resource handling code updated, further optimizing the WebGL batching. You should now see less gl ops per frame across all batches.
* The `Blitter` game object has been updated to use the `List` structure instead of `DisplayList`.
* Arcade Physics World `disableBody` has been renamed `disableGameObjectBody` to more accurately reflect what it does.
* Lots of un-used properties were removed from the Arcade Physics Static Body object.
* Arcade Physics Static Body can now refresh itself from its parent via `refreshBody`.
### Bug Fixes
* A couple of accidental uses of `let` existed, which broke Image loading in Safari # (thanks Yat Hin Wong)
* Added the static property `Graphics.TargetCamera` was added back in which fixed `Graphics.generateTexture`.
* The SetHitArea Action now calls `setInteractive`, fixing `Group.createMultiple` when a hitArea has been set.
* Removed rogue Tween emit calls. Fix #3222 (thanks @ZaDarkSide)
* Fixed incorrect call to TweenManager.makeActive. Fix #3219 (thanks @ZaDarkSide)
* The Depth component was missing from the Zone Game Object. Fix #3213 (thanks @Twilrom)
* Fixed issue with `Blitter` overwriting previous objects vertex data.
* The `Tile` game object tinting was fixed, so tiles now honor alpha values correctly.
* The `BitmapMask` would sometimes incorrectly bind its resources.
* Fixed the wrong Extend target in MergeXHRSettings (thanks @samme)
### New Features
* Destroying a Game Object will now call destroy on its physics body, if it has one set.
* Arcade Physics Colliders have a new `name` property and corresponding `setName` method.
* Matter.js bodies now have an inlined destroy method that removes them from the World.
* Impact bodies now remove themselves from the World when destroyed.
* Added Vector2.ZERO static property.

View file

@ -11,7 +11,7 @@ Along with the fantastic open source community, Phaser is actively developed and
Thousands of developers worldwide use Phaser. From indies and multi-national digital agencies, to schools and Universities. Each creating their own incredible [games](https://phaser.io/games/).
**Visit:** The [Phaser website](https://phaser.io) and follow on [Twitter](https://twitter.com/phaser_) (#phaserjs)<br />
**Learn:** [API Docs](https://phaser.io/docs), [Support Forum][forum] and [StackOverflow](https://stackoverflow.com/questions/tagged/phaser-framework)<br />
**Learn:** [API Docs](https://github.com/photonstorm/phaser3-docs), [Support Forum][forum] and [StackOverflow](https://stackoverflow.com/questions/tagged/phaser-framework)<br />
**Code:** 700+ [Examples](https://labs.phaser.io) (source available in this [repo][examples])<br />
**Read:** Weekly [Phaser World](#newsletter) Newsletter<br />
**Chat:** [Slack](https://phaser.io/community/slack) and [Discord](https://phaser.io/community/discord)<br />
@ -24,7 +24,9 @@ Grab the source and join in the fun!
<div align="center"><img src="https://phaser.io/images/github/news.jpg"></div>
> 12th February 2018
> 23rd February 2018
**Updated:** Thank you for the continued amazing response to the 3.0.0 release! We've carried on working hard and now prepared 3.1.2 for you, which is available today. Check out the [Change Log](#changelog) for more details.
After 1.5 years in the making, tens of thousands of lines of code, hundreds of examples and countless hours of relentless work: Phaser 3 is finally out. It has been a real labor of love and then some!
@ -92,13 +94,13 @@ npm install phaser
[Phaser is on jsDelivr](http://www.jsdelivr.com/projects/phaser), a "super-fast CDN for developers". Include the following in your html:
```html
<script src="//cdn.jsdelivr.net/npm/phaser@3.0.0/dist/phaser.js"></script>
<script src="//cdn.jsdelivr.net/npm/phaser@3.1.2/dist/phaser.js"></script>
```
or the minified version:
```html
<script src="//cdn.jsdelivr.net/npm/phaser@3.0.0/dist/phaser.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/phaser@3.1.2/dist/phaser.min.js"></script>
```
### License
@ -110,7 +112,13 @@ Phaser is released under the [MIT License](https://opensource.org/licenses/MIT).
<img src="https://phaser.io/images/github/learn.jpg" align="right">
Phaser 3 is so brand new the paint is still wet. As such we don't yet have any guides or tutorials! This will change in the coming weeks and we'll update this area as they emerge. For now, please subscribe to the [Phaser World](https://phaser.io/community/newsletter) newsletter as we'll publish them in there first.
Phaser 3 is so brand new the paint is still wet, but tutorials and guides are starting to come out!
* [Getting Started with Phaser 3](https://phaser.io/tutorials/getting-started-phaser3) (useful if you are completely new to Phaser)
* [Making your first Phaser 3 Game](https://phaser.io/tutorials/making-your-first-phaser-3-game)
* [Phaser 3 Bootstrap and Platformer Example](https://phaser.io/news/2018/02/phaser-3-bootstrap-platformer)
Also, please subscribe to the [Phaser World](https://phaser.io/community/newsletter) newsletter for details about new tutorials as they are published.
### Source Code Examples
@ -229,8 +237,25 @@ Should you wish to build Phaser 3 from source ensure you have the required packa
You can then run `webpack` to perform a dev build to the `build` folder, including source maps for local testing, or run `npm run dist` to create a minified packaged build into the `dist` folder.
![Change Log](https://phaser.io/images/github/div-change-log.png "Change Log")
<a name="changelog"></a>
We have always been meticulous in recording changes to the Phaser code base, and where relevant, giving attribution to those in the community who helped. This is something we'll continue with Phaser 3 and you'll see this section expand as we push through the 3.0.0 releases.
## Version 3.1.2 - 23rd February 2018
### Updates
* Hundreds of JSDoc fixes across the whole API.
* Tween.updateTweenData will now check to see if the Tween target still exists before trying to update its properties.
* If you try to use a local data URI in the Loader it now console warns instead of logs (thanks @samme)
### Bug Fixes
* The KeyCode `FORWAD_SLASH` had a typo and has been changed to `FORWAD_SLASH`. Fix #3271 (thanks @josedarioxyz)
* Fixed issue with vertex buffer creation on Static Tilemap Layer, causing tilemap layers to appear black. Fix #3266 (thanks @akleemans)
* Implemented Static Tilemap Layer scaling and Tile alpha support.
* Fixed issue with null texture on Particle Emitter batch generation. This would manifest if you had particles with blend modes on-top of other images not appearing.
* Added missing data parameter to ScenePlugin. Fixes #3810 (thanks @AleBles)
Please see the complete [Change Log]((https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md)) for previous releases.
Looking for a v2 change? Check out the [Phaser CE Change Log](https://github.com/photonstorm/phaser-ce/blob/master/CHANGELOG.md)
@ -261,8 +286,8 @@ All rights reserved.
"Above all, video games are meant to be just one thing: fun. Fun for everyone." - Satoru Iwata
[get-js]: https://github.com/photonstorm/phaser/releases/download/v3.0.0/phaser.js
[get-minjs]: https://github.com/photonstorm/phaser/releases/download/v3.0.0/phaser.min.js
[get-js]: https://github.com/photonstorm/phaser/releases/download/v3.1.2/phaser.js
[get-minjs]: https://github.com/photonstorm/phaser/releases/download/v3.1.2/phaser.min.js
[clone-http]: https://github.com/photonstorm/phaser.git
[clone-ssh]: git@github.com:photonstorm/phaser.git
[clone-ghwin]: github-windows://openRepo/https://github.com/photonstorm/phaser

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

15247
dist/phaser.js vendored

File diff suppressed because it is too large Load diff

2
dist/phaser.min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -1,7 +1,7 @@
{
"name": "phaser",
"version": "3.0.0",
"release": "Kaneda",
"version": "3.2.0",
"release": "Kaori",
"description": "A fast, free and fun HTML5 Game Framework for Desktop and Mobile web browsers.",
"author": "Richard Davey <rich@photonstorm.com> (http://www.photonstorm.com)",
"logo": "https://raw.github.com/photonstorm/phaser/master/phaser-logo-small.png",

View file

@ -32,6 +32,7 @@ var GridAlign = function (items, options)
var position = GetValue(options, 'position', CONST.TOP_LEFT);
var x = GetValue(options, 'x', 0);
var y = GetValue(options, 'y', 0);
// var centerX = GetValue(options, 'centerX', null);
// var centerY = GetValue(options, 'centerY', null);
@ -43,7 +44,7 @@ var GridAlign = function (items, options)
// If the Grid is centered on a position then we need to calculate it now
// if (centerX !== null && centerY !== null)
// {
//
//
// }
tempZone.setPosition(x, y);

View file

@ -54,7 +54,7 @@ var Animation = new Class({
/**
* A frame based animation (as opposed to a bone based animation)
*
* @name Phaser.Animations.Animation#key
* @name Phaser.Animations.Animation#type
* @type {string}
* @default frame
* @since 3.0.0

View file

@ -161,7 +161,7 @@ var PluginManager = new Class({
* Plugin is the object to instantiate to create the plugin
* Mapping is what the plugin is injected into the Scene.Systems as (i.e. input)
*
* @name PluginManager.register
* @method PluginManager.register
* @since 3.0.0
*
* @param {string} key - [description]

View file

@ -1323,6 +1323,12 @@ var Camera = new Class({
{
this._shakeOffsetX = (Math.random() * intensity * this.width * 2 - intensity * this.width) * this.zoom;
this._shakeOffsetY = (Math.random() * intensity * this.height * 2 - intensity * this.height) * this.zoom;
if (this.roundPixels)
{
this._shakeOffsetX |= 0;
this._shakeOffsetY |= 0;
}
}
}
},

View file

@ -54,7 +54,7 @@ var Camera = new Class({
* [description]
*
* @name Phaser.Cameras.Sprite3D#displayList
* @type {[type]}
* @type {Phaser.GameObjects.DisplayList}
* @since 3.0.0
*/
this.displayList = scene.sys.displayList;
@ -63,7 +63,7 @@ var Camera = new Class({
* [description]
*
* @name Phaser.Cameras.Sprite3D#updateList
* @type {[type]}
* @type {Phaser.GameObjects.UpdateList}
* @since 3.0.0
*/
this.updateList = scene.sys.updateList;
@ -892,8 +892,8 @@ var Camera = new Class({
{
if (out === undefined) { out = new Vector2(); }
//TODO: optimize this with a simple distance calculation:
//https://developer.valvesoftware.com/wiki/Field_of_View
// TODO: optimize this with a simple distance calculation:
// https://developer.valvesoftware.com/wiki/Field_of_View
if (this.billboardMatrixDirty)
{

View file

@ -29,7 +29,7 @@ var CameraManager = new Class({
/**
* [description]
*
* @name Phaser.Cameras.Sprite3D#scene
* @name Phaser.Cameras.Sprite3D.CameraManager#scene
* @type {Phaser.Scene}
* @since 3.0.0
*/
@ -38,7 +38,7 @@ var CameraManager = new Class({
/**
* [description]
*
* @name Phaser.Cameras.Sprite3D#systems
* @name Phaser.Cameras.Sprite3D.CameraManager#systems
* @type {Phaser.Scenes.Systems}
* @since 3.0.0
*/
@ -47,7 +47,7 @@ var CameraManager = new Class({
/**
* An Array of the Camera objects being managed by this Camera Manager.
*
* @name Phaser.Cameras.Sprite3D#cameras
* @name Phaser.Cameras.Sprite3D.CameraManager#cameras
* @type {array}
* @since 3.0.0
*/
@ -97,8 +97,8 @@ var CameraManager = new Class({
* @method Phaser.Cameras.Sprite3D.CameraManager#addOrthographicCamera
* @since 3.0.0
*
* @param {[type]} width - [description]
* @param {[type]} height - [description]
* @param {number} width - [description]
* @param {number} height - [description]
*
* @return {[type]} [description]
*/
@ -122,9 +122,9 @@ var CameraManager = new Class({
* @method Phaser.Cameras.Sprite3D.CameraManager#addPerspectiveCamera
* @since 3.0.0
*
* @param {[type]} fieldOfView - [description]
* @param {[type]} width - [description]
* @param {[type]} height - [description]
* @param {number} [fieldOfView=80] - [description]
* @param {number} [width] - [description]
* @param {number} [height] - [description]
*
* @return {[type]} [description]
*/
@ -149,7 +149,7 @@ var CameraManager = new Class({
* @method Phaser.Cameras.Sprite3D.CameraManager#getCamera
* @since 3.0.0
*
* @param {[type]} name - [description]
* @param {string} name - [description]
*
* @return {[type]} [description]
*/
@ -210,8 +210,8 @@ var CameraManager = new Class({
* @method Phaser.Cameras.Sprite3D.CameraManager#update
* @since 3.0.0
*
* @param {[type]} timestep - [description]
* @param {[type]} delta - [description]
* @param {number} timestep - [description]
* @param {number} delta - [description]
*/
update: function (timestep, delta)
{

View file

@ -13,7 +13,7 @@ var CONST = {
* @type {string}
* @since 3.0.0
*/
VERSION: '3.0.0',
VERSION: '3.2.0',
BlendModes: require('./renderer/BlendModes'),

View file

@ -117,11 +117,8 @@ function init ()
// Can't be done on a webgl context
var image = ctx2D.createImageData(1, 1);
/**
* Test to see if ImageData uses CanvasPixelArray or Uint8ClampedArray.
*
* @author Matt DesLauriers (@mattdesl)
*/
// Test to see if ImageData uses CanvasPixelArray or Uint8ClampedArray.
// @author Matt DesLauriers (@mattdesl)
isUint8 = image.data instanceof Uint8ClampedArray;
CanvasPool.remove(canvas);

View file

@ -89,7 +89,7 @@ var BitmapMask = new Class({
* [description]
*
* @name Phaser.Display.Masks.BitmapMask#mainFramebuffer
* @type {[type]}
* @type {WebGLFramebuffer}
* @since 3.0.0
*/
this.mainFramebuffer = null;
@ -98,11 +98,20 @@ var BitmapMask = new Class({
* [description]
*
* @name Phaser.Display.Masks.BitmapMask#maskFramebuffer
* @type {[type]}
* @type {WebGLFramebuffer}
* @since 3.0.0
*/
this.maskFramebuffer = null;
/**
* [description]
*
* @name Phaser.Display.Masks.BitmapMask#invertAlpha
* @type {boolean}
* @since 3.1.2
*/
this.invertAlpha = false;
if (renderer.gl)
{
var width = renderer.width;
@ -186,7 +195,7 @@ var BitmapMask = new Class({
* @param {[type]} mask - [description]
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera to render to.
*/
preRenderCanvas: function (renderer, mask, camera)
preRenderCanvas: function ()
{
// NOOP
},
@ -199,7 +208,7 @@ var BitmapMask = new Class({
*
* @param {[type]} renderer - [description]
*/
postRenderCanvas: function (renderer)
postRenderCanvas: function ()
{
// NOOP
}

View file

@ -10,7 +10,7 @@
module.exports = {
BitmapMask: require('./BitmapMask'),
GeometryMask: require('./GeometryMask')
BitmapMask: require('./BitmapMask'),
GeometryMask: require('./GeometryMask')
};

View file

@ -128,7 +128,7 @@ var UpdateList = new Class({
* @param {number} time - [description]
* @param {number} delta - [description]
*/
preUpdate: function (time, delta)
preUpdate: function ()
{
var toRemove = this._pendingRemoval.length;
var toInsert = this._pendingInsertion.length;
@ -153,9 +153,6 @@ var UpdateList = new Class({
{
this._list.splice(index, 1);
}
// Pool them?
// gameObject.destroy();
}
// Move pending to active

View file

@ -114,76 +114,76 @@ var ParseRetroFont = function (scene, config)
* @constant
* @type {string}
*/
ParseRetroFont.TEXT_SET1 = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
ParseRetroFont.TEXT_SET1 = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
/**
* Text Set 2 = !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ
* @constant
* @type {string}
*/
ParseRetroFont.TEXT_SET2 = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ";
ParseRetroFont.TEXT_SET2 = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ';
/**
* Text Set 3 = ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
* @constant
* @type {string}
*/
ParseRetroFont.TEXT_SET3 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
ParseRetroFont.TEXT_SET3 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ';
/**
* Text Set 4 = ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789
* @constant
* @type {string}
*/
ParseRetroFont.TEXT_SET4 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789";
ParseRetroFont.TEXT_SET4 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789';
/**
* Text Set 5 = ABCDEFGHIJKLMNOPQRSTUVWXYZ.,/() '!?-*:0123456789
* @constant
* @type {string}
*/
ParseRetroFont.TEXT_SET5 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ.,/() '!?-*:0123456789";
ParseRetroFont.TEXT_SET5 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ.,/() \'!?-*:0123456789';
/**
* Text Set 6 = ABCDEFGHIJKLMNOPQRSTUVWXYZ!?:;0123456789"(),-.'
* @constant
* @type {string}
*/
ParseRetroFont.TEXT_SET6 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!?:;0123456789\"(),-.' ";
ParseRetroFont.TEXT_SET6 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ!?:;0123456789"(),-.\' ';
/**
* Text Set 7 = AGMSY+:4BHNTZ!;5CIOU.?06DJPV,(17EKQW")28FLRX-'39
* @constant
* @type {string}
*/
ParseRetroFont.TEXT_SET7 = "AGMSY+:4BHNTZ!;5CIOU.?06DJPV,(17EKQW\")28FLRX-'39";
ParseRetroFont.TEXT_SET7 = 'AGMSY+:4BHNTZ!;5CIOU.?06DJPV,(17EKQW")28FLRX-\'39';
/**
* Text Set 8 = 0123456789 .ABCDEFGHIJKLMNOPQRSTUVWXYZ
* @constant
* @type {string}
*/
ParseRetroFont.TEXT_SET8 = "0123456789 .ABCDEFGHIJKLMNOPQRSTUVWXYZ";
ParseRetroFont.TEXT_SET8 = '0123456789 .ABCDEFGHIJKLMNOPQRSTUVWXYZ';
/**
* Text Set 9 = ABCDEFGHIJKLMNOPQRSTUVWXYZ()-0123456789.:,'"?!
* @constant
* @type {string}
*/
ParseRetroFont.TEXT_SET9 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ()-0123456789.:,'\"?!";
ParseRetroFont.TEXT_SET9 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ()-0123456789.:,\'"?!';
/**
* Text Set 10 = ABCDEFGHIJKLMNOPQRSTUVWXYZ
* @constant
* @type {string}
*/
ParseRetroFont.TEXT_SET10 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
ParseRetroFont.TEXT_SET10 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
/**
* Text Set 11 = ABCDEFGHIJKLMNOPQRSTUVWXYZ.,"-+!?()':;0123456789
* @constant
* @type {string}
*/
ParseRetroFont.TEXT_SET11 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ.,\"-+!?()':;0123456789";
ParseRetroFont.TEXT_SET11 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ.,"-+!?()\':;0123456789';
module.exports = ParseRetroFont;

View file

@ -25,10 +25,6 @@ var ParseXMLBitmapFont = function (xml, xSpacing, ySpacing, frame)
var letters = xml.getElementsByTagName('char');
var x = 0;
var y = 0;
var cx = 0;
var cy = 0;
var adjustForTrim = (frame !== undefined && frame.trimmed);
if (adjustForTrim)
@ -37,8 +33,6 @@ var ParseXMLBitmapFont = function (xml, xSpacing, ySpacing, frame)
var left = frame.width;
}
var diff = 0;
for (var i = 0; i < letters.length; i++)
{
var node = letters[i];
@ -53,18 +47,6 @@ var ParseXMLBitmapFont = function (xml, xSpacing, ySpacing, frame)
if (adjustForTrim)
{
// if (gx + gw > frame.width)
// {
// diff = frame.width - (gx + gw);
// gw -= diff;
// }
// if (gy + gh > frame.height)
// {
// diff = frame.height - (gy + gh);
// gh -= diff;
// }
if (gx < left)
{
left = gx;

View file

@ -90,6 +90,7 @@ var DynamicBitmapTextCanvasRenderer = function (renderer, src, interpolationPerc
ctx.save();
ctx.translate(src.x, src.y);
ctx.rotate(src.rotation);
ctx.translate(-src.displayOriginX, -src.displayOriginY);
ctx.scale(src.scaleX, src.scaleY);
if (src.cropWidth > 0 && src.cropHeight > 0)

View file

@ -62,7 +62,6 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage,
var textureX = textureFrame.cutX;
var textureY = textureFrame.cutY;
var rotation = 0;
var scale = (src.fontSize / src.fontData.size);
// Blend Mode
@ -88,6 +87,7 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage,
ctx.save();
ctx.translate((src.x - cameraScrollX) + src.frame.x, (src.y - cameraScrollY) + src.frame.y);
ctx.rotate(src.rotation);
ctx.translate(-src.displayOriginX, -src.displayOriginY);
ctx.scale(src.scaleX, src.scaleY);
// ctx.fillStyle = 'rgba(255,0,255,0.5)';
@ -144,6 +144,7 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage,
ctx.save();
ctx.translate(x, y);
ctx.scale(scale, scale);
// ctx.fillRect(0, 0, glyphW, glyphH);
ctx.drawImage(image, glyphX, glyphY, glyphW, glyphH, 0, 0, glyphW, glyphH);
ctx.restore();

View file

@ -27,6 +27,7 @@ GameObjectCreator.register('bitmapText', function (config)
var font = GetValue(config, 'font', '');
var text = GetAdvancedValue(config, 'text', '');
var size = GetAdvancedValue(config, 'size', false);
// var align = GetValue(config, 'align', 'left');
var bitmapText = new BitmapText(this.scene, 0, 0, font, text, size);

View file

@ -31,7 +31,6 @@ var BlitterCanvasRenderer = function (renderer, src, interpolationPercentage, ca
renderer.setBlendMode(src.blendMode);
var ca = renderer.currentAlpha;
var ctx = renderer.gameContext;
var cameraScrollX = src.x - camera.scrollX * src.scrollFactorX;
var cameraScrollY = src.y - camera.scrollY * src.scrollFactorY;

View file

@ -658,8 +658,8 @@ var Animation = new Class({
return this;
},
// Scale the time (make it go faster / slower)
// Factor that's used to scale time where 1 = normal speed (the default), 0.5 = half speed, 2 = double speed, etc.
// Scale the time (make it go faster / slower)
// Factor that's used to scale time where 1 = normal speed (the default), 0.5 = half speed, 2 = double speed, etc.
/**
* [description]

View file

@ -0,0 +1,146 @@
var MatrixStack = {
matrixStack: null,
currentMatrix: null,
currentMatrixIndex: 0,
initMatrixStack: function ()
{
this.matrixStack = new Float32Array(6000); // up to 1000 matrices
this.currentMatrix = new Float32Array([1.0, 0.0, 0.0, 1.0, 0.0, 0.0]);
this.currentMatrixIndex = 0;
return this;
},
save: function ()
{
if (this.currentMatrixIndex >= this.matrixStack.length) return this;
var matrixStack = this.matrixStack;
var currentMatrix = this.currentMatrix;
var currentMatrixIndex = this.currentMatrixIndex;
this.currentMatrixIndex += 6;
matrixStack[currentMatrixIndex + 0] = currentMatrix[0];
matrixStack[currentMatrixIndex + 1] = currentMatrix[1];
matrixStack[currentMatrixIndex + 2] = currentMatrix[2];
matrixStack[currentMatrixIndex + 3] = currentMatrix[3];
matrixStack[currentMatrixIndex + 4] = currentMatrix[4];
matrixStack[currentMatrixIndex + 5] = currentMatrix[5];
return this;
},
restore: function ()
{
if (this.currentMatrixIndex <= 0) return this;
this.currentMatrixIndex -= 6;
var matrixStack = this.matrixStack;
var currentMatrix = this.currentMatrix;
var currentMatrixIndex = this.currentMatrixIndex;
currentMatrix[0] = matrixStack[currentMatrixIndex + 0];
currentMatrix[1] = matrixStack[currentMatrixIndex + 1];
currentMatrix[2] = matrixStack[currentMatrixIndex + 2];
currentMatrix[3] = matrixStack[currentMatrixIndex + 3];
currentMatrix[4] = matrixStack[currentMatrixIndex + 4];
currentMatrix[5] = matrixStack[currentMatrixIndex + 5];
return this;
},
loadIdentity: function ()
{
this.setTransform(1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
return this;
},
transform: function (a, b, c, d, tx, ty)
{
var currentMatrix = this.currentMatrix;
var m0 = currentMatrix[0];
var m1 = currentMatrix[1];
var m2 = currentMatrix[2];
var m3 = currentMatrix[3];
var m4 = currentMatrix[4];
var m5 = currentMatrix[5];
currentMatrix[0] = m0 * a + m2 * b;
currentMatrix[1] = m1 * a + m3 * b;
currentMatrix[2] = m0 * c + m2 * d;
currentMatrix[3] = m1 * c + m3 * d;
currentMatrix[4] = m0 * tx + m2 * ty + m4;
currentMatrix[5] = m1 * tx + m3 * ty + m5;
return this;
},
setTransform: function (a, b, c, d, tx, ty)
{
var currentMatrix = this.currentMatrix;
currentMatrix[0] = a;
currentMatrix[1] = b;
currentMatrix[2] = c;
currentMatrix[3] = d;
currentMatrix[4] = tx;
currentMatrix[5] = ty;
return this;
},
translate: function (x, y)
{
var currentMatrix = this.currentMatrix;
var m0 = currentMatrix[0];
var m1 = currentMatrix[1];
var m2 = currentMatrix[2];
var m3 = currentMatrix[3];
var m4 = currentMatrix[4];
var m5 = currentMatrix[5];
currentMatrix[4] = m0 * x + m2 * y + m4;
currentMatrix[5] = m1 * x + m3 * y + m5;
return this;
},
scale: function (x, y)
{
var currentMatrix = this.currentMatrix;
var m0 = currentMatrix[0];
var m1 = currentMatrix[1];
var m2 = currentMatrix[2];
var m3 = currentMatrix[3];
currentMatrix[0] = m0 * x;
currentMatrix[1] = m1 * x;
currentMatrix[2] = m2 * y;
currentMatrix[3] = m3 * y;
return this;
},
rotate: function (t)
{
var currentMatrix = this.currentMatrix;
var m0 = currentMatrix[0];
var m1 = currentMatrix[1];
var m2 = currentMatrix[2];
var m3 = currentMatrix[3];
var st = Math.sin(t);
var ct = Math.cos(t);
currentMatrix[0] = m0 * ct + m2 * st;
currentMatrix[1] = m1 * ct + m3 * st;
currentMatrix[2] = m2 * -st + m2 * ct;
currentMatrix[3] = m3 * -st + m3 * ct;
return this;
}
};
module.exports = MatrixStack;

View file

@ -17,6 +17,7 @@ module.exports = {
Depth: require('./Depth'),
Flip: require('./Flip'),
GetBounds: require('./GetBounds'),
MatrixStack: require('./MatrixStack'),
Origin: require('./Origin'),
Pipeline: require('./Pipeline'),
ScaleMode: require('./ScaleMode'),

View file

@ -1115,6 +1115,13 @@ var Graphics = new Class({
});
/**
* A Camera used specifically by the Graphics system for rendering to textures.
*
* @name Phaser.GameObjects.Graphics.TargetCamera
* @type {Phaser.Cameras.Scene2D.Camera}
* @since 3.1.0
*/
Graphics.TargetCamera = new Camera(0, 0, 0, 0);
module.exports = Graphics;

View file

@ -249,7 +249,7 @@ var GraphicsCanvasRenderer = function (renderer, src, interpolationPercentage, c
break;
default:
console.error('Phaser: Invalid Graphics Command ID ' + commandID);
// console.error('Phaser: Invalid Graphics Command ID ' + commandID);
break;
}
}

View file

@ -25,6 +25,7 @@ var GameObjects = {
Image: require('./image/Image'),
Particles: require('./particles/ParticleEmitterManager'),
PathFollower: require('./pathfollower/PathFollower'),
RenderTexture: require('./rendertexture/RenderTexture'),
Sprite3D: require('./sprite3d/Sprite3D'),
Sprite: require('./sprite/Sprite'),
Text: require('./text/static/Text'),
@ -41,6 +42,7 @@ var GameObjects = {
Image: require('./image/ImageFactory'),
Particles: require('./particles/ParticleManagerFactory'),
PathFollower: require('./pathfollower/PathFollowerFactory'),
RenderTexture: require('./rendertexture/RenderTextureFactory'),
Sprite3D: require('./sprite3d/Sprite3DFactory'),
Sprite: require('./sprite/SpriteFactory'),
StaticBitmapText: require('./bitmaptext/static/BitmapTextFactory'),
@ -56,6 +58,7 @@ var GameObjects = {
Group: require('./group/GroupCreator'),
Image: require('./image/ImageCreator'),
Particles: require('./particles/ParticleManagerCreator'),
RenderTexture: require('./rendertexture/RenderTextureCreator'),
Sprite3D: require('./sprite3d/Sprite3DCreator'),
Sprite: require('./sprite/SpriteCreator'),
StaticBitmapText: require('./bitmaptext/static/BitmapTextCreator'),

View file

@ -16,7 +16,7 @@
* @param {number} interpolationPercentage - Reserved for future use and custom pipelines.
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera that is rendering the Game Object.
*/
var MeshCanvasRenderer = function (renderer, src, interpolationPercentage, camera)
var MeshCanvasRenderer = function ()
{
};

View file

@ -31,7 +31,7 @@ if (WEBGL_RENDERER)
{
GameObjectFactory.register('mesh', function (x, y, vertices, uv, colors, alphas, texture, frame)
{
return this.displayList.add(new Mesh(this.scene, x, y, vertices, uv, key, frame));
return this.displayList.add(new Mesh(this.scene, x, y, vertices, uv, colors, alphas, texture, frame));
});
}

View file

@ -538,11 +538,10 @@ var EmitterOp = new Class({
* @param {Phaser.GameObjects.Particles.Particle} particle - [description]
* @param {string} key - [description]
* @param {float} t - The T value (between 0 and 1)
* @param {number} value - [description]
*
* @return {number} [description]
*/
easeValueUpdate: function (particle, key, t, value)
easeValueUpdate: function (particle, key, t)
{
var data = particle.data[key];

View file

@ -136,7 +136,7 @@ var GravityWell = new Class({
* @param {number} delta - The delta time in ms.
* @param {float} step - The delta value divided by 1000.
*/
update: function (particle, delta, step)
update: function (particle, delta)
{
var x = this.x - particle.x;
var y = this.y - particle.y;

View file

@ -12,7 +12,6 @@ var EdgeZone = require('./zones/EdgeZone');
var EmitterOp = require('./EmitterOp');
var GetFastValue = require('../../utils/object/GetFastValue');
var GetRandomElement = require('../../utils/array/GetRandomElement');
var GetValue = require('../../utils/object/GetValue');
var HasAny = require('../../utils/object/HasAny');
var HasValue = require('../../utils/object/HasValue');
var Particle = require('./Particle');
@ -942,7 +941,7 @@ var ParticleEmitter = new Class({
if (this._frameCounter === this.frameQuantity)
{
this._frameCounter = 0;
this.currentFrame = Wrap(this.currentFrame + 1, 0, this._frameLength);
this.currentFrame = Wrap(this.currentFrame + 1, 0, this._frameLength);
}
return frame;
@ -986,7 +985,8 @@ var ParticleEmitter = new Class({
else if (t === 'object')
{
var frameConfig = frames;
var frames = GetFastValue(frameConfig, 'frames', null);
frames = GetFastValue(frameConfig, 'frames', null);
if (frames)
{
@ -1068,10 +1068,10 @@ var ParticleEmitter = new Class({
{
var obj = x;
var x = obj.x;
var y = obj.y;
var width = (HasValue(obj, 'w')) ? obj.w : obj.width;
var height = (HasValue(obj, 'h')) ? obj.h : obj.height;
x = obj.x;
y = obj.y;
width = (HasValue(obj, 'w')) ? obj.w : obj.width;
height = (HasValue(obj, 'h')) ? obj.h : obj.height;
}
if (this.bounds)

View file

@ -5,7 +5,6 @@
*/
var Class = require('../../../utils/Class');
var Wrap = require('../../../math/Wrap');
/**
* @classdesc

View file

@ -46,37 +46,37 @@ var Quad = new Class({
// | \
// 1----2
var vertices = [
var vertices = [
0, 0, // tl
0, 0, // bl
0, 0, // br
0, 0, // tl
0, 0, // br
0, 0 // tr
0, 0 // tr
];
var uv = [
var uv = [
0, 0, // tl
0, 1, // bl
1, 1, // br
0, 0, // tl
1, 1, // br
1, 0 // tr
1, 0 // tr
];
var colors = [
var colors = [
0xffffff, // tl
0xffffff, // bl
0xffffff, // br
0xffffff, // tl
0xffffff, // br
0xffffff // tr
0xffffff // tr
];
var alphas = [
var alphas = [
1, // tl
1, // bl
1, // br
1, // tl
1, // br
1 // tr
1 // tr
];
Mesh.call(this, scene, x, y, vertices, uv, colors, alphas, texture, frame);

View file

@ -0,0 +1,75 @@
var Class = require('../../utils/Class');
var Components = require('../components');
var GameObject = require('../GameObject');
var RenderTextureWebGL = require('./RenderTextureWebGL');
var Render = require('./RenderTextureRender');
var RenderTexture = new Class({
Extends: GameObject,
Mixins: [
Components.Alpha,
Components.BlendMode,
Components.Depth,
Components.Flip,
Components.GetBounds,
Components.MatrixStack,
Components.Origin,
Components.Pipeline,
Components.ScaleMode,
Components.ScrollFactor,
Components.Size,
Components.Tint,
Components.Transform,
Components.Visible,
Render
],
initialize:
function RenderTexture(scene, x, y, width, height)
{
GameObject.call(this, scene, 'RenderTexture');
this.initMatrixStack();
this.renderer = scene.sys.game.renderer;
if (this.renderer.type === Phaser.WEBGL)
{
var gl = this.renderer.gl;
this.gl = gl;
this.fill = RenderTextureWebGL.fill;
this.clear = RenderTextureWebGL.clear;
this.draw = RenderTextureWebGL.draw;
this.drawFrame = RenderTextureWebGL.drawFrame;
this.texture = this.renderer.createTexture2D(0, gl.NEAREST, gl.NEAREST, gl.CLAMP_TO_EDGE, gl.CLAMP_TO_EDGE, gl.RGBA, null, width, height, false);
this.framebuffer = this.renderer.createFramebuffer(width, height, this.texture, false);
}
else
{
// For now we'll just add canvas stubs
this.fill = function () {};
this.clear = function () {};
this.draw = function () {};
this.drawFrame = function () {};
}
this.setPosition(x, y);
this.setSize(width, height);
this.initPipeline('TextureTintPipeline');
},
destroy: function ()
{
GameObject.destroy.call(this);
if (this.renderer.type === Phaser.WEBGL)
{
this.renderer.deleteTexture(this.texture);
this.renderer.deleteFramebuffer(this.framebuffer);
}
}
});
module.exports = RenderTexture;

View file

@ -0,0 +1,12 @@
var GameObject = require('../GameObject');
var RenderTextureCanvasRenderer = function (renderer, renderTexture, interpolationPercentage, camera)
{
if (GameObject.RENDER_MASK !== renderTexture.renderFlags || (renderTexture.cameraFilter > 0 && (renderTexture.cameraFilter & camera._id)))
{
return;
}
};
module.exports = RenderTextureCanvasRenderer;

View file

@ -0,0 +1,18 @@
var BuildGameObject = require('../BuildGameObject');
var BuildGameObjectAnimation = require('../BuildGameObjectAnimation');
var GameObjectCreator = require('../GameObjectCreator');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var RenderTexture = require('./RenderTexture');
GameObjectCreator.register('renderTexture', function (config)
{
var x = GetAdvancedValue(config, 'x', 0);
var y = GetAdvancedValue(config, 'y', 0);
var width = GetAdvancedValue(config, 'width', 32);
var height = GetAdvancedValue(config, 'height', 32);
var renderTexture = new RenderTexture(this.scene, x, y, width, height);
BuildGameObject(this.scene, renderTexture, config);
return renderTexture;
});

View file

@ -0,0 +1,7 @@
var GameObjectFactory = require('../GameObjectFactory');
var RenderTexture = require('./RenderTexture');
GameObjectFactory.register('renderTexture', function (x, y, width, height)
{
return this.displayList.add(new RenderTexture(this.scene, x, y, width, height));
});

View file

@ -0,0 +1,19 @@
var renderWebGL = require('../../utils/NOOP');
var renderCanvas = require('../../utils/NOOP');
if (WEBGL_RENDERER)
{
renderWebGL = require('./RenderTextureWebGLRenderer');
}
if (CANVAS_RENDERER)
{
renderCanvas = require('./RenderTextureCanvasRenderer');
}
module.exports = {
renderWebGL: renderWebGL,
renderCanvas: renderCanvas
};

View file

@ -0,0 +1,45 @@
var RenderTextureWebGL = {
fill: function (rgb)
{
var ur = ((rgb >> 16)|0) & 0xff;
var ug = ((rgb >> 8)|0) & 0xff;
var ub = (rgb|0) & 0xff;
this.renderer.setFramebuffer(this.framebuffer);
var gl = this.gl;
gl.clearColor(ur / 255.0, ug / 255.0, ub / 255.0, 1);
gl.clear(gl.COLOR_BUFFER_BIT);
this.renderer.setFramebuffer(null);
return this;
},
clear: function ()
{
this.renderer.setFramebuffer(this.framebuffer);
var gl = this.gl;
gl.clearColor(0, 0, 0, 0);
gl.clear(gl.COLOR_BUFFER_BIT);
this.renderer.setFramebuffer(null);
return this;
},
draw: function (texture, x, y)
{
this.renderer.setFramebuffer(this.framebuffer);
this.renderer.pipelines.TextureTintPipeline.drawTexture(texture, x, y, 0, 0, texture.width, texture.height, this.currentMatrix);
this.renderer.setFramebuffer(null);
return this;
},
drawFrame: function (texture, x, y, frame)
{
this.renderer.setFramebuffer(this.framebuffer);
this.renderer.pipelines.TextureTintPipeline.drawTexture(texture, frame.x, frame.y, frame.width, frame.height, texture.width, texture.height, this.currentMatrix);
this.renderer.setFramebuffer(null);
return this;
}
};
module.exports = RenderTextureWebGL;

View file

@ -0,0 +1,28 @@
var GameObject = require('../GameObject');
var RenderTextureWebGLRenderer = function (renderer, renderTexture, interpolationPercentage, camera)
{
if (GameObject.RENDER_MASK !== renderTexture.renderFlags || (renderTexture.cameraFilter > 0 && (renderTexture.cameraFilter & camera._id)))
{
return;
}
this.pipeline.batchTexture(
renderTexture,
renderTexture.texture,
renderTexture.texture.width, renderTexture.texture.height,
renderTexture.x, renderTexture.y,
renderTexture.width, renderTexture.height,
renderTexture.scaleX, renderTexture.scaleY,
renderTexture.rotation,
renderTexture.flipX, renderTexture.flipY,
renderTexture.scrollFactorX, renderTexture.scrollFactorY,
renderTexture.displayOriginX, renderTexture.displayOriginY,
0, 0, renderTexture.texture.width, renderTexture.texture.height,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0, 0,
camera
);
};
module.exports = RenderTextureWebGLRenderer;

View file

@ -290,9 +290,9 @@ var TextStyle = new Class({
* @since 3.0.0
*
* @param {[type]} style - [description]
* @param {[type]} updateText - [description]
* @param {boolean} [updateText=true] - [description]
*
* @return {Phaser.GameObjects.Components.TextStyle This TextStyle component.
* @return {Phaser.GameObjects.Components.TextStyle} This TextStyle component.
*/
setStyle: function (style, updateText)
{
@ -565,7 +565,7 @@ var TextStyle = new Class({
* @method Phaser.GameObjects.Components.TextStyle#setBackgroundColor
* @since 3.0.0
*
* @param {string color - [description]
* @param {string} color - [description]
*
* @return {Phaser.GameObjects.Text} The parent Text object.
*/

View file

@ -959,7 +959,8 @@ var Text = new Class({
}
context.save();
//context.scale(resolution, resolution);
// context.scale(resolution, resolution);
if (style.backgroundColor)
{

View file

@ -28,7 +28,8 @@ var TextCanvasRenderer = function (renderer, src, interpolationPercentage, camer
}
var ctx = renderer.currentContext;
var resolution = src.resolution;
// var resolution = src.resolution;
// Blend Mode
if (renderer.currentBlendMode !== src.blendMode)
@ -53,7 +54,8 @@ var TextCanvasRenderer = function (renderer, src, interpolationPercentage, camer
var canvas = src.canvas;
ctx.save();
//ctx.scale(1.0 / resolution, 1.0 / resolution);
// ctx.scale(1.0 / resolution, 1.0 / resolution);
ctx.translate(src.x - camera.scrollX * src.scrollFactorX, src.y - camera.scrollY * src.scrollFactorY);
ctx.rotate(src.rotation);
ctx.scale(src.scaleX, src.scaleY);

View file

@ -177,7 +177,9 @@ var TileSprite = new Class({
this.updateTileTexture();
scene.sys.game.renderer.onContextRestored(function (renderer) {
scene.sys.game.renderer.onContextRestored(function (renderer)
{
var gl = renderer.gl;
this.tileTexture = null;
this.dirty = true;
this.tileTexture = renderer.createTexture2D(0, gl.LINEAR, gl.LINEAR, gl.REPEAT, gl.REPEAT, gl.RGBA, this.canvasBuffer, this.potWidth, this.potHeight);

View file

@ -20,7 +20,7 @@ var Contains = require('../triangle/Contains');
*/
var TriangleToCircle = function (triangle, circle)
{
// First the cheapest ones:
// First the cheapest ones:
if (
triangle.left > circle.right ||

View file

@ -28,7 +28,7 @@ var ContainsRect = function (rectA, rectB)
return (
(rectB.x > rectA.x && rectB.x < rectA.right) &&
(rectB.right > rectA.x && rectB.right < rectA.right) &&
(rectB.y > rectA.y && rectB.y < rectA.bottom) &&
(rectB.y > rectA.y && rectB.y < rectA.bottom) &&
(rectB.bottom > rectA.y && rectB.bottom < rectA.bottom)
);
};

View file

@ -56,6 +56,7 @@ var MarchingAnts = function (rect, step, quantity, out)
switch (face)
{
// Top face
case 0:
x += step;

View file

@ -18,9 +18,9 @@
var Overlaps = function (rectA, rectB)
{
return (
rectA.x < rectB.right &&
rectA.right > rectB.x &&
rectA.y < rectB.bottom &&
rectA.x < rectB.right &&
rectA.right > rectB.x &&
rectA.y < rectB.bottom &&
rectA.bottom > rectB.y
);
};

View file

@ -25,7 +25,7 @@ var Triangle = require('./Triangle');
*/
var BuildRight = function (x, y, width, height)
{
if (height === undefined) { height = width; }
if (height === undefined) { height = width; }
// 90 degree angle
var x1 = x;

View file

@ -350,7 +350,7 @@ var Pointer = new Class({
* @param {[type]} event - [description]
* @param {[type]} time - [description]
*/
touchmove: function (event, time)
touchmove: function (event)
{
this.event = event;
@ -373,7 +373,7 @@ var Pointer = new Class({
* @param {[type]} event - [description]
* @param {[type]} time - [description]
*/
move: function (event, time)
move: function (event)
{
if (event.buttons)
{

View file

@ -209,11 +209,12 @@ var GamepadManager = new Class({
*
* @method Phaser.Input.Gamepad.GamepadManager#removePad
* @since 3.0.0
* @todo Code this feature
*
* @param {[type]} index - [description]
* @param {[type]} pad - [description]
*/
removePad: function (index, pad)
removePad: function ()
{
// TODO
},

View file

@ -43,4 +43,4 @@ module.exports = {
RIGHT_STICK_H: 2,
RIGHT_STICK_V: 3
};
};

View file

@ -525,11 +525,11 @@ module.exports = {
PERIOD: 190,
/**
* @name Phaser.Input.Keyboard.KeyCodes.FORWAD_SLASH
* @name Phaser.Input.Keyboard.KeyCodes.FORWARD_SLASH
* @type {integer}
* @since 3.0.0
*/
FORWAD_SLASH: 191,
FORWARD_SLASH: 191,
/**
* @name Phaser.Input.Keyboard.KeyCodes.BACK_SLASH

View file

@ -8,8 +8,10 @@
* @namespace Phaser.Input.Mouse
*/
/* eslint-disable */
module.exports = {
MouseManager: require('./MouseManager')
};
/* eslint-enable */

View file

@ -8,8 +8,10 @@
* @namespace Phaser.Input.Touch
*/
/* eslint-disable */
module.exports = {
TouchManager: require('./TouchManager')
};
/* eslint-enable */

View file

@ -272,7 +272,7 @@ var File = new Class({
if (this.src.indexOf('data:') === 0)
{
console.log('Local data URI');
console.warn('Local data URIs are not supported: ' + this.key);
}
else
{
@ -311,7 +311,7 @@ var File = new Class({
*
* @param {ProgressEvent} event - The DOM ProgressEvent that resulted from this error.
*/
onError: function (event)
onError: function ()
{
this.resetXHR();

View file

@ -23,7 +23,7 @@ var XHRSettings = require('./XHRSettings');
*/
var MergeXHRSettings = function (global, local)
{
var output = (global === undefined) ? XHRSettings() : Extend(global);
var output = (global === undefined) ? XHRSettings() : Extend({}, global);
if (local)
{

View file

@ -82,6 +82,7 @@ var AudioFile = new Class({
},
function (e)
{
// eslint-disable-next-line no-console
console.error('Error with decoding audio data for \'' + this.key + '\':', e.message);
_this.state = CONST.FILE_ERRORED;
@ -103,7 +104,7 @@ AudioFile.create = function (loader, key, urls, config, xhrSettings)
if ((audioConfig && audioConfig.noAudio) || (!deviceAudio.webAudio && !deviceAudio.audioData))
{
console.info('Skipping loading audio \'' + key + '\' since sounds are disabled.');
// console.info('Skipping loading audio \'' + key + '\' since sounds are disabled.');
return null;
}
@ -111,7 +112,7 @@ AudioFile.create = function (loader, key, urls, config, xhrSettings)
if (!url)
{
console.warn('No supported url provided for audio \'' + key + '\'!');
// console.warn('No supported url provided for audio \'' + key + '\'!');
return null;
}

View file

@ -61,7 +61,7 @@ var HTML5AudioFile = new Class({
this.loader.nextFile(this, true);
},
onError: function (event)
onError: function ()
{
for (var i = 0; i < this.data.length; i++)
{

View file

@ -39,7 +39,7 @@ var SpriteSheetFile = function (key, url, config, path, xhrSettings)
* The file is **not** loaded immediately after calling this method.
* Instead, the file is added to a queue within the Loader, which is processed automatically when the Loader starts.
*
* @method Phaser.Loader.LoaderPlugin#image
* @method Phaser.Loader.LoaderPlugin#spritesheet
* @since 3.0.0
*
* @param {string} key - [description]

View file

@ -17,6 +17,8 @@
var IsEven = function (value)
{
// Use abstract equality == for "is number" test
// eslint-disable-next-line eqeqeq
return (value == parseFloat(value)) ? !(value % 2) : void 0;
};

View file

@ -78,7 +78,7 @@ var Vector2 = new Class({
* @method Phaser.Math.Vector2#copy
* @since 3.0.0
*
* @param {[type]} src - [description]
* @param {Phaser.Math.Vector2|object} src - [description]
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
@ -533,4 +533,12 @@ var Vector2 = new Class({
});
/**
* A static zero Vector2 for use by reference.
*
* @method Phaser.Math.Vector2.ZERO
* @since 3.1.0
*/
Vector2.ZERO = new Vector2();
module.exports = Vector2;

View file

@ -32,7 +32,7 @@ var Vector4 = new Class({
/**
* The x component of this Vector.
*
* @name Phaser.Math.Vector3#x
* @name Phaser.Math.Vector4#x
* @type {number}
* @default 0
* @since 3.0.0
@ -41,7 +41,7 @@ var Vector4 = new Class({
/**
* The y component of this Vector.
*
* @name Phaser.Math.Vector3#y
* @name Phaser.Math.Vector4#y
* @type {number}
* @default 0
* @since 3.0.0
@ -50,7 +50,7 @@ var Vector4 = new Class({
/**
* The z component of this Vector.
*
* @name Phaser.Math.Vector3#z
* @name Phaser.Math.Vector4#z
* @type {number}
* @default 0
* @since 3.0.0
@ -59,7 +59,7 @@ var Vector4 = new Class({
/**
* The w component of this Vector.
*
* @name Phaser.Math.Vector3#w
* @name Phaser.Math.Vector4#w
* @type {number}
* @default 0
* @since 3.0.0
@ -87,7 +87,7 @@ var Vector4 = new Class({
* @method Phaser.Math.Vector4#clone
* @since 3.0.0
*
* @return {[type]} [description]
* @return {Phaser.Math.Vector4} [description]
*/
clone: function ()
{
@ -100,9 +100,9 @@ var Vector4 = new Class({
* @method Phaser.Math.Vector4#copy
* @since 3.0.0
*
* @param {[type]} src - [description]
* @param {Phaser.Math.Vector4} src - [description]
*
* @return {[type]} [description]
* @return {Phaser.Math.Vector4} This Vector4 object.
*/
copy: function (src)
{
@ -120,9 +120,9 @@ var Vector4 = new Class({
* @method Phaser.Math.Vector4#equals
* @since 3.0.0
*
* @param {[type]} v - [description]
* @param {Phaser.Math.Vector4} v - [description]
*
* @return {[type]} [description]
* @return {boolean} [description]
*/
equals: function (v)
{
@ -135,12 +135,12 @@ var Vector4 = new Class({
* @method Phaser.Math.Vector4#set
* @since 3.0.0
*
* @param {[type]} x - [description]
* @param {[type]} y - [description]
* @param {[type]} z - [description]
* @param {[type]} w - [description]
* @param {number} x - [description]
* @param {number} y - [description]
* @param {number} z - [description]
* @param {number} w - [description]
*
* @return {[type]} [description]
* @return {Phaser.Math.Vector4} This Vector4 object.
*/
set: function (x, y, z, w)
{
@ -168,9 +168,9 @@ var Vector4 = new Class({
* @method Phaser.Math.Vector4#add
* @since 3.0.0
*
* @param {[type]} v - [description]
* @param {Phaser.Math.Vector2|Phaser.Math.Vector3|Phaser.Math.Vector4} v - [description]
*
* @return {[type]} [description]
* @return {Phaser.Math.Vector4} This Vector4 object.
*/
add: function (v)
{
@ -188,9 +188,9 @@ var Vector4 = new Class({
* @method Phaser.Math.Vector4#subtract
* @since 3.0.0
*
* @param {[type]} v - [description]
* @param {Phaser.Math.Vector2|Phaser.Math.Vector3|Phaser.Math.Vector4} v - [description]
*
* @return {[type]} [description]
* @return {Phaser.Math.Vector4} This Vector4 object.
*/
subtract: function (v)
{
@ -208,9 +208,9 @@ var Vector4 = new Class({
* @method Phaser.Math.Vector4#scale
* @since 3.0.0
*
* @param {[type]} scale - [description]
* @param {number} scale - [description]
*
* @return {[type]} [description]
* @return {Phaser.Math.Vector4} This Vector4 object.
*/
scale: function (scale)
{
@ -228,7 +228,7 @@ var Vector4 = new Class({
* @method Phaser.Math.Vector4#length
* @since 3.0.0
*
* @return {[type]} [description]
* @return {number} [description]
*/
length: function ()
{
@ -246,7 +246,7 @@ var Vector4 = new Class({
* @method Phaser.Math.Vector4#lengthSq
* @since 3.0.0
*
* @return {[type]} [description]
* @return {number} [description]
*/
lengthSq: function ()
{
@ -264,7 +264,7 @@ var Vector4 = new Class({
* @method Phaser.Math.Vector4#normalize
* @since 3.0.0
*
* @return {[type]} [description]
* @return {Phaser.Math.Vector4} This Vector4 object.
*/
normalize: function ()
{
@ -295,7 +295,7 @@ var Vector4 = new Class({
*
* @param {[type]} v - [description]
*
* @return {[type]} [description]
* @return {number} [description]
*/
dot: function (v)
{
@ -311,7 +311,7 @@ var Vector4 = new Class({
* @param {[type]} v - [description]
* @param {[type]} t - [description]
*
* @return {[type]} [description]
* @return {Phaser.Math.Vector4} This Vector4 object.
*/
lerp: function (v, t)
{
@ -338,7 +338,7 @@ var Vector4 = new Class({
*
* @param {[type]} v - [description]
*
* @return {[type]} [description]
* @return {Phaser.Math.Vector4} This Vector4 object.
*/
multiply: function (v)
{
@ -358,7 +358,7 @@ var Vector4 = new Class({
*
* @param {[type]} v - [description]
*
* @return {[type]} [description]
* @return {Phaser.Math.Vector4} This Vector4 object.
*/
divide: function (v)
{
@ -378,7 +378,7 @@ var Vector4 = new Class({
*
* @param {[type]} v - [description]
*
* @return {[type]} [description]
* @return {number} [description]
*/
distance: function (v)
{
@ -398,7 +398,7 @@ var Vector4 = new Class({
*
* @param {[type]} v - [description]
*
* @return {[type]} [description]
* @return {number} [description]
*/
distanceSq: function (v)
{
@ -416,7 +416,7 @@ var Vector4 = new Class({
* @method Phaser.Math.Vector4#negate
* @since 3.0.0
*
* @return {[type]} [description]
* @return {Phaser.Math.Vector4} This Vector4 object.
*/
negate: function ()
{
@ -436,7 +436,7 @@ var Vector4 = new Class({
*
* @param {[type]} mat - [description]
*
* @return {[type]} [description]
* @return {Phaser.Math.Vector4} This Vector4 object.
*/
transformMat4: function (mat)
{
@ -464,7 +464,7 @@ var Vector4 = new Class({
*
* @param {[type]} q - [description]
*
* @return {[type]} [description]
* @return {Phaser.Math.Vector4} This Vector4 object.
*/
transformQuat: function (q)
{
@ -497,7 +497,7 @@ var Vector4 = new Class({
* @method Phaser.Math.Vector4#reset
* @since 3.0.0
*
* @return {[type]} [description]
* @return {Phaser.Math.Vector4} This Vector4 object.
*/
reset: function ()
{
@ -511,6 +511,7 @@ var Vector4 = new Class({
});
// TODO: Check if these are required internally, if not, remove.
Vector4.prototype.sub = Vector4.prototype.subtract;
Vector4.prototype.mul = Vector4.prototype.multiply;
Vector4.prototype.div = Vector4.prototype.divide;

View file

@ -10,13 +10,12 @@
* @function Phaser.Math.Fuzzy.Floor
* @since 3.0.0
*
* @param {number} a - [description]
* @param {number} b - [description]
* @param {number} value - [description]
* @param {float} [epsilon=0.0001] - [description]
*
* @return {number} [description]
*/
var Floor = function (a, b, epsilon)
var Floor = function (value, epsilon)
{
if (epsilon === undefined) { epsilon = 0.0001; }

View file

@ -309,8 +309,9 @@ var RandomDataGenerator = new Class({
var a = '';
var b = '';
for (b = a = ''; a++ < 36; b +=~a % 5 | a*3 & 4 ? (a^15 ? 8 ^ this.frac()*(a^20 ? 16 : 4) : 4).toString(16) : '-')
for (b = a = ''; a++ < 36; b += ~a % 5 | a * 3 & 4 ? (a ^ 15 ? 8 ^ this.frac() * (a ^ 20 ? 16 : 4) : 4).toString(16) : '-')
{
// eslint-disable-next-line no-empty
}
return b;

View file

@ -84,18 +84,6 @@ var Body = new Class({
*/
this.enable = true;
/**
* If Body.destroy is called during the main physics update loop then this flag is set.
* The Body is then actually destroyed during World.postUpdate.
* You can also toggle it yourself.
*
* @name Phaser.Physics.Arcade.Body#pendingDestroy
* @type {boolean}
* @default false
* @since 3.0.1
*/
this.pendingDestroy = false;
/**
* [description]
*
@ -1085,28 +1073,29 @@ var Body = new Class({
},
/**
* [description]
* Resets this Body to the given coordinates. Also positions its parent Game Object to the same coordinates.
* If the body had any velocity or acceleration it is lost as a result of calling this.
*
* @method Phaser.Physics.Arcade.Body#reset
* @since 3.0.0
*
* @param {number} x - [description]
* @param {number} y - [description]
* @param {number} x - The horizontal position to place the Game Object and Body.
* @param {number} y - The vertical position to place the Game Object and Body.
*/
reset: function (x, y)
{
this.stop();
var sprite = this.gameObject;
var gameObject = this.gameObject;
this.position.x = x - sprite.displayOriginX + (sprite.scaleX * this.offset.x);
this.position.y = y - sprite.displayOriginY + (sprite.scaleY * this.offset.y);
gameObject.setPosition(x, y);
this.prev.x = this.position.x;
this.prev.y = this.position.y;
gameObject.getTopLeft(this.position);
this.rotation = this.gameObject.angle;
this.preRotation = this.rotation;
this.prev.copy(this.position);
this.rotation = gameObject.angle;
this.preRotation = gameObject.angle;
this.updateBounds();
this.updateCenter();
@ -1279,17 +1268,9 @@ var Body = new Class({
*/
destroy: function ()
{
if (!this.pendingDestroy)
{
// Will be removed the next time World.postUpdate runs, not before.
this.pendingDestroy = true;
}
else
{
this.world.disableBody(this);
this.enable = false;
this.world = null;
}
this.world.pendingDestroy.set(this);
},
/**

View file

@ -43,7 +43,7 @@ var Collider = new Class({
*
* @name Phaser.Physics.Arcade.Collider#name
* @type {string}
* @since 3.0.1
* @since 3.1.0
*/
this.name = '';
@ -116,7 +116,7 @@ var Collider = new Class({
* [description]
*
* @method Phaser.Physics.Arcade.Collider#setName
* @since 3.0.1
* @since 3.1.0
*
* @param {string} name - [description]
*

View file

@ -7,7 +7,6 @@
var CircleContains = require('../../geom/circle/Contains');
var Class = require('../../utils/Class');
var CONST = require('./const');
var Rectangle = require('../../geom/rectangle/Rectangle');
var RectangleContains = require('../../geom/rectangle/Contains');
var Vector2 = require('../../math/Vector2');
@ -120,7 +119,7 @@ var StaticBody = new Class({
* @type {number}
* @since 3.0.0
*/
this.width = gameObject.width;
this.width = gameObject.displayWidth;
/**
* [description]
@ -129,31 +128,7 @@ var StaticBody = new Class({
* @type {number}
* @since 3.0.0
*/
this.height = gameObject.height;
/**
* [description]
*
* @name Phaser.Physics.Arcade.StaticBody#sourceWidth
* @type {number}
* @since 3.0.0
*/
this.sourceWidth = gameObject.width;
/**
* [description]
*
* @name Phaser.Physics.Arcade.StaticBody#sourceHeight
* @type {number}
* @since 3.0.0
*/
this.sourceHeight = gameObject.height;
if (gameObject.frame)
{
this.sourceWidth = gameObject.frame.realWidth;
this.sourceHeight = gameObject.frame.realHeight;
}
this.height = gameObject.displayHeight;
/**
* [description]
@ -162,7 +137,7 @@ var StaticBody = new Class({
* @type {number}
* @since 3.0.0
*/
this.halfWidth = Math.abs(gameObject.width / 2);
this.halfWidth = Math.abs(this.width / 2);
/**
* [description]
@ -171,7 +146,7 @@ var StaticBody = new Class({
* @type {number}
* @since 3.0.0
*/
this.halfHeight = Math.abs(gameObject.height / 2);
this.halfHeight = Math.abs(this.height / 2);
/**
* [description]
@ -189,7 +164,7 @@ var StaticBody = new Class({
* @type {Phaser.Math.Vector2}
* @since 3.0.0
*/
this.velocity = new Vector2();
this.velocity = Vector2.ZERO;
/**
* [description]
@ -208,7 +183,7 @@ var StaticBody = new Class({
* @type {Phaser.Math.Vector2}
* @since 3.0.0
*/
this.gravity = new Vector2();
this.gravity = Vector2.ZERO;
/**
* [description]
@ -217,7 +192,7 @@ var StaticBody = new Class({
* @type {Phaser.Math.Vector2}
* @since 3.0.0
*/
this.bounce = new Vector2();
this.bounce = Vector2.ZERO;
// If true this Body will dispatch events
@ -271,16 +246,6 @@ var StaticBody = new Class({
*/
this.immovable = true;
/**
* [description]
*
* @name Phaser.Physics.Arcade.StaticBody#moves
* @type {boolean}
* @default false
* @since 3.0.0
*/
this.moves = false;
/**
* [description]
*
@ -395,36 +360,70 @@ var StaticBody = new Class({
* @since 3.0.0
*/
this.physicsType = CONST.STATIC_BODY;
},
/**
* [description]
*
* @name Phaser.Physics.Arcade.StaticBody#_sx
* @type {number}
* @private
* @since 3.0.0
*/
this._sx = gameObject.scaleX;
/**
* Changes the Game Object this Body is bound to.
* First it removes its reference from the old Game Object, then sets the new one.
* You can optionally update the position and dimensions of this Body to reflect that of the new Game Object.
*
* @method Phaser.Physics.Arcade.StaticBody#setGameObject
* @since 3.1.0
*
* @param {Phaser.GameObjects.GameObject} gameObject - The new Game Object that will own this Body.
* @param {boolean} [update=true] - Reposition and resize this Body to match the new Game Object?
*
* @return {Phaser.Physics.Arcade.StaticBody} This Static Body object.
*/
setGameObject: function (gameObject, update)
{
if (gameObject && gameObject !== this.gameObject)
{
// Remove this body from the old game object
this.gameObject.body = null;
/**
* [description]
*
* @name Phaser.Physics.Arcade.StaticBody#_sy
* @type {number}
* @private
* @since 3.0.0
*/
this._sy = gameObject.scaleY;
gameObject.body = this;
/**
* [description]
*
* @name Phaser.Physics.Arcade.StaticBody#_bounds
* @type {Phaser.Geom.Rectangle}
* @private
* @since 3.0.0
*/
this._bounds = new Rectangle();
// Update our reference
this.gameObject = gameObject;
}
if (update)
{
this.updateFromGameObject();
}
return this;
},
/**
* Updates this Static Body so that its position and dimensions are updated
* based on the current Game Object it is bound to.
*
* @method Phaser.Physics.Arcade.StaticBody#updateFromGameObject
* @since 3.1.0
*
* @return {Phaser.Physics.Arcade.StaticBody} This Static Body object.
*/
updateFromGameObject: function ()
{
this.world.staticTree.remove(this);
var gameObject = this.gameObject;
gameObject.getTopLeft(this.position);
this.width = gameObject.displayWidth;
this.height = gameObject.displayHeight;
this.halfWidth = Math.abs(this.width / 2);
this.halfHeight = Math.abs(this.height / 2);
this.center.set(this.position.x + this.halfWidth, this.position.y + this.halfHeight);
this.world.staticTree.insert(this);
return this;
},
/**
@ -447,12 +446,12 @@ var StaticBody = new Class({
this.world.staticTree.remove(this);
this.sourceWidth = width;
this.sourceHeight = height;
this.width = this.sourceWidth * this._sx;
this.height = this.sourceHeight * this._sy;
this.halfWidth = Math.floor(this.width / 2);
this.halfHeight = Math.floor(this.height / 2);
this.width = width;
this.height = height;
this.halfWidth = Math.floor(width / 2);
this.halfHeight = Math.floor(height / 2);
this.offset.set(offsetX, offsetY);
this.updateCenter();
@ -487,13 +486,11 @@ var StaticBody = new Class({
this.world.staticTree.remove(this);
this.isCircle = true;
this.radius = radius;
this.sourceWidth = radius * 2;
this.sourceHeight = radius * 2;
this.width = this.sourceWidth * this._sx;
this.height = this.sourceHeight * this._sy;
this.width = radius * 2;
this.height = radius * 2;
this.halfWidth = Math.floor(this.width / 2);
this.halfHeight = Math.floor(this.height / 2);
@ -534,17 +531,14 @@ var StaticBody = new Class({
*/
reset: function (x, y)
{
var sprite = this.gameObject;
var gameObject = this.gameObject;
if (x === undefined) { x = sprite.x; }
if (y === undefined) { y = sprite.y; }
if (x === undefined) { x = gameObject.x; }
if (y === undefined) { y = gameObject.y; }
this.world.staticTree.remove(this);
this.position.x = x - sprite.displayOriginX + (sprite.scaleX * this.offset.x);
this.position.y = y - sprite.displayOriginY + (sprite.scaleY * this.offset.y);
this.rotation = this.gameObject.angle;
gameObject.getTopLeft(this.position);
this.updateCenter();
@ -673,8 +667,9 @@ var StaticBody = new Class({
*/
destroy: function ()
{
this.gameObject.body = null;
this.gameObject = null;
this.enable = false;
this.world.pendingDestroy.set(this);
},
/**
@ -748,9 +743,10 @@ var StaticBody = new Class({
set: function (value)
{
this.world.staticTree.remove(this);
this.position.x = value;
this.world.staticTree.remove(this);
this.world.staticTree.insert(this);
}
@ -772,9 +768,10 @@ var StaticBody = new Class({
set: function (value)
{
this.world.staticTree.remove(this);
this.position.y = value;
this.world.staticTree.remove(this);
this.world.staticTree.insert(this);
}

View file

@ -111,7 +111,7 @@ var StaticPhysicsGroup = new Class({
*
* @param {object} entries - [description]
*/
createMultipleCallback: function (entries)
createMultipleCallback: function ()
{
this.refresh();
},

View file

@ -11,6 +11,8 @@ var Collider = require('./Collider');
var CONST = require('./const');
var DistanceBetween = require('../../math/distance/DistanceBetween');
var EventEmitter = require('eventemitter3');
var GetOverlapX = require('./GetOverlapX');
var GetOverlapY = require('./GetOverlapY');
var GetValue = require('../../utils/object/GetValue');
var ProcessQueue = require('../../structs/ProcessQueue');
var ProcessTileCallbacks = require('./tilemap/ProcessTileCallbacks');
@ -74,6 +76,15 @@ var World = new Class({
*/
this.staticBodies = new Set();
/**
* Static Bodies
*
* @name Phaser.Physics.Arcade.World#pendingDestroy
* @type {Phaser.Structs.Set}
* @since 3.1.0
*/
this.pendingDestroy = new Set();
/**
* [description]
*
@ -383,7 +394,7 @@ var World = new Class({
* [description]
*
* @method Phaser.Physics.Arcade.World#disableGameObjectBody
* @since 3.0.1
* @since 3.1.0
*
* @param {Phaser.GameObjects.GameObject} object - [description]
*
@ -682,10 +693,13 @@ var World = new Class({
{
var i;
var body;
var bodies = this.bodies.entries;
var len = bodies.length;
var toDestroy = [];
var dynamic = this.bodies;
var staticBodies = this.staticBodies;
var pending = this.pendingDestroy;
var bodies = dynamic.entries;
var len = bodies.length;
for (i = 0; i < len; i++)
{
@ -695,11 +709,6 @@ var World = new Class({
{
body.postUpdate();
}
if (body.pendingDestroy)
{
toDestroy.push(body);
}
}
if (this.drawDebug)
@ -718,7 +727,7 @@ var World = new Class({
}
}
bodies = this.staticBodies.entries;
bodies = staticBodies.entries;
len = bodies.length;
for (i = 0; i < len; i++)
@ -732,13 +741,34 @@ var World = new Class({
}
}
for (i = 0; i < toDestroy.length; i++)
if (pending.size > 0)
{
body = toDestroy[i];
var dynamicTree = this.tree;
var staticTree = this.staticTree;
this.emit('destroybody', this, body);
bodies = pending.entries;
len = bodies.length;
body.destroy();
for (i = 0; i < len; i++)
{
body = bodies[i];
if (body.physicsType === CONST.DYNAMIC_BODY)
{
dynamicTree.remove(body);
dynamic.delete(body);
}
else if (body.physicsType === CONST.STATIC_BODY)
{
staticTree.remove(body);
staticBodies.delete(body);
}
body.world = undefined;
body.gameObject = undefined;
}
pending.clear();
}
},
@ -1360,6 +1390,7 @@ var World = new Class({
return this.collideSpriteVsTilemapLayer(object1, object2, collideCallback, processCallback, callbackContext, overlapOnly);
}
}
// GROUPS
else if (object1.isParent)
{
@ -1376,6 +1407,7 @@ var World = new Class({
return this.collideGroupVsTilemapLayer(object1, object2, collideCallback, processCallback, callbackContext, overlapOnly);
}
}
// TILEMAP LAYERS
else if (object1.isTilemap)
{
@ -1518,7 +1550,8 @@ var World = new Class({
{
if (children[i].body)
{
if (this.collideSpriteVsTilemapLayer(children[i], tilemapLayer, collideCallback, processCallback, callbackContext, overlapOnly)) {
if (this.collideSpriteVsTilemapLayer(children[i], tilemapLayer, collideCallback, processCallback, callbackContext, overlapOnly))
{
didCollide = true;
}
}

View file

@ -18,18 +18,16 @@ var Enable = {
* @method Phaser.Physics.Arcade.Components.Enable#enableBody
* @since 3.0.0
*
* @param {[type]} reset - [description]
* @param {[type]} x - [description]
* @param {[type]} y - [description]
* @param {[type]} enableGameObject - [description]
* @param {[type]} showGameObject - [description]
* @param {boolean} reset - [description]
* @param {number} x - [description]
* @param {number} y - [description]
* @param {boolean} enableGameObject - [description]
* @param {boolean} showGameObject - [description]
*
* @return {[type]} [description]
* @return {Phaser.GameObjects.GameObject} This Game Object.
*/
enableBody: function (reset, x, y, enableGameObject, showGameObject)
{
this.body.enable = true;
if (reset)
{
this.body.reset(x, y);
@ -45,6 +43,8 @@ var Enable = {
this.body.gameObject.visible = true;
}
this.body.enable = true;
return this;
},
@ -54,10 +54,10 @@ var Enable = {
* @method Phaser.Physics.Arcade.Components.Enable#disableBody
* @since 3.0.0
*
* @param {[type]} disableGameObject - [description]
* @param {[type]} hideGameObject - [description]
* @param {boolean} [disableGameObject=false] - [description]
* @param {boolean} [hideGameObject=false] - [description]
*
* @return {[type]} [description]
* @return {Phaser.GameObjects.GameObject} This Game Object.
*/
disableBody: function (disableGameObject, hideGameObject)
{
@ -78,6 +78,24 @@ var Enable = {
this.body.gameObject.visible = false;
}
return this;
},
/**
* Syncs the Bodies position and size with its parent Game Object.
* You don't need to call this for Dynamic Bodies, as it happens automatically.
* But for Static bodies it's a useful way of modifying the position of a Static Body
* in the Physics World, based on its Game Object.
*
* @method Phaser.Physics.Arcade.Components.Enable#refreshBody
* @since 3.1.0
*
* @return {Phaser.GameObjects.GameObject} This Game Object.
*/
refreshBody: function ()
{
this.body.updateFromGameObject();
return this;
}

View file

@ -516,7 +516,7 @@ var Body = new Class({
*
* @param {object} config - [description]
*/
fromJSON: function (config)
fromJSON: function ()
{
},
@ -526,9 +526,9 @@ var Body = new Class({
* @method Phaser.Physics.Impact.Body#check
* @since 3.0.0
*
* @param {[type]} other - [description]
* @param {Phaser.Physics.Impact.Body} other - [description]
*/
check: function (other)
check: function ()
{
},
@ -559,7 +559,7 @@ var Body = new Class({
*
* @return {boolean} [description]
*/
handleMovementTrace: function (res)
handleMovementTrace: function ()
{
return true;
},

View file

@ -172,19 +172,22 @@ var World = new Class({
var _this = this;
var engine = this.engine;
MatterEvents.on(engine, 'beforeUpdate', function (event) {
MatterEvents.on(engine, 'beforeUpdate', function (event)
{
_this.emit('beforeupdate', event);
});
MatterEvents.on(engine, 'afterUpdate', function (event) {
MatterEvents.on(engine, 'afterUpdate', function (event)
{
_this.emit('afterupdate', event);
});
MatterEvents.on(engine, 'collisionStart', function (event) {
MatterEvents.on(engine, 'collisionStart', function (event)
{
var pairs = event.pairs;
var bodyA;
@ -200,7 +203,8 @@ var World = new Class({
});
MatterEvents.on(engine, 'collisionActive', function (event) {
MatterEvents.on(engine, 'collisionActive', function (event)
{
var pairs = event.pairs;
var bodyA;
@ -216,7 +220,8 @@ var World = new Class({
});
MatterEvents.on(engine, 'collisionEnd', function (event) {
MatterEvents.on(engine, 'collisionEnd', function (event)
{
var pairs = event.pairs;
var bodyA;
@ -480,9 +485,7 @@ var World = new Class({
convertTilemapLayer: function (tilemapLayer, options)
{
var layerData = tilemapLayer.layer;
var tiles = tilemapLayer.getTilesWithin(0, 0, layerData.width, layerData.height, {
isColliding: true
});
var tiles = tilemapLayer.getTilesWithin(0, 0, layerData.width, layerData.height, {isColliding: true});
this.convertTiles(tiles, options);
@ -661,9 +664,12 @@ var World = new Class({
{
if (points === undefined) { points = []; }
// var pathPattern = /L?\s*([-\d.e]+)[\s,]*([-\d.e]+)*/ig;
// eslint-disable-next-line no-useless-escape
var pathPattern = /L?\s*([\-\d\.e]+)[\s,]*([\-\d\.e]+)*/ig;
path.replace(pathPattern, function(match, x, y)
path.replace(pathPattern, function (match, x, y)
{
points.push({ x: parseFloat(x), y: parseFloat(y) });
});

View file

@ -75,7 +75,7 @@ var Collision = {
this.body.collisionFilter.mask = flags;
return this;
},
}
};

View file

@ -68,7 +68,8 @@ var Sleep = {
{
var world = this.world;
MatterEvents.on(this.body, 'sleepStart', function (event) {
MatterEvents.on(this.body, 'sleepStart', function (event)
{
world.emit('sleepstart', event, this);
});
}
@ -96,7 +97,8 @@ var Sleep = {
{
var world = this.world;
MatterEvents.on(this.body, 'sleepEnd', function (event) {
MatterEvents.on(this.body, 'sleepEnd', function (event)
{
world.emit('sleepend', event, this);
});
}

View file

@ -103,7 +103,7 @@ module.exports = {
/**
* Hard Light blend mode.
*
* @name Phaser.BlendModes.SOFT_LIGHT
* @name Phaser.BlendModes.HARD_LIGHT
* @type {integer}
* @since 3.0.0
*/

View file

@ -268,7 +268,7 @@ var CanvasRenderer = new Class({
*
* @param {function} callback - [description]
*/
onContextLost: function (callback)
onContextLost: function ()
{
},
@ -280,7 +280,7 @@ var CanvasRenderer = new Class({
*
* @param {function} callback - [description]
*/
onContextRestored: function (callback)
onContextRestored: function ()
{
},

View file

@ -40,6 +40,7 @@ var DrawImage = function (src, camera)
if (this.currentScaleMode !== src.scaleMode)
{
this.currentScaleMode = src.scaleMode;
// ctx[this.smoothProperty] = (source.scaleMode === ScaleModes.LINEAR);
}

View file

@ -97,10 +97,11 @@ module.exports = {
* @since 3.0.0
*
* @param {number} attributes - [description]
* @param {WebGLRenderingContext} glContext - [description]
*
* @return {number} [description]
*/
getComponentCount: function (attributes)
getComponentCount: function (attributes, glContext)
{
var count = 0;
@ -108,7 +109,7 @@ module.exports = {
{
var element = attributes[index];
if (element.type === WebGLRenderingContext.FLOAT)
if (element.type === glContext.FLOAT)
{
count += element.size;
}

View file

@ -155,7 +155,7 @@ var WebGLPipeline = new Class({
* [description]
*
* @name Phaser.Renderer.WebGL.WebGLPipeline#vertexSize
* @type {int}
* @type {integer}
* @since 3.0.0
*/
this.vertexSize = config.vertexSize;
@ -164,7 +164,7 @@ var WebGLPipeline = new Class({
* [description]
*
* @name Phaser.Renderer.WebGL.WebGLPipeline#topology
* @type {int}
* @type {integer}
* @since 3.0.0
*/
this.topology = config.topology;
@ -182,10 +182,20 @@ var WebGLPipeline = new Class({
* This will store the amount of components of 32 bit length
*
* @name Phaser.Renderer.WebGL.WebGLPipeline#vertexComponentCount
* @type {int}
* @type {integer}
* @since 3.0.0
*/
this.vertexComponentCount = Utils.getComponentCount(config.attributes);
this.vertexComponentCount = Utils.getComponentCount(config.attributes, this.gl);
/**
* Indicates if the current pipeline is flushing the contents to the GPU.
* When the variable is set the flush function will be locked.
*
* @name Phaser.Renderer.WebGL.WebGLPipeline#flushLocked
* @type {boolean}
* @since 3.1.0
*/
this.flushLocked = false;
},
/**
@ -298,7 +308,7 @@ var WebGLPipeline = new Class({
*
* @return {Phaser.Renderer.WebGL.WebGLPipeline} [description]
*/
onRender: function (scene, camera)
onRender: function ()
{
// called for each camera
return this;
@ -328,19 +338,26 @@ var WebGLPipeline = new Class({
*/
flush: function ()
{
if (this.flushLocked) { return this; }
this.flushLocked = true;
var gl = this.gl;
var vertexCount = this.vertexCount;
var vertexBuffer = this.vertexBuffer;
var vertexData = this.vertexData;
var topology = this.topology;
var vertexSize = this.vertexSize;
if (vertexCount === 0) return;
if (vertexCount === 0)
{
this.flushLocked = false;
return;
}
gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.bytes.subarray(0, vertexCount * vertexSize));
gl.drawArrays(topology, 0, vertexCount);
this.vertexCount = 0;
this.flushLocked = false;
return this;
},

View file

@ -33,6 +33,7 @@ var WebGLRenderer = new Class({
function WebGLRenderer (game)
{
// eslint-disable-next-line consistent-this
var renderer = this;
var contextCreationConfig = {
@ -178,16 +179,16 @@ var WebGLRenderer = new Class({
encoder: null
};
for (var i = 0; i <= 16; i++)
{
this.blendModes.push({ func: [ WebGLRenderingContext.ONE, WebGLRenderingContext.ONE_MINUS_SRC_ALPHA ], equation: WebGLRenderingContext.FUNC_ADD });
}
// Internal Renderer State (Textures, Framebuffers, Pipelines, Buffers, etc)
this.blendModes[1].func = [ WebGLRenderingContext.ONE, WebGLRenderingContext.DST_ALPHA ];
this.blendModes[2].func = [ WebGLRenderingContext.DST_COLOR, WebGLRenderingContext.ONE_MINUS_SRC_ALPHA ];
this.blendModes[3].func = [ WebGLRenderingContext.ONE, WebGLRenderingContext.ONE_MINUS_SRC_COLOR ];
// Intenal Renderer State (Textures, Framebuffers, Pipelines, Buffers, etc)
/**
* [description]
*
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentActiveTextureUnit
* @type {integer}
* @since 3.1.0
*/
this.currentActiveTextureUnit = 0;
/**
* [description]
@ -252,7 +253,7 @@ var WebGLRenderer = new Class({
* [description]
*
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentBlendMode
* @type {int}
* @type {integer}
* @since 3.0.0
*/
this.currentBlendMode = Infinity;
@ -274,7 +275,7 @@ var WebGLRenderer = new Class({
* @type {Uint32Array}
* @since 3.0.0
*/
this.currentScissor = new Uint32Array([0, 0, this.width, this.height]);
this.currentScissor = new Uint32Array([ 0, 0, this.width, this.height ]);
/**
* [description]
@ -293,11 +294,12 @@ var WebGLRenderer = new Class({
* @type {Uint32Array}
* @since 3.0.0
*/
this.scissorStack = new Uint32Array(4 * 1000);
this.scissorStack = new Uint32Array(4 * 1000);
// Setup context lost and restore event listeners
this.canvas.addEventListener('webglcontextlost', function (event) {
this.canvas.addEventListener('webglcontextlost', function (event)
{
renderer.contextLost = true;
event.preventDefault();
@ -308,7 +310,8 @@ var WebGLRenderer = new Class({
}
}, false);
this.canvas.addEventListener('webglcontextrestored', function (event) {
this.canvas.addEventListener('webglcontextrestored', function ()
{
renderer.contextLost = false;
renderer.init(renderer.config);
for (var index = 0; index < renderer.restoredContextCallbacks.length; ++index)
@ -377,6 +380,15 @@ var WebGLRenderer = new Class({
this.gl = gl;
for (var i = 0; i <= 16; i++)
{
this.blendModes.push({ func: [ gl.ONE, gl.ONE_MINUS_SRC_ALPHA ], equation: gl.FUNC_ADD });
}
this.blendModes[1].func = [ gl.ONE, gl.DST_ALPHA ];
this.blendModes[2].func = [ gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA ];
this.blendModes[3].func = [ gl.ONE, gl.ONE_MINUS_SRC_COLOR ];
// Load supported extensions
this.supportedExtensions = gl.getSupportedExtensions();
@ -460,7 +472,7 @@ var WebGLRenderer = new Class({
*/
onContextRestored: function (callback, target)
{
this.restoredContextCallbacks.push([callback, target]);
this.restoredContextCallbacks.push([ callback, target ]);
return this;
},
@ -477,7 +489,7 @@ var WebGLRenderer = new Class({
*/
onContextLost: function (callback, target)
{
this.lostContextCallbacks.push([callback, target]);
this.lostContextCallbacks.push([ callback, target ]);
return this;
},
@ -508,7 +520,7 @@ var WebGLRenderer = new Class({
*/
getExtension: function (extensionName)
{
if (!this.hasExtension(extensionName)) return null;
if (!this.hasExtension(extensionName)) { return null; }
if (!(extensionName in this.extensions))
{
@ -593,8 +605,8 @@ var WebGLRenderer = new Class({
*/
addPipeline: function (pipelineName, pipelineInstance)
{
if (!this.hasPipeline(pipelineName)) this.pipelines[pipelineName] = pipelineInstance;
else console.warn('Pipeline', pipelineName, ' already exists.');
if (!this.hasPipeline(pipelineName)) { this.pipelines[pipelineName] = pipelineInstance; }
else { console.warn('Pipeline', pipelineName, ' already exists.'); }
pipelineInstance.name = pipelineName;
this.pipelines[pipelineName].resize(this.width, this.height, this.config.resolution);
@ -608,10 +620,10 @@ var WebGLRenderer = new Class({
* @method Phaser.Renderer.WebGL.WebGLRenderer#setScissor
* @since 3.0.0
*
* @param {int} x - [description]
* @param {int} y - [description]
* @param {int} w - [description]
* @param {int} h - [description]
* @param {integer} x - [description]
* @param {integer} y - [description]
* @param {integer} w - [description]
* @param {integer} h - [description]
*
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
*/
@ -619,11 +631,11 @@ var WebGLRenderer = new Class({
{
var gl = this.gl;
var currentScissor = this.currentScissor;
var enabled = (x == 0 && y == 0 && w == gl.canvas.width && h == gl.canvas.height && w >= 0 && h >= 0);
var enabled = (x === 0 && y === 0 && w === gl.canvas.width && h === gl.canvas.height && w >= 0 && h >= 0);
if (currentScissor[0] !== x ||
currentScissor[1] !== y ||
currentScissor[2] !== w ||
if (currentScissor[0] !== x ||
currentScissor[1] !== y ||
currentScissor[2] !== w ||
currentScissor[3] !== h)
{
this.flush();
@ -654,10 +666,10 @@ var WebGLRenderer = new Class({
* @method Phaser.Renderer.WebGL.WebGLRenderer#pushScissor
* @since 3.0.0
*
* @param {int} x - [description]
* @param {int} y - [description]
* @param {int} w - [description]
* @param {int} h - [description]
* @param {integer} x - [description]
* @param {integer} y - [description]
* @param {integer} w - [description]
* @param {integer} h - [description]
*
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
*/
@ -697,7 +709,7 @@ var WebGLRenderer = new Class({
var h = scissorStack[stackIndex + 3];
this.currentScissorIdx = stackIndex;
this.setScissor(x, y, w, h);
this.setScissor(x, y, w, h);
return this;
},
@ -734,7 +746,7 @@ var WebGLRenderer = new Class({
* @method Phaser.Renderer.WebGL.WebGLRenderer#setBlendMode
* @since 3.0.0
*
* @param {int} blendModeId - [description]
* @param {integer} blendModeId - [description]
*
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
*/
@ -766,6 +778,38 @@ var WebGLRenderer = new Class({
return this;
},
addBlendMode: function (func, equation)
{
var index = this.blendModes.push({ func: func, equation: equation });
return index - 1;
},
updateBlendMode: function (index, func, equation)
{
if (this.blendModes[index])
{
this.blendModes[index].func = func;
if (equation)
{
this.blendModes[index].equation = equation;
}
}
return this;
},
removeBlendMode: function (index)
{
if (index > 16 && this.blendModes[index])
{
this.blendModes.splice(index, 1);
}
return this;
},
/**
* [description]
*
@ -773,7 +817,7 @@ var WebGLRenderer = new Class({
* @since 3.0.0
*
* @param {WebGLTexture} texture - [description]
* @param {int} textureUnit - [description]
* @param {integer} textureUnit - [description]
*
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
*/
@ -785,7 +829,11 @@ var WebGLRenderer = new Class({
{
this.flush();
gl.activeTexture(gl.TEXTURE0 + textureUnit);
if (this.currentActiveTextureUnit !== textureUnit)
{
gl.activeTexture(gl.TEXTURE0 + textureUnit);
this.currentActiveTextureUnit = textureUnit;
}
gl.bindTexture(gl.TEXTURE_2D, texture);
this.currentTextures[textureUnit] = texture;
@ -902,14 +950,14 @@ var WebGLRenderer = new Class({
* @since 3.0.0
*
* @param {object} source - [description]
* @param {int} width - [description]
* @param {int} height - [description]
* @param {int} scaleMode - [description]
* @param {integer} width - [description]
* @param {integer} height - [description]
* @param {integer} scaleMode - [description]
*
* @return {WebGLTexture} [description]
*/
createTextureFromSource: function (source, width, height, scaleMode)
{
{
var gl = this.gl;
var filter = gl.NEAREST;
var wrap = gl.CLAMP_TO_EDGE;
@ -950,15 +998,15 @@ var WebGLRenderer = new Class({
* @method Phaser.Renderer.WebGL.WebGLRenderer#createTexture2D
* @since 3.0.0
*
* @param {int} mipLevel - [description]
* @param {int} minFilter - [description]
* @param {int} magFilter - [description]
* @param {int} wrapT - [description]
* @param {int} wrapS - [description]
* @param {int} format - [description]
* @param {integer} mipLevel - [description]
* @param {integer} minFilter - [description]
* @param {integer} magFilter - [description]
* @param {integer} wrapT - [description]
* @param {integer} wrapS - [description]
* @param {integer} format - [description]
* @param {object} pixels - [description]
* @param {int} width - [description]
* @param {int} height - [description]
* @param {integer} width - [description]
* @param {integer} height - [description]
* @param {boolean} pma - [description]
*
* @return {WebGLTexture} [description]
@ -968,7 +1016,7 @@ var WebGLRenderer = new Class({
var gl = this.gl;
var texture = gl.createTexture();
pma = (pma === undefined || pma === null) ? true : pma;
pma = (pma === undefined || pma === null) ? true : pma;
this.setTexture2D(texture, 0);
@ -1007,8 +1055,8 @@ var WebGLRenderer = new Class({
* @method Phaser.Renderer.WebGL.WebGLRenderer#createFramebuffer
* @since 3.0.0
*
* @param {int} width - [description]
* @param {int} height - [description]
* @param {integer} width - [description]
* @param {integer} height - [description]
* @param {WebGLFramebuffer} renderTexture - [description]
* @param {boolean} addDepthStencilBuffer - [description]
*
@ -1106,7 +1154,7 @@ var WebGLRenderer = new Class({
* @since 3.0.0
*
* @param {ArrayBuffer} initialDataOrSize - [description]
* @param {int} bufferUsage - [description]
* @param {integer} bufferUsage - [description]
*
* @return {WebGLBuffer} [description]
*/
@ -1129,7 +1177,7 @@ var WebGLRenderer = new Class({
* @since 3.0.0
*
* @param {ArrayBuffer} initialDataOrSize - [description]
* @param {int} bufferUsage - [description]
* @param {integer} bufferUsage - [description]
*
* @return {WebGLBuffer} [description]
*/
@ -1157,6 +1205,7 @@ var WebGLRenderer = new Class({
*/
deleteTexture: function (texture)
{
this.gl.deleteTexture(texture);
return this;
},
@ -1172,6 +1221,7 @@ var WebGLRenderer = new Class({
*/
deleteFramebuffer: function (framebuffer)
{
this.gl.deleteFramebuffer(framebuffer);
return this;
},
@ -1187,6 +1237,7 @@ var WebGLRenderer = new Class({
*/
deleteProgram: function (program)
{
this.gl.deleteProgram(program);
return this;
},
@ -1200,8 +1251,9 @@ var WebGLRenderer = new Class({
*
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
*/
deleteBuffer: function (vertexBuffer)
deleteBuffer: function (buffer)
{
this.gl.deleteBuffer(buffer);
return this;
},
@ -1227,12 +1279,12 @@ var WebGLRenderer = new Class({
var FlatTintPipeline = this.pipelines.FlatTintPipeline;
FlatTintPipeline.batchFillRect(
0, 0, 1, 1, 0,
camera.x, camera.y, camera.width, camera.height,
0, 0, 1, 1, 0,
camera.x, camera.y, camera.width, camera.height,
Utils.getTintFromFloats(color.redGL, color.greenGL, color.blueGL, 1.0),
color.alphaGL,
1, 0, 0, 1, 0, 0,
[1, 0, 0, 1, 0, 0]
[ 1, 0, 0, 1, 0, 0 ]
);
FlatTintPipeline.flush();
@ -1255,22 +1307,22 @@ var WebGLRenderer = new Class({
// Fade
FlatTintPipeline.batchFillRect(
0, 0, 1, 1, 0,
camera.x, camera.y, camera.width, camera.height,
0, 0, 1, 1, 0,
camera.x, camera.y, camera.width, camera.height,
Utils.getTintFromFloats(camera._fadeRed, camera._fadeGreen, camera._fadeBlue, 1.0),
camera._fadeAlpha,
1, 0, 0, 1, 0, 0,
[1, 0, 0, 1, 0, 0]
[ 1, 0, 0, 1, 0, 0 ]
);
// Flash
FlatTintPipeline.batchFillRect(
0, 0, 1, 1, 0,
camera.x, camera.y, camera.width, camera.height,
0, 0, 1, 1, 0,
camera.x, camera.y, camera.width, camera.height,
Utils.getTintFromFloats(camera._flashRed, camera._flashGreen, camera._flashBlue, 1.0),
camera._flashAlpha,
1, 0, 0, 1, 0, 0,
[1, 0, 0, 1, 0, 0]
[ 1, 0, 0, 1, 0, 0 ]
);
FlatTintPipeline.flush();
@ -1287,7 +1339,7 @@ var WebGLRenderer = new Class({
*/
preRender: function ()
{
if (this.contextLost) return;
if (this.contextLost) { return; }
var gl = this.gl;
var color = this.config.backgroundColor;
@ -1297,7 +1349,7 @@ var WebGLRenderer = new Class({
gl.clearColor(color.redGL, color.greenGL, color.blueGL, color.alphaGL);
if (this.config.clearBeforeRender)
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
{ gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT); }
for (var key in pipelines)
{
@ -1318,9 +1370,8 @@ var WebGLRenderer = new Class({
*/
render: function (scene, children, interpolationPercentage, camera)
{
if (this.contextLost) return;
if (this.contextLost) { return; }
var gl = this.gl;
var list = children.list;
var childCount = list.length;
var pipelines = this.pipelines;
@ -1372,7 +1423,7 @@ var WebGLRenderer = new Class({
*/
postRender: function ()
{
if (this.contextLost) return;
if (this.contextLost) { return; }
// Unbind custom framebuffer here
@ -1419,11 +1470,11 @@ var WebGLRenderer = new Class({
* @param {HTMLCanvasElement} srcCanvas - [description]
* @param {WebGLTexture} dstTexture - [description]
* @param {boolean} shouldReallocate - [description]
* @param {int} scaleMode - [description]
* @param {integer} scaleMode - [description]
*
* @return {WebGLTexture} [description]
*/
canvasToTexture: function (srcCanvas, dstTexture, shouldReallocate, scaleMode)
canvasToTexture: function (srcCanvas, dstTexture, shouldReallocate)
{
var gl = this.gl;
@ -1465,8 +1516,8 @@ var WebGLRenderer = new Class({
* @method Phaser.Renderer.WebGL.WebGLRenderer#setTextureFilter
* @since 3.0.0
*
* @param {int} texture - [description]
* @param {int} filter - [description]
* @param {integer} texture - [description]
* @param {integer} filter - [description]
*
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
*/
@ -1575,7 +1626,7 @@ var WebGLRenderer = new Class({
*
* @param {WebGLProgram} program - [description]
* @param {string} name - [description]
* @param {int} x - [description]
* @param {integer} x - [description]
*
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
*/
@ -1594,8 +1645,8 @@ var WebGLRenderer = new Class({
*
* @param {WebGLProgram} program - [description]
* @param {string} name - [description]
* @param {int} x - [description]
* @param {int} y - [description]
* @param {integer} x - [description]
* @param {integer} y - [description]
*
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
*/
@ -1614,9 +1665,9 @@ var WebGLRenderer = new Class({
*
* @param {WebGLProgram} program - [description]
* @param {string} name - [description]
* @param {int} x - [description]
* @param {int} y - [description]
* @param {int} z - [description]
* @param {integer} x - [description]
* @param {integer} y - [description]
* @param {integer} z - [description]
*
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
*/
@ -1635,10 +1686,10 @@ var WebGLRenderer = new Class({
*
* @param {WebGLProgram} program - [description]
* @param {string} name - [description]
* @param {int} x - [description]
* @param {int} y - [description]
* @param {int} z - [description]
* @param {int} w - [description]
* @param {integer} x - [description]
* @param {integer} y - [description]
* @param {integer} z - [description]
* @param {integer} w - [description]
*
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
*/
@ -1717,8 +1768,6 @@ var WebGLRenderer = new Class({
*/
destroy: function ()
{
var gl = this.gl;
// Clear-up anything that should be cleared :)
for (var key in this.pipelines)
{
@ -1729,7 +1778,7 @@ var WebGLRenderer = new Class({
for (var index = 0; index < this.nativeTextures.length; ++index)
{
this.deleteTexture(this.nativeTextures[index]);
delete this.nativeTextures[index];
delete this.nativeTextures[index];
}
if (this.hasExtension('WEBGL_lose_context'))

View file

@ -6,8 +6,7 @@
var Class = require('../../../utils/Class');
var ShaderSourceFS = require('../shaders/BitmapMask.frag');
var ShaderSourceVS = require('../shaders/BitmapMask.vert');
var Utils = require('../Utils');
var ShaderSourceVS = require('../shaders/BitmapMask.vert');
var WebGLPipeline = require('../WebGLPipeline');
/**
@ -41,7 +40,7 @@ var BitmapMaskPipeline = new Class({
fragShader: ShaderSourceFS,
vertexCapacity: 3,
vertexSize:
vertexSize:
Float32Array.BYTES_PER_ELEMENT * 2,
vertices: new Float32Array([
@ -192,8 +191,10 @@ var BitmapMaskPipeline = new Class({
// Bind bitmap mask pipeline and draw
renderer.setPipeline(this);
renderer.setTexture2D(mask.mainTexture, 0);
renderer.setTexture2D(mask.maskTexture, 1);
renderer.setTexture2D(mask.mainTexture, 0);
renderer.setInt1(this.program, 'uInvertMaskAlpha', mask.invertAlpha);
// Finally draw a triangle filling the whole screen
gl.drawArrays(this.topology, 0, 3);

View file

@ -8,8 +8,8 @@ var Class = require('../../../utils/Class');
var Commands = require('../../../gameobjects/graphics/Commands');
var Earcut = require('../../../geom/polygon/Earcut');
var ModelViewProjection = require('./components/ModelViewProjection');
var ShaderSourceFS = require('../shaders/FlatTint.frag');
var ShaderSourceVS = require('../shaders/FlatTint.vert');
var ShaderSourceFS = require('../shaders/FlatTint.frag');
var ShaderSourceVS = require('../shaders/FlatTint.vert');
var Utils = require('../Utils');
var WebGLPipeline = require('../WebGLPipeline');
@ -29,7 +29,7 @@ var Path = function (x, y, width, rgb, alpha)
this.points[0] = new Point(x, y, width, rgb, alpha);
};
var currentMatrix = new Float32Array([1, 0, 0, 1, 0, 0]);
var currentMatrix = new Float32Array([ 1, 0, 0, 1, 0, 0 ]);
var matrixStack = new Float32Array(6 * 1000);
var matrixStackLength = 0;
var pathArray = [];
@ -69,8 +69,8 @@ var FlatTintPipeline = new Class({
fragShader: ShaderSourceFS,
vertexCapacity: 12000,
vertexSize:
Float32Array.BYTES_PER_ELEMENT * 2 +
vertexSize:
Float32Array.BYTES_PER_ELEMENT * 2 +
Uint8Array.BYTES_PER_ELEMENT * 4,
attributes: [
@ -187,7 +187,7 @@ var FlatTintPipeline = new Class({
* @param {float} y - [description]
* @param {float} width - [description]
* @param {float} height - [description]
* @param {int} fillColor - [description]
* @param {integer} fillColor - [description]
* @param {float} fillAlpha - [description]
* @param {float} a1 - [description]
* @param {float} b1 - [description]
@ -196,10 +196,9 @@ var FlatTintPipeline = new Class({
* @param {float} e1 - [description]
* @param {float} f1 - [description]
* @param {Float32Array} currentMatrix - [description]
* @param {boolean} roundPixels - [description]
*/
batchFillRect: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, x, y, width, height, fillColor, fillAlpha, a1, b1, c1, d1, e1, f1, currentMatrix, roundPixels)
{
batchFillRect: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, x, y, width, height, fillColor, fillAlpha, a1, b1, c1, d1, e1, f1, currentMatrix)
{
this.renderer.setPipeline(this);
if (this.vertexCount + 6 > this.vertexCapacity)
@ -207,8 +206,8 @@ var FlatTintPipeline = new Class({
this.flush();
}
var renderer = this.renderer;
var resolution = renderer.config.resolution;
var renderer = this.renderer;
var resolution = renderer.config.resolution; // eslint-disable-line no-unused-vars
var vertexViewF32 = this.vertexViewF32;
var vertexViewU32 = this.vertexViewU32;
var vertexOffset = this.vertexCount * this.vertexComponentCount;
@ -236,18 +235,6 @@ var FlatTintPipeline = new Class({
var ty3 = xw * b + y * d + f;
var tint = Utils.getTintAppendFloatAlphaAndSwap(fillColor, fillAlpha);
if (roundPixels)
{
tx0 = ((tx0 * resolution)|0) / resolution;
ty0 = ((ty0 * resolution)|0) / resolution;
tx1 = ((tx1 * resolution)|0) / resolution;
ty1 = ((ty1 * resolution)|0) / resolution;
tx2 = ((tx2 * resolution)|0) / resolution;
ty2 = ((ty2 * resolution)|0) / resolution;
tx3 = ((tx3 * resolution)|0) / resolution;
ty3 = ((ty3 * resolution)|0) / resolution;
}
vertexViewF32[vertexOffset + 0] = tx0;
vertexViewF32[vertexOffset + 1] = ty0;
vertexViewU32[vertexOffset + 2] = tint;
@ -287,7 +274,7 @@ var FlatTintPipeline = new Class({
* @param {float} y1 - [description]
* @param {float} x2 - [description]
* @param {float} y2 - [description]
* @param {int} fillColor - [description]
* @param {integer} fillColor - [description]
* @param {float} fillAlpha - [description]
* @param {float} a1 - [description]
* @param {float} b1 - [description]
@ -296,9 +283,8 @@ var FlatTintPipeline = new Class({
* @param {float} e1 - [description]
* @param {float} f1 - [description]
* @param {Float32Array} currentMatrix - [description]
* @param {boolean} roundPixels - [description]
*/
batchFillTriangle: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, x0, y0, x1, y1, x2, y2, fillColor, fillAlpha, a1, b1, c1, d1, e1, f1, currentMatrix, roundPixels)
batchFillTriangle: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, x0, y0, x1, y1, x2, y2, fillColor, fillAlpha, a1, b1, c1, d1, e1, f1, currentMatrix)
{
this.renderer.setPipeline(this);
@ -307,8 +293,8 @@ var FlatTintPipeline = new Class({
this.flush();
}
var renderer = this.renderer;
var resolution = renderer.config.resolution;
var renderer = this.renderer;
var resolution = renderer.config.resolution; // eslint-disable-line no-unused-vars
var vertexViewF32 = this.vertexViewF32;
var vertexViewU32 = this.vertexViewU32;
var vertexOffset = this.vertexCount * this.vertexComponentCount;
@ -332,16 +318,6 @@ var FlatTintPipeline = new Class({
var ty2 = x2 * b + y2 * d + f;
var tint = Utils.getTintAppendFloatAlphaAndSwap(fillColor, fillAlpha);
if (roundPixels)
{
tx0 = ((tx0 * resolution)|0) / resolution;
ty0 = ((ty0 * resolution)|0) / resolution;
tx1 = ((tx1 * resolution)|0) / resolution;
ty1 = ((ty1 * resolution)|0) / resolution;
tx2 = ((tx2 * resolution)|0) / resolution;
ty2 = ((ty2 * resolution)|0) / resolution;
}
vertexViewF32[vertexOffset + 0] = tx0;
vertexViewF32[vertexOffset + 1] = ty0;
vertexViewU32[vertexOffset + 2] = tint;
@ -373,7 +349,7 @@ var FlatTintPipeline = new Class({
* @param {float} x2 - [description]
* @param {float} y2 - [description]
* @param {float} lineWidth - [description]
* @param {int} lineColor - [description]
* @param {integer} lineColor - [description]
* @param {float} lineAlpha - [description]
* @param {float} a - [description]
* @param {float} b - [description]
@ -382,9 +358,8 @@ var FlatTintPipeline = new Class({
* @param {float} e - [description]
* @param {float} f - [description]
* @param {Float32Array} currentMatrix - [description]
* @param {boolean} roundPixels - [description]
*/
batchStrokeTriangle: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, x0, y0, x1, y1, x2, y2, lineWidth, lineColor, lineAlpha, a, b, c, d, e, f, currentMatrix, roundPixels)
batchStrokeTriangle: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, x0, y0, x1, y1, x2, y2, lineWidth, lineColor, lineAlpha, a, b, c, d, e, f, currentMatrix)
{
var tempTriangle = this.tempTriangle;
@ -414,8 +389,7 @@ var FlatTintPipeline = new Class({
tempTriangle, lineWidth, lineColor, lineAlpha,
a, b, c, d, e, f,
false,
currentMatrix,
roundPixels
currentMatrix
);
},
@ -431,7 +405,7 @@ var FlatTintPipeline = new Class({
* @param {float} srcScaleY - [description]
* @param {float} srcRotation - [description]
* @param {float} path - [description]
* @param {int} fillColor - [description]
* @param {integer} fillColor - [description]
* @param {float} fillAlpha - [description]
* @param {float} a1 - [description]
* @param {float} b1 - [description]
@ -440,14 +414,13 @@ var FlatTintPipeline = new Class({
* @param {float} e1 - [description]
* @param {float} f1 - [description]
* @param {Float32Array} currentMatrix - [description]
* @param {boolean} roundPixels - [description]
*/
batchFillPath: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, path, fillColor, fillAlpha, a1, b1, c1, d1, e1, f1, currentMatrix, roundPixels)
batchFillPath: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, path, fillColor, fillAlpha, a1, b1, c1, d1, e1, f1, currentMatrix)
{
this.renderer.setPipeline(this);
var renderer = this.renderer;
var resolution = renderer.config.resolution;
var renderer = this.renderer;
var resolution = renderer.config.resolution; // eslint-disable-line no-unused-vars
var length = path.length;
var polygonCache = this.polygonCache;
var polygonIndexArray;
@ -508,16 +481,6 @@ var FlatTintPipeline = new Class({
tx2 = x2 * a + y2 * c + e;
ty2 = x2 * b + y2 * d + f;
if (roundPixels)
{
tx0 = ((tx0 * resolution)|0) / resolution;
ty0 = ((ty0 * resolution)|0) / resolution;
tx1 = ((tx1 * resolution)|0) / resolution;
ty1 = ((ty1 * resolution)|0) / resolution;
tx2 = ((tx2 * resolution)|0) / resolution;
ty2 = ((ty2 * resolution)|0) / resolution;
}
vertexViewF32[vertexOffset + 0] = tx0;
vertexViewF32[vertexOffset + 1] = ty0;
vertexViewU32[vertexOffset + 2] = tint;
@ -547,7 +510,7 @@ var FlatTintPipeline = new Class({
* @param {float} srcRotation - [description]
* @param {array} path - [description]
* @param {float} lineWidth - [description]
* @param {int} lineColor - [description]
* @param {integer} lineColor - [description]
* @param {float} lineAlpha - [description]
* @param {float} a - [description]
* @param {float} b - [description]
@ -557,9 +520,8 @@ var FlatTintPipeline = new Class({
* @param {float} f - [description]
* @param {boolean} isLastPath - [description]
* @param {Float32Array} currentMatrix - [description]
* @param {boolean} roundPixels - [description]
*/
batchStrokePath: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, path, lineWidth, lineColor, lineAlpha, a, b, c, d, e, f, isLastPath, currentMatrix, roundPixels)
batchStrokePath: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, path, lineWidth, lineColor, lineAlpha, a, b, c, d, e, f, isLastPath, currentMatrix)
{
this.renderer.setPipeline(this);
@ -585,8 +547,7 @@ var FlatTintPipeline = new Class({
point0.width / 2, point1.width / 2,
point0.rgb, point1.rgb, lineAlpha,
a, b, c, d, e, f,
currentMatrix,
roundPixels
currentMatrix
);
polylines.push(line);
@ -646,8 +607,8 @@ var FlatTintPipeline = new Class({
* @param {float} by - [description]
* @param {float} aLineWidth - [description]
* @param {float} bLineWidth - [description]
* @param {int} aLineColor - [description]
* @param {int} bLineColor - [description]
* @param {integer} aLineColor - [description]
* @param {integer} bLineColor - [description]
* @param {float} lineAlpha - [description]
* @param {float} a1 - [description]
* @param {float} b1 - [description]
@ -656,9 +617,8 @@ var FlatTintPipeline = new Class({
* @param {float} e1 - [description]
* @param {float} f1 - [description]
* @param {Float32Array} currentMatrix - [description]
* @param {boolean} roundPixels - [description]
*/
batchLine: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, ax, ay, bx, by, aLineWidth, bLineWidth, aLineColor, bLineColor, lineAlpha, a1, b1, c1, d1, e1, f1, currentMatrix, roundPixels)
batchLine: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, ax, ay, bx, by, aLineWidth, bLineWidth, aLineColor, bLineColor, lineAlpha, a1, b1, c1, d1, e1, f1, currentMatrix)
{
this.renderer.setPipeline(this);
@ -667,8 +627,8 @@ var FlatTintPipeline = new Class({
this.flush();
}
var renderer = this.renderer;
var resolution = renderer.config.resolution;
var renderer = this.renderer;
var resolution = renderer.config.resolution; // eslint-disable-line no-unused-vars
var a0 = currentMatrix[0];
var b0 = currentMatrix[1];
var c0 = currentMatrix[2];
@ -711,18 +671,6 @@ var FlatTintPipeline = new Class({
var bTint = getTint(bLineColor, lineAlpha);
var vertexOffset = this.vertexCount * this.vertexComponentCount;
if (roundPixels)
{
x0 = ((x0 * resolution)|0) / resolution;
y0 = ((y0 * resolution)|0) / resolution;
x1 = ((x1 * resolution)|0) / resolution;
y1 = ((y1 * resolution)|0) / resolution;
x2 = ((x2 * resolution)|0) / resolution;
y2 = ((y2 * resolution)|0) / resolution;
x3 = ((x3 * resolution)|0) / resolution;
y3 = ((y3 * resolution)|0) / resolution;
}
vertexViewF32[vertexOffset + 0] = x0;
vertexViewF32[vertexOffset + 1] = y0;
vertexViewU32[vertexOffset + 2] = bTint;
@ -731,7 +679,7 @@ var FlatTintPipeline = new Class({
vertexViewU32[vertexOffset + 5] = aTint;
vertexViewF32[vertexOffset + 6] = x2;
vertexViewF32[vertexOffset + 7] = y2;
vertexViewU32[vertexOffset + 8] = bTint
vertexViewU32[vertexOffset + 8] = bTint;
vertexViewF32[vertexOffset + 9] = x1;
vertexViewF32[vertexOffset + 10] = y1;
vertexViewU32[vertexOffset + 11] = aTint;
@ -763,7 +711,7 @@ var FlatTintPipeline = new Class({
*/
batchGraphics: function (graphics, camera)
{
if (graphics.commandBuffer.length <= 0) return;
if (graphics.commandBuffer.length <= 0) { return; }
this.renderer.setPipeline(this);
@ -816,7 +764,9 @@ var FlatTintPipeline = new Class({
var mvd = src * cmb + srd * cmd;
var mve = sre * cma + srf * cmc + cme;
var mvf = sre * cmb + srf * cmd + cmf;
var roundPixels = camera.roundPixels;
var pathArrayIndex;
var pathArrayLength;
pathArray.length = 0;
@ -892,52 +842,58 @@ var FlatTintPipeline = new Class({
break;
case Commands.FILL_PATH:
for (var pathArrayIndex = 0, pathArrayLength = pathArray.length;
for (pathArrayIndex = 0, pathArrayLength = pathArray.length;
pathArrayIndex < pathArrayLength;
++pathArrayIndex)
{
this.batchFillPath(
/* Graphics Game Object Properties */
srcX, srcY, srcScaleX, srcScaleY, srcRotation,
/* Rectangle properties */
pathArray[pathArrayIndex].points,
fillColor,
fillAlpha,
/* Transform */
mva, mvb, mvc, mvd, mve, mvf,
currentMatrix,
roundPixels
currentMatrix
);
}
break;
case Commands.STROKE_PATH:
for (var pathArrayIndex = 0, pathArrayLength = pathArray.length;
for (pathArrayIndex = 0, pathArrayLength = pathArray.length;
pathArrayIndex < pathArrayLength;
++pathArrayIndex)
{
path = pathArray[pathArrayIndex];
this.batchStrokePath(
/* Graphics Game Object Properties */
srcX, srcY, srcScaleX, srcScaleY, srcRotation,
/* Rectangle properties */
path.points,
lineWidth,
lineColor,
lineAlpha,
/* Transform */
mva, mvb, mvc, mvd, mve, mvf,
path === this._lastPath,
currentMatrix,
roundPixels
currentMatrix
);
}
break;
case Commands.FILL_RECT:
this.batchFillRect(
/* Graphics Game Object Properties */
srcX, srcY, srcScaleX, srcScaleY, srcRotation,
/* Rectangle properties */
commands[cmdIndex + 1],
commands[cmdIndex + 2],
@ -945,10 +901,10 @@ var FlatTintPipeline = new Class({
commands[cmdIndex + 4],
fillColor,
fillAlpha,
/* Transform */
mva, mvb, mvc, mvd, mve, mvf,
currentMatrix,
roundPixels
currentMatrix
);
cmdIndex += 4;
@ -956,8 +912,10 @@ var FlatTintPipeline = new Class({
case Commands.FILL_TRIANGLE:
this.batchFillTriangle(
/* Graphics Game Object Properties */
srcX, srcY, srcScaleX, srcScaleY, srcRotation,
/* Triangle properties */
commands[cmdIndex + 1],
commands[cmdIndex + 2],
@ -967,10 +925,10 @@ var FlatTintPipeline = new Class({
commands[cmdIndex + 6],
fillColor,
fillAlpha,
/* Transform */
mva, mvb, mvc, mvd, mve, mvf,
currentMatrix,
roundPixels
currentMatrix
);
cmdIndex += 6;
@ -978,8 +936,10 @@ var FlatTintPipeline = new Class({
case Commands.STROKE_TRIANGLE:
this.batchStrokeTriangle(
/* Graphics Game Object Properties */
srcX, srcY, srcScaleX, srcScaleY, srcRotation,
/* Triangle properties */
commands[cmdIndex + 1],
commands[cmdIndex + 2],
@ -990,10 +950,10 @@ var FlatTintPipeline = new Class({
lineWidth,
lineColor,
lineAlpha,
/* Transform */
mva, mvb, mvc, mvd, mve, mvf,
currentMatrix,
roundPixels
currentMatrix
);
cmdIndex += 6;
@ -1109,6 +1069,7 @@ var FlatTintPipeline = new Class({
break;
default:
// eslint-disable-next-line no-console
console.error('Phaser: Invalid Graphics Command ID ' + cmd);
break;
}
@ -1126,7 +1087,7 @@ var FlatTintPipeline = new Class({
* @param {Phaser.Tilemaps.StaticTilemapLayer} tilemap - [description]
* @param {Phaser.Cameras.Scene2D.Camera} camera - [description]
*/
drawStaticTilemapLayer: function (tilemap, camera)
drawStaticTilemapLayer: function ()
{
},
@ -1139,7 +1100,7 @@ var FlatTintPipeline = new Class({
* @param {Phaser.GameObjects.Particles.ParticleEmittermanager} emitterManager - [description]
* @param {Phaser.Cameras.Scene2D.Camera} camera - [description]
*/
drawEmitterManager: function (emitterManager, camera)
drawEmitterManager: function ()
{
},
@ -1152,7 +1113,7 @@ var FlatTintPipeline = new Class({
* @param {Phaser.GameObjects.Blitter} blitter - [description]
* @param {Phaser.Cameras.Scene2D.Camera} camera - [description]
*/
drawBlitter: function (blitter, camera)
drawBlitter: function ()
{
},
@ -1165,7 +1126,7 @@ var FlatTintPipeline = new Class({
* @param {Phaser.GameObjects.Sprite} sprite - [description]
* @param {Phaser.Cameras.Scene2D.Camera} camera - [description]
*/
batchSprite: function (sprite, camera)
batchSprite: function ()
{
},
@ -1178,7 +1139,7 @@ var FlatTintPipeline = new Class({
* @param {Phaser.GameObjects.Mesh} mesh - [description]
* @param {Phaser.Cameras.Scene2D.Camera} camera - [description]
*/
batchMesh: function (mesh, camera)
batchMesh: function ()
{
},
@ -1191,7 +1152,7 @@ var FlatTintPipeline = new Class({
* @param {Phaser.GameObjects.BitmapText} bitmapText - [description]
* @param {Phaser.Cameras.Scene2D.Camera} camera - [description]
*/
batchBitmapText: function (bitmapText, camera)
batchBitmapText: function ()
{
},
@ -1204,7 +1165,7 @@ var FlatTintPipeline = new Class({
* @param {Phaser.GameObjects.DynamicBitmapText} bitmapText - [description]
* @param {Phaser.Cameras.Scene2D.Camera} camera - [description]
*/
batchDynamicBitmapText: function (bitmapText, camera)
batchDynamicBitmapText: function ()
{
},
@ -1217,7 +1178,7 @@ var FlatTintPipeline = new Class({
* @param {Phaser.GameObjects.Text} text - [description]
* @param {Phaser.Cameras.Scene2D.Camera} camera - [description]
*/
batchText: function (text, camera)
batchText: function ()
{
},
@ -1230,7 +1191,7 @@ var FlatTintPipeline = new Class({
* @param {Phaser.Tilemaps.DynamicTilemapLayer} tilemapLayer - [description]
* @param {Phaser.Cameras.Scene2D.Camera} camera - [description]
*/
batchDynamicTilemapLayer: function (tilemapLayer, camera)
batchDynamicTilemapLayer: function ()
{
},
@ -1243,7 +1204,7 @@ var FlatTintPipeline = new Class({
* @param {Phaser.GameObjects.TileSprite} tileSprite - [description]
* @param {Phaser.Cameras.Scene2D.Camera} camera - [description]
*/
batchTileSprite: function (tileSprite, camera)
batchTileSprite: function ()
{
}

View file

@ -7,8 +7,6 @@
var Class = require('../../../utils/Class');
var ShaderSourceFS = require('../shaders/ForwardDiffuse.frag');
var TextureTintPipeline = require('./TextureTintPipeline');
var Utils = require('../Utils');
var WebGLPipeline = require('../WebGLPipeline');
var LIGHT_COUNT = 10;
@ -89,18 +87,19 @@ var ForwardDiffuseLightPipeline = new Class({
var cameraMatrix = camera.matrix;
var point = {x: 0, y: 0};
var height = renderer.height;
var index;
for (var index = 0; index < LIGHT_COUNT; ++index)
for (index = 0; index < LIGHT_COUNT; ++index)
{
renderer.setFloat1(program, 'uLights[' + index + '].radius', 0); // reset lights
}
if (lightCount <= 0) return this;
if (lightCount <= 0) { return this; }
renderer.setFloat4(program, 'uCamera', camera.x, camera.y, camera.rotation, camera.zoom);
renderer.setFloat3(program, 'uAmbientLightColor', lightManager.ambientColor.r, lightManager.ambientColor.g, lightManager.ambientColor.b);
for (var index = 0; index < lightCount; ++index)
for (index = 0; index < lightCount; ++index)
{
var light = lights[index];
var lightName = 'uLights[' + index + '].';
@ -130,6 +129,8 @@ var ForwardDiffuseLightPipeline = new Class({
if (normalTexture)
{
this.renderer.setPipeline(this);
this.setTexture2D(normalTexture.glTexture, 1);
TextureTintPipeline.prototype.drawStaticTilemapLayer.call(this, tilemap, camera);
}
else
@ -155,6 +156,8 @@ var ForwardDiffuseLightPipeline = new Class({
if (normalTexture)
{
this.renderer.setPipeline(this);
this.setTexture2D(normalTexture.glTexture, 1);
TextureTintPipeline.prototype.drawEmitterManager.call(this, emitterManager, camera);
}
else
@ -180,6 +183,8 @@ var ForwardDiffuseLightPipeline = new Class({
if (normalTexture)
{
this.renderer.setPipeline(this);
this.setTexture2D(normalTexture.glTexture, 1);
TextureTintPipeline.prototype.drawBlitter.call(this, blitter, camera);
}
else
@ -205,7 +210,8 @@ var ForwardDiffuseLightPipeline = new Class({
if (normalTexture)
{
this.renderer.setTexture2D(normalTexture.glTexture, 1);
this.renderer.setPipeline(this);
this.setTexture2D(normalTexture.glTexture, 1);
TextureTintPipeline.prototype.batchSprite.call(this, sprite, camera);
}
else
@ -231,7 +237,8 @@ var ForwardDiffuseLightPipeline = new Class({
if (normalTexture)
{
this.renderer.setTexture2D(normalTexture.glTexture, 1);
this.renderer.setPipeline(this);
this.setTexture2D(normalTexture.glTexture, 1);
TextureTintPipeline.prototype.batchMesh.call(this, mesh, camera);
}
else
@ -258,6 +265,8 @@ var ForwardDiffuseLightPipeline = new Class({
if (normalTexture)
{
this.renderer.setPipeline(this);
this.setTexture2D(normalTexture.glTexture, 1);
TextureTintPipeline.prototype.batchBitmapText.call(this, bitmapText, camera);
}
else
@ -283,6 +292,8 @@ var ForwardDiffuseLightPipeline = new Class({
if (normalTexture)
{
this.renderer.setPipeline(this);
this.setTexture2D(normalTexture.glTexture, 1);
TextureTintPipeline.prototype.batchDynamicBitmapText.call(this, bitmapText, camera);
}
else
@ -308,6 +319,8 @@ var ForwardDiffuseLightPipeline = new Class({
if (normalTexture)
{
this.renderer.setPipeline(this);
this.setTexture2D(normalTexture.glTexture, 1);
TextureTintPipeline.prototype.batchText.call(this, text, camera);
}
else
@ -333,6 +346,8 @@ var ForwardDiffuseLightPipeline = new Class({
if (normalTexture)
{
this.renderer.setPipeline(this);
this.setTexture2D(normalTexture.glTexture, 1);
TextureTintPipeline.prototype.batchDynamicTilemapLayer.call(this, tilemapLayer, camera);
}
else
@ -358,6 +373,8 @@ var ForwardDiffuseLightPipeline = new Class({
if (normalTexture)
{
this.renderer.setPipeline(this);
this.setTexture2D(normalTexture.glTexture, 1);
TextureTintPipeline.prototype.batchTileSprite.call(this, tileSprite, camera);
}
else

File diff suppressed because it is too large Load diff

View file

@ -369,16 +369,16 @@ var ModelViewProjection = {
vm[2] = 0.0;
vm[3] = 0.0;
vm[4] = matrix2D[2];
vm[5] = matrix2D[3];
vm[6] = 0.0;
vm[5] = matrix2D[3];
vm[6] = 0.0;
vm[7] = 0.0;
vm[8] = matrix2D[4];
vm[9] = matrix2D[5];
vm[10] = 1.0;
vm[9] = matrix2D[5];
vm[10] = 1.0;
vm[11] = 0.0;
vm[12] = 0.0;
vm[13] = 0.0;
vm[14] = 0.0;
vm[12] = 0.0;
vm[13] = 0.0;
vm[14] = 0.0;
vm[15] = 1.0;
this.viewMatrixDirty = true;

View file

@ -5,12 +5,23 @@ precision mediump float;
uniform vec2 uResolution;
uniform sampler2D uMainSampler;
uniform sampler2D uMaskSampler;
uniform bool uInvertMaskAlpha;
void main()
{
vec2 uv = gl_FragCoord.xy / uResolution;
vec4 mainColor = texture2D(uMainSampler, uv);
vec4 maskColor = texture2D(uMaskSampler, uv);
float alpha = maskColor.a * mainColor.a;
float alpha = mainColor.a;
if (!uInvertMaskAlpha)
{
alpha *= (maskColor.a);
}
else
{
alpha *= (1.0 - maskColor.a);
}
gl_FragColor = vec4(mainColor.rgb * alpha, alpha);
}

View file

@ -74,16 +74,6 @@ var ScenePlugin = new Class({
* @since 3.0.0
*/
this.manager = scene.sys.game.scene;
/**
* [description]
*
* @name Phaser.Scenes.ScenePlugin#_queue
* @type {array}
* @private
* @since 3.0.0
*/
this._queue = [];
},
/**
@ -125,7 +115,7 @@ var ScenePlugin = new Class({
else
{
this.manager.stop(this.key);
this.manager.start(key);
this.manager.start(key, data);
}
}
@ -172,7 +162,7 @@ var ScenePlugin = new Class({
}
else
{
this.manager.start(key);
this.manager.start(key, data);
}
}

View file

@ -3,7 +3,6 @@
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var Class = require('../utils/Class');
var EventEmitter = require('eventemitter3');
var Extend = require('../utils/object/Extend');
@ -11,7 +10,7 @@ var NOOP = require('../utils/NOOP');
/**
* @classdesc
* [description]
* Class containing all the shared state and behaviour of a sound object, independent of the implementation.
*
* @class BaseSound
* @extends EventEmitter
@ -22,15 +21,11 @@ var NOOP = require('../utils/NOOP');
*
* @param {Phaser.Sound.BaseSoundManager} manager - Reference to the current sound manager instance.
* @param {string} key - Asset key for the sound.
* @param {object} config - An optional config object containing default sound settings.
* @param {SoundConfig} [config] - An optional config object containing default sound settings.
*/
var BaseSound = new Class({
Extends: EventEmitter,
initialize:
function BaseSound (manager, key, config)
initialize: function BaseSound (manager, key, config)
{
EventEmitter.call(this);
@ -115,7 +110,8 @@ var BaseSound = new Class({
* Default values will be set by properties' setters.
*
* @name Phaser.Sound.BaseSound#config
* @type {object}
* @type {SoundConfig}
* @private
* @since 3.0.0
*/
this.config = {
@ -130,7 +126,7 @@ var BaseSound = new Class({
* It could be default config or marker config.
*
* @name Phaser.Sound.BaseSound#currentConfig
* @type {object}
* @type {SoundConfig}
* @private
* @since 3.0.0
*/
@ -204,18 +200,10 @@ var BaseSound = new Class({
* @since 3.0.0
*/
this.loop = false;
/**
* [description]
*
* @name Phaser.Sound.BaseSound#config
* @type {object}
* @since 3.0.0
*/
this.config = Extend(this.config, config);
/**
* Object containing markers definitions (Object.<string, ISoundMarker>)
* Object containing markers definitions (Object.<string, SoundMarker>).
*
* @name Phaser.Sound.BaseSound#markers
* @type {object}
@ -230,7 +218,7 @@ var BaseSound = new Class({
* 'null' if whole sound is playing.
*
* @name Phaser.Sound.BaseSound#currentMarker
* @type {?ISoundMarker}
* @type {SoundMarker}
* @default null
* @readOnly
* @since 3.0.0
@ -256,34 +244,26 @@ var BaseSound = new Class({
* @method Phaser.Sound.BaseSound#addMarker
* @since 3.0.0
*
* @param {ISoundMarker} marker - Marker object
* @param {SoundMarker} marker - Marker object.
*
* @return {boolean} Whether the marker was added successfully
* @return {boolean} Whether the marker was added successfully.
*/
addMarker: function (marker)
{
if (!marker)
if (!marker || !marker.name || typeof marker.name !== 'string')
{
console.error('addMarker - Marker object has to be provided!');
return false;
}
if (!marker.name || typeof marker.name !== 'string')
{
console.error('addMarker - Marker has to have a valid name!');
return false;
}
if (this.markers[marker.name])
{
// eslint-disable-next-line no-console
console.error('addMarker - Marker with name \'' + marker.name + '\' already exists for sound \'' + this.key + '\'!');
return false;
}
marker = Extend(true, {
name: '',
start: 0,
duration: this.totalDuration,
duration: this.totalDuration - (marker.start || 0),
config: {
mute: false,
volume: 1,
@ -294,9 +274,7 @@ var BaseSound = new Class({
delay: 0
}
}, marker);
this.markers[marker.name] = marker;
return true;
},
@ -306,32 +284,23 @@ var BaseSound = new Class({
* @method Phaser.Sound.BaseSound#updateMarker
* @since 3.0.0
*
* @param {ISoundMarker} marker - Marker object with updated values.
* @param {SoundMarker} marker - Marker object with updated values.
*
* @return {boolean} Whether the marker was updated successfully.
*/
updateMarker: function (marker)
{
if (!marker)
if (!marker || !marker.name || typeof marker.name !== 'string')
{
console.error('updateMarker - Marker object has to be provided!');
return false;
}
if (!marker.name || typeof marker.name !== 'string')
{
console.error('updateMarker - Marker has to have a valid name!');
return false;
}
if (!this.markers[marker.name])
{
// eslint-disable-next-line no-console
console.error('updateMarker - Marker with name \'' + marker.name + '\' does not exist for sound \'' + this.key + '\'!');
return false;
}
this.markers[marker.name] = Extend(true, this.markers[marker.name], marker);
return true;
},
@ -343,20 +312,16 @@ var BaseSound = new Class({
*
* @param {string} markerName - The name of the marker to remove.
*
* @return {ISoundMarker|null} Removed marker object or 'null' if there was no marker with provided name.
* @return {SoundMarker|null} Removed marker object or 'null' if there was no marker with provided name.
*/
removeMarker: function (markerName)
{
var marker = this.markers[markerName];
if (!marker)
{
console.error('removeMarker - Marker with name \'' + marker.name + '\' does not exist for sound \'' + this.key + '\'!');
return null;
}
this.markers[markerName] = null;
return marker;
},
@ -369,26 +334,24 @@ var BaseSound = new Class({
* @since 3.0.0
*
* @param {string} [markerName=''] - If you want to play a marker then provide the marker name here, otherwise omit it to play the full sound.
* @param {ISoundConfig} [config] - Optional sound config object to be applied to this marker or entire sound if no marker name is provided. It gets memorized for future plays of current section of the sound.
* @param {SoundConfig} [config] - Optional sound config object to be applied to this marker or entire sound if no marker name is provided. It gets memorized for future plays of current section of the sound.
*
* @return {boolean} Whether the sound started playing successfully.
*/
play: function (markerName, config)
{
if (markerName === void 0) { markerName = ''; }
if (typeof markerName === 'object')
{
config = markerName;
markerName = '';
}
if (typeof markerName !== 'string')
{
// eslint-disable-next-line no-console
console.error('Sound marker name has to be a string!');
return false;
}
if (!markerName)
{
this.currentMarker = null;
@ -399,20 +362,18 @@ var BaseSound = new Class({
{
if (!this.markers[markerName])
{
// eslint-disable-next-line no-console
console.error('No marker with name \'' + markerName + '\' found for sound \'' + this.key + '\'!');
return false;
}
this.currentMarker = this.markers[markerName];
this.currentConfig = this.currentMarker.config;
this.duration = this.currentMarker.duration;
}
this.resetConfig();
this.currentConfig = Extend(this.currentConfig, config);
this.isPlaying = true;
this.isPaused = false;
return true;
},
@ -421,7 +382,7 @@ var BaseSound = new Class({
*
* @method Phaser.Sound.BaseSound#pause
* @since 3.0.0
*
*
* @return {boolean} Whether the sound was paused successfully.
*/
pause: function ()
@ -430,10 +391,8 @@ var BaseSound = new Class({
{
return false;
}
this.isPlaying = false;
this.isPaused = true;
return true;
},
@ -442,7 +401,7 @@ var BaseSound = new Class({
*
* @method Phaser.Sound.BaseSound#resume
* @since 3.0.0
*
*
* @return {boolean} Whether the sound was resumed successfully.
*/
resume: function ()
@ -451,10 +410,8 @@ var BaseSound = new Class({
{
return false;
}
this.isPlaying = true;
this.isPaused = false;
return true;
},
@ -463,7 +420,7 @@ var BaseSound = new Class({
*
* @method Phaser.Sound.BaseSound#stop
* @since 3.0.0
*
*
* @return {boolean} Whether the sound was stopped successfully.
*/
stop: function ()
@ -514,7 +471,7 @@ var BaseSound = new Class({
* @override
* @protected
* @since 3.0.0
*
*
* @param {number} time - The current timestamp as generated by the Request Animation Frame or SetTimeout.
* @param {number} delta - The delta time elapsed since the last frame.
*/
@ -532,7 +489,6 @@ var BaseSound = new Class({
{
return;
}
this.pendingRemove = true;
this.manager = null;
this.key = '';
@ -557,25 +513,14 @@ var BaseSound = new Class({
var cent = 1.0005777895065548; // Math.pow(2, 1/1200);
var totalDetune = this.currentConfig.detune + this.manager.detune;
var detuneRate = Math.pow(cent, totalDetune);
this.totalRate = this.currentConfig.rate * this.manager.rate * detuneRate;
}
});
/**
* Playback rate.
*
* @name Phaser.Sound.BaseSound#rate
* @type {number}
* @since 3.0.0
*/
Object.defineProperty(BaseSound.prototype, 'rate', {
get: function ()
{
return this.currentConfig.rate;
},
set: function (value)
{
this.currentConfig.rate = value;
@ -589,21 +534,11 @@ Object.defineProperty(BaseSound.prototype, 'rate', {
this.emit('rate', this, value);
}
});
/**
* Detuning of sound.
*
* @name Phaser.Sound.BaseSound#detune
* @property {number} detune
* @since 3.0.0
*/
Object.defineProperty(BaseSound.prototype, 'detune', {
get: function ()
{
return this.currentConfig.detune;
},
set: function (value)
{
this.currentConfig.detune = value;
@ -617,5 +552,4 @@ Object.defineProperty(BaseSound.prototype, 'detune', {
this.emit('detune', this, value);
}
});
module.exports = BaseSound;

View file

@ -3,7 +3,6 @@
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var Class = require('../utils/Class');
var EventEmitter = require('eventemitter3');
var NOOP = require('../utils/NOOP');
@ -25,12 +24,8 @@ var NOOP = require('../utils/NOOP');
* @param {Phaser.Game} game - Reference to the current game instance.
*/
var BaseSoundManager = new Class({
Extends: EventEmitter,
initialize:
function BaseSoundManager (game)
initialize: function BaseSoundManager (game)
{
EventEmitter.call(this);
@ -48,7 +43,7 @@ var BaseSoundManager = new Class({
* An array containing all added sounds.
*
* @name Phaser.Sound.BaseSoundManager#sounds
* @type {array}
* @type {Phaser.Sound.BaseSound[]}
* @default []
* @private
* @since 3.0.0
@ -75,29 +70,6 @@ var BaseSoundManager = new Class({
*/
this.volume = 1;
/**
* Global playback rate at which all the sounds will be played.
* Value of 1.0 plays the audio at full speed, 0.5 plays the audio at half speed
* and 2.0 doubles the audio's playback speed.
*
* @name Phaser.Sound.BaseSoundManager#rate
* @type {number}
* @default 1
* @since 3.0.0
*/
this.rate = 1;
/**
* Global detuning of all sounds in [cents](https://en.wikipedia.org/wiki/Cent_%28music%29).
* The range of the value is -1200 to 1200, but we recommend setting it to [50](https://en.wikipedia.org/wiki/50_Cent).
*
* @name Phaser.Sound.BaseSoundManager#detune
* @type {number}
* @default 0
* @since 3.0.0
*/
this.detune = 0;
/**
* Flag indicating if sounds should be paused when game looses focus,
* for instance when user switches to another tab/program/app.
@ -156,6 +128,7 @@ var BaseSoundManager = new Class({
*
* @name Phaser.Sound.BaseSoundManager#locked
* @type {boolean}
* @readOnly
* @since 3.0.0
*/
this.locked = this.locked || false;
@ -167,6 +140,7 @@ var BaseSoundManager = new Class({
* @name Phaser.Sound.BaseSoundManager#unlocked
* @type {boolean}
* @default false
* @private
* @since 3.0.0
*/
this.unlocked = false;
@ -183,45 +157,43 @@ var BaseSoundManager = new Class({
* @method Phaser.Sound.BaseSoundManager#add
* @override
* @since 3.0.0
*
*
* @param {string} key - Asset key for the sound.
* @param {ISoundConfig} [config] - An optional config object containing default sound settings.
*
* @return {ISound} The new sound instance.
* @param {SoundConfig} [config] - An optional config object containing default sound settings.
*
* @return {Phaser.Sound.BaseSound} The new sound instance.
*/
add: NOOP,
/**
* Audio sprite sound type.
*
* @typedef {Phaser.Sound.BaseSound} AudioSpriteSound
*
* @property {object} spritemap - Local reference to 'spritemap' object form json file generated by audiosprite tool.
*/
/**
* Adds a new audio sprite sound into the sound manager.
*
* @method Phaser.Sound.BaseSoundManager#addAudioSprite
* @since 3.0.0
*
*
* @param {string} key - Asset key for the sound.
* @param {ISoundConfig} [config] - An optional config object containing default sound settings.
*
* @return {IAudioSpriteSound} The new audio sprite sound instance.
* @param {SoundConfig} [config] - An optional config object containing default sound settings.
*
* @return {AudioSpriteSound} The new audio sprite sound instance.
*/
addAudioSprite: function (key, config)
{
var sound = this.add(key, config);
/**
* Local reference to 'spritemap' object form json file generated by audiosprite tool.
*
* @property {object} spritemap
*/
sound.spritemap = this.game.cache.json.get(key).spritemap;
for (var markerName in sound.spritemap)
{
if (!sound.spritemap.hasOwnProperty(markerName))
{
continue;
}
var marker = sound.spritemap[markerName];
sound.addMarker({
name: markerName,
start: marker.start,
@ -229,7 +201,6 @@ var BaseSoundManager = new Class({
config: config
});
}
return sound;
},
@ -239,18 +210,16 @@ var BaseSoundManager = new Class({
*
* @method Phaser.Sound.BaseSoundManager#play
* @since 3.0.0
*
*
* @param {string} key - Asset key for the sound.
* @param {ISoundConfig | ISoundMarker} [extra] - An optional additional object containing settings to be applied to the sound. It could be either config or marker object.
*
* @param {SoundConfig|SoundMarker} [extra] - An optional additional object containing settings to be applied to the sound. It could be either config or marker object.
*
* @return {boolean} Whether the sound started playing successfully.
*/
play: function (key, extra)
{
var sound = this.add(key);
sound.once('ended', sound.destroy, sound);
if (extra)
{
if (extra.name)
@ -275,19 +244,17 @@ var BaseSoundManager = new Class({
*
* @method Phaser.Sound.BaseSoundManager#playAudioSprite
* @since 3.0.0
*
*
* @param {string} key - Asset key for the sound.
* @param {string} spriteName - The name of the sound sprite to play.
* @param {ISoundConfig} [config] - An optional config object containing default sound settings.
*
* @param {SoundConfig} [config] - An optional config object containing default sound settings.
*
* @return {boolean} Whether the audio sprite sound started playing successfully.
*/
playAudioSprite: function (key, spriteName, config)
{
var sound = this.addAudioSprite(key);
sound.once('ended', sound.destroy, sound);
return sound.play(spriteName, config);
},
@ -297,9 +264,9 @@ var BaseSoundManager = new Class({
*
* @method Phaser.Sound.BaseSoundManager#remove
* @since 3.0.0
*
* @param {ISound} sound - The sound object to remove.
*
*
* @param {Phaser.Sound.BaseSound} sound - The sound object to remove.
*
* @return {boolean} True if the sound was removed successfully, otherwise false.
*/
remove: function (sound)
@ -320,9 +287,9 @@ var BaseSoundManager = new Class({
*
* @method Phaser.Sound.BaseSoundManager#removeByKey
* @since 3.0.0
*
*
* @param {string} key - The key to match when removing sound objects.
*
*
* @return {number} The number of matching sound objects that were removed.
*/
removeByKey: function (key)
@ -443,7 +410,7 @@ var BaseSoundManager = new Class({
* @method Phaser.Sound.BaseSoundManager#update
* @protected
* @since 3.0.0
*
*
* @param {number} time - The current timestamp as generated by the Request Animation Frame or SetTimeout.
* @param {number} delta - The delta time elapsed since the last frame.
*/
@ -460,7 +427,6 @@ var BaseSoundManager = new Class({
*/
this.emit('unlocked', this);
}
for (var i = this.sounds.length - 1; i >= 0; i--)
{
if (this.sounds[i].pendingRemove)
@ -468,7 +434,6 @@ var BaseSoundManager = new Class({
this.sounds.splice(i, 1);
}
}
this.sounds.forEach(function (sound)
{
sound.update(time, delta);
@ -484,12 +449,10 @@ var BaseSoundManager = new Class({
destroy: function ()
{
this.removeAllListeners();
this.forEachActiveSound(function (sound)
{
sound.destroy();
});
this.sounds.length = 0;
this.sounds = null;
this.game = null;
@ -501,14 +464,13 @@ var BaseSoundManager = new Class({
* @method Phaser.Sound.BaseSoundManager#forEachActiveSound
* @private
* @since 3.0.0
*
*
* @param {function} callbackfn - Callback function. (sound: ISound, index: number, array: ISound[]) => void
* @param [scope] - Callback context.
* @param {object} [scope] - Callback context.
*/
forEachActiveSound: function (callbackfn, scope)
{
var _this = this;
this.sounds.forEach(function (sound, index)
{
if (!sound.pendingRemove)
@ -516,70 +478,77 @@ var BaseSoundManager = new Class({
callbackfn.call(scope || _this, sound, index, _this.sounds);
}
});
}
});
/**
* Global playback rate.
*
* @name Phaser.Sound.BaseSoundManager#rate
* @type {number}
* @since 3.0.0
*/
Object.defineProperty(BaseSoundManager.prototype, 'rate', {
get: function ()
{
return this._rate;
},
set: function (value)
{
this._rate = value;
this.forEachActiveSound(function (sound)
/**
* Global playback rate at which all the sounds will be played.
* Value of 1.0 plays the audio at full speed, 0.5 plays the audio at half speed
* and 2.0 doubles the audio's playback speed.
*
* @name Phaser.Sound.BaseSoundManager#rate
* @type {number}
* @default 1
* @since 3.0.0
*/
rate: {
get: function ()
{
sound.setRate();
});
return this._rate;
},
/**
* @event Phaser.Sound.BaseSoundManager#rate
* @param {Phaser.Sound.BaseSoundManager} soundManager - Reference to the sound manager that emitted event.
* @param {number} value - An updated value of Phaser.Sound.BaseSoundManager#rate property.
*/
this.emit('rate', this, value);
}
set: function (value)
{
this._rate = value;
});
this.forEachActiveSound(function (sound)
{
sound.setRate();
});
/**
* Global detune.
*
* @name Phaser.Sound.BaseSoundManager#detune
* @type {number}
* @since 3.0.0
*/
Object.defineProperty(BaseSoundManager.prototype, 'detune', {
/**
* @event Phaser.Sound.BaseSoundManager#rate
* @param {Phaser.Sound.BaseSoundManager} soundManager - Reference to the sound manager that emitted event.
* @param {number} value - An updated value of Phaser.Sound.BaseSoundManager#rate property.
*/
this.emit('rate', this, value);
}
get: function ()
{
return this._detune;
},
set: function (value)
{
this._detune = value;
this.forEachActiveSound(function (sound)
{
sound.setRate();
});
/**
* Global detuning of all sounds in [cents](https://en.wikipedia.org/wiki/Cent_%28music%29).
* The range of the value is -1200 to 1200, but we recommend setting it to [50](https://en.wikipedia.org/wiki/50_Cent).
*
* @name Phaser.Sound.BaseSoundManager#detune
* @type {number}
* @default 0
* @since 3.0.0
*/
detune: {
get: function ()
{
return this._detune;
},
set: function (value)
{
this._detune = value;
this.forEachActiveSound(function (sound)
{
sound.setRate();
});
/**
* @event Phaser.Sound.BaseSoundManager#detune
* @param {Phaser.Sound.BaseSoundManager} soundManager - Reference to the sound manager that emitted event.
* @param {number} value - An updated value of Phaser.Sound.BaseSoundManager#detune property.
*/
this.emit('detune', this, value);
}
/**
* @event Phaser.Sound.BaseSoundManager#detune
* @param {Phaser.Sound.BaseSoundManager} soundManager - Reference to the sound manager that emitted event.
* @param {number} value - An updated value of Phaser.Sound.BaseSoundManager#detune property.
*/
this.emit('detune', this, value);
}
});

View file

@ -12,6 +12,7 @@ var WebAudioSoundManager = require('./webaudio/WebAudioSoundManager');
* Creates a Web Audio, HTML5 Audio or No Audio Sound Manager based on config and device settings.
*
* @function Phaser.Sound.SoundManagerCreator
* @author Pavle Goloskokovic <pgoloskokovic@gmail.com> (http://prunegames.com)
* @since 3.0.0
*
* @param {Phaser.Game} game - Reference to the current game instance.

View file

@ -3,7 +3,6 @@
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var Class = require('../../utils/Class');
var BaseSound = require('../BaseSound');
@ -17,18 +16,14 @@ var BaseSound = require('../BaseSound');
* @constructor
* @author Pavle Goloskokovic <pgoloskokovic@gmail.com> (http://prunegames.com)
* @since 3.0.0
*
*
* @param {Phaser.Sound.HTML5AudioSoundManager} manager - Reference to the current sound manager instance.
* @param {string} key - Asset key for the sound.
* @param {ISoundConfig} [config={}] - An optional config object containing default sound settings.
* @param {SoundConfig} [config={}] - An optional config object containing default sound settings.
*/
var HTML5AudioSound = new Class({
Extends: BaseSound,
initialize:
function HTML5AudioSound (manager, key, config)
initialize: function HTML5AudioSound (manager, key, config)
{
if (config === void 0) { config = {}; }
@ -43,9 +38,9 @@ var HTML5AudioSound = new Class({
* @since 3.0.0
*/
this.tags = manager.game.cache.audio.get(key);
if (!this.tags)
{
// eslint-disable-next-line no-console
console.error('No audio loaded in cache with key: \'' + key + '\'!');
return;
}
@ -85,11 +80,8 @@ var HTML5AudioSound = new Class({
* @since 3.0.0
*/
this.previousTime = 0;
this.duration = this.tags[0].duration;
this.totalDuration = this.tags[0].duration;
BaseSound.call(this, manager, key, config);
},
@ -100,10 +92,10 @@ var HTML5AudioSound = new Class({
*
* @method Phaser.Sound.HTML5AudioSound#play
* @since 3.0.0
*
*
* @param {string} [markerName=''] - If you want to play a marker then provide the marker name here, otherwise omit it to play the full sound.
* @param {ISoundConfig} [config] - Optional sound config object to be applied to this marker or entire sound if no marker name is provided. It gets memorized for future plays of current section of the sound.
*
* @param {SoundConfig} [config] - Optional sound config object to be applied to this marker or entire sound if no marker name is provided. It gets memorized for future plays of current section of the sound.
*
* @return {boolean} Whether the sound started playing successfully.
*/
play: function (markerName, config)
@ -112,7 +104,6 @@ var HTML5AudioSound = new Class({
{
return false;
}
if (!BaseSound.prototype.play.call(this, markerName, config))
{
return false;
@ -129,7 +120,6 @@ var HTML5AudioSound = new Class({
* @param {Phaser.Sound.HTML5AudioSound} sound - Reference to the sound that emitted event.
*/
this.emit('play', this);
return true;
},
@ -138,7 +128,7 @@ var HTML5AudioSound = new Class({
*
* @method Phaser.Sound.HTML5AudioSound#pause
* @since 3.0.0
*
*
* @return {boolean} Whether the sound was paused successfully.
*/
pause: function ()
@ -147,12 +137,10 @@ var HTML5AudioSound = new Class({
{
return false;
}
if (this.startTime > 0)
{
return false;
}
if (!BaseSound.prototype.pause.call(this))
{
return false;
@ -168,7 +156,6 @@ var HTML5AudioSound = new Class({
* @param {Phaser.Sound.HTML5AudioSound} sound - Reference to the sound that emitted event.
*/
this.emit('pause', this);
return true;
},
@ -177,7 +164,7 @@ var HTML5AudioSound = new Class({
*
* @method Phaser.Sound.HTML5AudioSound#resume
* @since 3.0.0
*
*
* @return {boolean} Whether the sound was resumed successfully.
*/
resume: function ()
@ -186,12 +173,10 @@ var HTML5AudioSound = new Class({
{
return false;
}
if (this.startTime > 0)
{
return false;
}
if (!BaseSound.prototype.resume.call(this))
{
return false;
@ -208,7 +193,6 @@ var HTML5AudioSound = new Class({
* @param {Phaser.Sound.HTML5AudioSound} sound - Reference to the sound that emitted event.
*/
this.emit('resume', this);
return true;
},
@ -217,7 +201,7 @@ var HTML5AudioSound = new Class({
*
* @method Phaser.Sound.HTML5AudioSound#stop
* @since 3.0.0
*
*
* @return {boolean} Whether the sound was stopped successfully.
*/
stop: function ()
@ -226,7 +210,6 @@ var HTML5AudioSound = new Class({
{
return false;
}
if (!BaseSound.prototype.stop.call(this))
{
return false;
@ -240,7 +223,6 @@ var HTML5AudioSound = new Class({
* @param {Phaser.Sound.HTML5AudioSound} sound - Reference to the sound that emitted event.
*/
this.emit('stop', this);
return true;
},
@ -250,7 +232,7 @@ var HTML5AudioSound = new Class({
* @method Phaser.Sound.HTML5AudioSound#pickAndPlayAudioTag
* @private
* @since 3.0.0
*
*
* @return {boolean} Whether the sound was assigned an audio tag successfully.
*/
pickAndPlayAudioTag: function ()
@ -260,18 +242,15 @@ var HTML5AudioSound = new Class({
this.reset();
return false;
}
var seek = this.currentConfig.seek;
var delay = this.currentConfig.delay;
var offset = (this.currentMarker ? this.currentMarker.start : 0) + seek;
this.previousTime = offset;
this.audio.currentTime = offset;
this.applyConfig();
if (delay === 0)
{
this.startTime = 0;
if (this.audio.paused)
{
this.playCatchPromise();
@ -280,15 +259,12 @@ var HTML5AudioSound = new Class({
else
{
this.startTime = window.performance.now() + delay * 1000;
if (!this.audio.paused)
{
this.audio.pause();
}
}
this.resetConfig();
return true;
},
@ -302,7 +278,7 @@ var HTML5AudioSound = new Class({
* @method Phaser.Sound.HTML5AudioSound#pickAudioTag
* @private
* @since 3.0.0
*
*
* @return {boolean} Whether the sound was assigned an audio tag successfully.
*/
pickAudioTag: function ()
@ -314,7 +290,6 @@ var HTML5AudioSound = new Class({
for (var i = 0; i < this.tags.length; i++)
{
var audio = this.tags[i];
if (audio.dataset.used === 'false')
{
audio.dataset.used = 'true';
@ -322,14 +297,11 @@ var HTML5AudioSound = new Class({
return true;
}
}
if (!this.manager.override)
{
return false;
}
var otherSounds = [];
this.manager.forEachActiveSound(function (sound)
{
if (sound.key === this.key && sound.audio)
@ -337,7 +309,6 @@ var HTML5AudioSound = new Class({
otherSounds.push(sound);
}
}, this);
otherSounds.sort(function (a1, a2)
{
if (a1.loop === a2.loop)
@ -347,15 +318,12 @@ var HTML5AudioSound = new Class({
}
return a1.loop ? 1 : -1;
});
var selectedSound = otherSounds[0];
this.audio = selectedSound.audio;
selectedSound.reset();
selectedSound.audio = null;
selectedSound.startTime = 0;
selectedSound.previousTime = 0;
return true;
},
@ -370,9 +338,9 @@ var HTML5AudioSound = new Class({
playCatchPromise: function ()
{
var playPromise = this.audio.play();
if (playPromise)
{
// eslint-disable-next-line no-unused-vars
playPromise.catch(function (reason) { });
}
},
@ -445,10 +413,11 @@ var HTML5AudioSound = new Class({
* @method Phaser.Sound.HTML5AudioSound#update
* @protected
* @since 3.0.0
*
*
* @param {number} time - The current timestamp as generated by the Request Animation Frame or SetTimeout.
* @param {number} delta - The delta time elapsed since the last frame.
*/
// eslint-disable-next-line no-unused-vars
update: function (time, delta)
{
if (!this.isPlaying)
@ -572,20 +541,11 @@ var HTML5AudioSound = new Class({
}
}
});
/**
* Mute setting.
*
* @name Phaser.Sound.HTML5AudioSound#mute
* @type {boolean}
*/
Object.defineProperty(HTML5AudioSound.prototype, 'mute', {
get: function ()
{
return this.currentConfig.mute;
},
set: function (value)
{
this.currentConfig.mute = value;
@ -602,22 +562,12 @@ Object.defineProperty(HTML5AudioSound.prototype, 'mute', {
*/
this.emit('mute', this, value);
}
});
/**
* Volume setting.
*
* @name Phaser.Sound.HTML5AudioSound#volume
* @type {number}
*/
Object.defineProperty(HTML5AudioSound.prototype, 'volume', {
get: function ()
{
return this.currentConfig.volume;
},
set: function (value)
{
this.currentConfig.volume = value;
@ -634,22 +584,12 @@ Object.defineProperty(HTML5AudioSound.prototype, 'volume', {
*/
this.emit('volume', this, value);
}
});
/**
* Playback rate.
*
* @name Phaser.Sound.HTML5AudioSound#rate
* @type {number}
*/
Object.defineProperty(HTML5AudioSound.prototype, 'rate', {
get: function ()
{
return Object.getOwnPropertyDescriptor(BaseSound.prototype, 'rate').get.call(this);
},
set: function (value)
{
this.currentConfig.rate = value;
@ -659,22 +599,12 @@ Object.defineProperty(HTML5AudioSound.prototype, 'rate', {
}
Object.getOwnPropertyDescriptor(BaseSound.prototype, 'rate').set.call(this, value);
}
});
/**
* Detuning of sound.
*
* @name Phaser.Sound.HTML5AudioSound#detune
* @type {number}
*/
Object.defineProperty(HTML5AudioSound.prototype, 'detune', {
get: function ()
{
return Object.getOwnPropertyDescriptor(BaseSound.prototype, 'detune').get.call(this);
},
set: function (value)
{
this.currentConfig.detune = value;
@ -684,17 +614,8 @@ Object.defineProperty(HTML5AudioSound.prototype, 'detune', {
}
Object.getOwnPropertyDescriptor(BaseSound.prototype, 'detune').set.call(this, value);
}
});
/**
* Current position of playing sound.
*
* @name Phaser.Sound.HTML5AudioSound#seek
* @type {number}
*/
Object.defineProperty(HTML5AudioSound.prototype, 'seek', {
get: function ()
{
if (this.isPlaying)
@ -711,7 +632,6 @@ Object.defineProperty(HTML5AudioSound.prototype, 'seek', {
return 0;
}
},
set: function (value)
{
if (this.manager.isLocked(this, 'seek', value))
@ -744,21 +664,11 @@ Object.defineProperty(HTML5AudioSound.prototype, 'seek', {
}
}
});
/**
* Property indicating whether or not
* the sound or current sound marker will loop.
*
* @name Phaser.Sound.HTML5AudioSound#loop
* @type {boolean}
*/
Object.defineProperty(HTML5AudioSound.prototype, 'loop', {
get: function ()
{
return this.currentConfig.loop;
},
set: function (value)
{
this.currentConfig.loop = value;
@ -778,7 +688,5 @@ Object.defineProperty(HTML5AudioSound.prototype, 'loop', {
*/
this.emit('loop', this, value);
}
});
module.exports = HTML5AudioSound;

Some files were not shown because too many files have changed in this diff Show more