Skip to content

Commit d586483

Browse files
committed
Merge branch 'master' of https://github.com/photonstorm/phaser
2 parents cdd75f8 + 0a4fc5b commit d586483

22 files changed

Lines changed: 203 additions & 147 deletions

File tree

CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ You can find the source for Camera 3D in the new `plugins/camera3d` folder, alon
197197
* In Matter.js if you scaled a Body it would only scale correctly once, due to the way Matter handles scaling internally. We now automatically reset the Matter scale before applying the new value, which allows you to keep the Phaser and Matter object scales in sync. Fix #3785 #3951 (thanks @bergben)
198198
* The default Container Blend Mode is now `SKIP_TEST`. This allows you to either set a blend mode for a Container, in which case all children use that blend mode. Or, you can set a blend mode on the children and the children will render using their own blend modes, as the Container doesn't have one set. The WebGL and Canvas Renderer functions have also been updated to support this change. Fix #3684 (thanks @TadejZupancic)
199199
* Previously the Input Manager would create a Touch handler unless the Game Config had `input.touch` set to `false` (the default was true). If no such property is set, it no longer defaults to `true` and instead is set to whatever `Device.input.touch` returns. On non-touchscreen desktops this means it will now only create one single Pointer, rather than two.
200+
* The Arcade Physics Body `_tempMatrix` property has been removed. It was only used if the Body's Game Object had a parent. The matrix has been moved to the World instance instead, shared by all bodies.
201+
* Arcade Physics World has gained two new private properties `_tempMatrix` and `_tempMatrix2`. These are used by all bodies in the simulation that need a temporal matrix for calculations, rather than having their own instances.
202+
* The Input Manager has gained a new private property `_tempMatrix2`. This is used internally in the hitTest checks to avoid constant matrix creation.
203+
* The Transform Matrix has a new method `applyInverse` which will take an x/y position and inverse translate it through the current matrix.
204+
* Using `keyboard.addKeys("W, A, S, D")` would fail because of the spacing between the characters. `addKeys` will now trim the input allowing you to space characters out if you prefer (thanks @dhruvyad)
205+
* Calling `setTimeScale` on the Sprite's Animation component will now set the time scale value and keep it set until you change it again. Previously it would be reset to 1 when a new animation was loaded into the component, but this no longer happens - once the time scale is set it remains in effect, regardless of which animations are played on the Sprite.
200206

201207
### Game Config Resolution Specific Bug Fixes
202208

@@ -239,12 +245,16 @@ Setting the `resolution` property in the Game Config to a value other than 1 wou
239245
* A Game Object couldn't have a blend mode of `SKIP_TEST` set by using the getter or the `setBlendMode` method.
240246
* In Arcade Physics the `World.disable` call was passing the wrong argument, so never disabling the actual body (thanks @samme)
241247
* There was a visual bug with Rounded Rectangles in Canvas mode, due to the addition of the `overshoot` argument in the Graphics arc call. This has been fixed, so arcs will now render correctly and consistently in WebGL and Canvas and Rounded Rectangles are back to normal again too. Fix #3912 (thanks @valse)
248+
* The `InputManager.inputCandidate` method, which determines if a Game Object can be interacted with by a given Pointer and Camera combination, now takes the full camera status into consideration. This means if a Camera is set to ignore a Game Object you can now longer interact with it, or if the Camera is ignoring a Container with an interactive Game Object inside it, you cannot interact with the Container children any more. Previously they would interact regardless of the Camera state. Fix #3984 (thanks @NemoStein @samid737)
249+
* `Transform.getWorldTransformMatrix` has been recoded to iterate the transform parents correctly, applying the matrix multiplications as it goes. This (along with some changes in the Input Manager) fix the issue with Game Objects inside of Containers failing hit tests between certain angles. Fix #3920 (thanks @chaping @hackhat)
250+
* Calling Arcade Physics `collide` during an `update` method wouldn't inject the results back into the Body parent, causing the bodies to carry on moving. Using Colliders worked, but manually checking did not. Now, both methods work. Fix #3777 (thanks @samme)
251+
* The `setTintFill` method would ignore the `alpha` value of the Game Object in the shader. The alpha value is now blended with the tint fill, allowing you to properly alpha out tint-filled Game Objects. Fix #3992 (thanks @trl-bsd)
242252

243253
### Examples, Documentation and TypeScript
244254

245255
My thanks to the following for helping with the Phaser 3 Examples, Docs and TypeScript definitions, either by reporting errors, fixing them or helping author the docs:
246256

247-
@SBCGames @rgk @rook2pawn @robbintt @bguyl @halilcakarr @PhaserEditor2D @Edwin222 @tfelix @Yudikubota @hexus @guzmonne @ampled @thanh-taro @dcbriccetti @Dreaded-Gnu @padme-amidala @rootasjey @ampled @thejonanshow @polarstoat @jdjoshuadavison @alexeymolchan @samme @PBird @kid-wumeng
257+
@SBCGames @rgk @rook2pawn @robbintt @bguyl @halilcakarr @PhaserEditor2D @Edwin222 @tfelix @Yudikubota @hexus @guzmonne @ampled @thanh-taro @dcbriccetti @Dreaded-Gnu @padme-amidala @rootasjey @ampled @thejonanshow @polarstoat @jdjoshuadavison @alexeymolchan @samme @PBird @spontoreau @hypertrifle @kid-wumeng
248258

249259
Thanks to @khaleb85 for fixing the super-annoying lag on the API Docs pages when it hung the browser while indexing the search field.
250260

src/animations/Animation.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,6 @@ var Animation = new Class({
529529
component.msPerFrame = this.msPerFrame;
530530
component.skipMissedFrames = this.skipMissedFrames;
531531

532-
component._timeScale = 1;
533532
component._delay = this.delay;
534533
component._repeat = this.repeat;
535534
component._repeatDelay = this.repeatDelay;

src/boot/Config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ var ValueToColor = require('../display/color/ValueToColor');
8686
*
8787
* @property {boolean} [antialias=true] - [description]
8888
* @property {boolean} [pixelArt=false] - [description]
89-
* @property {boolean} [autoResize=false] - [description]
89+
* @property {boolean} [autoResize=true] - Automatically resize the Game Canvas if you resize the renderer.
9090
* @property {boolean} [roundPixels=false] - [description]
9191
* @property {boolean} [transparent=false] - [description]
9292
* @property {boolean} [clearBeforeRender=true] - [description]
@@ -451,9 +451,9 @@ var Config = new Class({
451451
var renderConfig = GetValue(config, 'render', config);
452452

453453
/**
454-
* @const {boolean} Phaser.Boot.Config#autoResize - [description]
454+
* @const {boolean} Phaser.Boot.Config#autoResize - Automatically resize the Game Canvas if you resize the renderer.
455455
*/
456-
this.autoResize = GetValue(renderConfig, 'autoResize', false);
456+
this.autoResize = GetValue(renderConfig, 'autoResize', true);
457457

458458
/**
459459
* @const {boolean} Phaser.Boot.Config#antialias - [description]

src/cameras/2d/Camera.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ var Camera = new Class({
261261
/**
262262
* Sets the Camera to render to a texture instead of to the main display.
263263
*
264+
* Make sure that you resize the camera first if you're going to use this feature.
265+
*
264266
* This is an experimental feature and should be expected to change in the future.
265267
*
266268
* @method Phaser.Cameras.Scene2D.Camera#setRenderToTexture

src/gameobjects/components/Animation.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ var Animation = new Class({
509509

510510
this.forward = true;
511511
this._reverse = false;
512+
512513
return this._startAnimation(key, startFrame);
513514
},
514515

@@ -537,6 +538,7 @@ var Animation = new Class({
537538

538539
this.forward = false;
539540
this._reverse = true;
541+
540542
return this._startAnimation(key, startFrame);
541543
},
542544

src/gameobjects/components/Transform.js

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -427,12 +427,14 @@ var Transform = {
427427
* @since 3.4.0
428428
*
429429
* @param {Phaser.GameObjects.Components.TransformMatrix} [tempMatrix] - The matrix to populate with the values from this Game Object.
430+
* @param {Phaser.GameObjects.Components.TransformMatrix} [parentMatrix] - A temporary matrix to hold parent values during the calculations.
430431
*
431432
* @return {Phaser.GameObjects.Components.TransformMatrix} The populated Transform Matrix.
432433
*/
433-
getWorldTransformMatrix: function (tempMatrix)
434+
getWorldTransformMatrix: function (tempMatrix, parentMatrix)
434435
{
435436
if (tempMatrix === undefined) { tempMatrix = new TransformMatrix(); }
437+
if (parentMatrix === undefined) { parentMatrix = new TransformMatrix(); }
436438

437439
var parent = this.parentContainer;
438440

@@ -441,31 +443,17 @@ var Transform = {
441443
return this.getLocalTransformMatrix(tempMatrix);
442444
}
443445

444-
var parents = [];
445-
446+
tempMatrix.applyITRS(this.x, this.y, this._rotation, this._scaleX, this._scaleY);
447+
446448
while (parent)
447449
{
448-
parents.unshift(parent);
449-
parent = parent.parentContainer;
450-
}
450+
parentMatrix.applyITRS(parent.x, parent.y, parent._rotation, parent._scaleX, parent._scaleY);
451451

452-
tempMatrix.loadIdentity();
452+
parentMatrix.multiply(tempMatrix, tempMatrix);
453453

454-
var length = parents.length;
455-
456-
for (var i = 0; i < length; ++i)
457-
{
458-
parent = parents[i];
459-
460-
tempMatrix.translate(parent.x, parent.y);
461-
tempMatrix.rotate(parent.rotation);
462-
tempMatrix.scale(parent.scaleX, parent.scaleY);
454+
parent = parent.parentContainer;
463455
}
464456

465-
tempMatrix.translate(this.x, this.y);
466-
tempMatrix.rotate(this._rotation);
467-
tempMatrix.scale(this._scaleX, this._scaleY);
468-
469457
return tempMatrix;
470458
}
471459

src/gameobjects/components/TransformMatrix.js

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
var Class = require('../../utils/Class');
8+
var Vector2 = require('../../math/Vector2');
89

910
/**
1011
* @classdesc
@@ -419,12 +420,12 @@ var TransformMatrix = new Class({
419420

420421
var destinationMatrix = (out === undefined) ? this : out;
421422

422-
destinationMatrix.a = sourceA * localA + sourceB * localC;
423-
destinationMatrix.b = sourceA * localB + sourceB * localD;
424-
destinationMatrix.c = sourceC * localA + sourceD * localC;
425-
destinationMatrix.d = sourceC * localB + sourceD * localD;
426-
destinationMatrix.e = sourceE * localA + sourceF * localC + localE;
427-
destinationMatrix.f = sourceE * localB + sourceF * localD + localF;
423+
destinationMatrix.a = (sourceA * localA) + (sourceB * localC);
424+
destinationMatrix.b = (sourceA * localB) + (sourceB * localD);
425+
destinationMatrix.c = (sourceC * localA) + (sourceD * localC);
426+
destinationMatrix.d = (sourceC * localB) + (sourceD * localD);
427+
destinationMatrix.e = (sourceE * localA) + (sourceF * localC) + localE;
428+
destinationMatrix.f = (sourceE * localB) + (sourceF * localD) + localF;
428429

429430
return destinationMatrix;
430431
},
@@ -802,6 +803,42 @@ var TransformMatrix = new Class({
802803
return this;
803804
},
804805

806+
/**
807+
* Takes the `x` and `y` values and returns a new position in the `output` vector that is the inverse of
808+
* the current matrix with its transformation applied.
809+
*
810+
* Can be used to translate points from world to local space.
811+
*
812+
* @method Phaser.GameObjects.Components.TransformMatrix#applyInverse
813+
* @since 3.12.0
814+
*
815+
* @param {number} x - The x position to translate.
816+
* @param {number} y - The y position to translate.
817+
* @param {Phaser.Math.Vector2} [output] - A Vector2, or point-like object, to store the results in.
818+
*
819+
* @return {Phaser.Math.Vector2} The coordinates, inverse-transformed through this matrix.
820+
*/
821+
applyInverse: function (x, y, output)
822+
{
823+
if (output === undefined) { output = new Vector2(); }
824+
825+
var matrix = this.matrix;
826+
827+
var a = matrix[0];
828+
var b = matrix[1];
829+
var c = matrix[2];
830+
var d = matrix[3];
831+
var tx = matrix[4];
832+
var ty = matrix[5];
833+
834+
var id = 1 / ((a * d) + (c * -b));
835+
836+
output.x = (d * id * x) + (-c * id * y) + (((ty * c) - (tx * d)) * id);
837+
output.y = (a * id * y) + (-b * id * x) + (((-ty * a) + (tx * b)) * id);
838+
839+
return output;
840+
},
841+
805842
/**
806843
* Returns the X component of this matrix multiplied by the given values.
807844
* This is the same as `x * a + y * c + e`.

src/gameobjects/container/Container.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ var Container = new Class({
438438

439439
/**
440440
* Returns the world transform matrix as used for Bounds checks.
441+
*
441442
* The returned matrix is temporal and shouldn't be stored.
442443
*
443444
* @method Phaser.GameObjects.Container#getBoundsTransformMatrix
@@ -447,7 +448,7 @@ var Container = new Class({
447448
*/
448449
getBoundsTransformMatrix: function ()
449450
{
450-
return this.getWorldTransformMatrix(this.tempTransformMatrix);
451+
return this.getWorldTransformMatrix(this.tempTransformMatrix, this.localTransform);
451452
},
452453

453454
/**

src/gameobjects/group/GroupFactory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var GameObjectFactory = require('../GameObjectFactory');
1515
* @method Phaser.GameObjects.GameObjectFactory#group
1616
* @since 3.0.0
1717
*
18-
* @param {(Phaser.GameObjects.GameObject[]|GroupConfig||GroupConfig[])} [children] - Game Objects to add to this Group; or the `config` argument.
18+
* @param {(Phaser.GameObjects.GameObject[]|GroupConfig|GroupConfig[])} [children] - Game Objects to add to this Group; or the `config` argument.
1919
* @param {GroupConfig} [config] - A Group Configuration object.
2020
*
2121
* @return {Phaser.GameObjects.Group} The Game Object that was created.

src/input/InputManager.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,16 @@ var InputManager = new Class({
336336
*/
337337
this._tempMatrix = new TransformMatrix();
338338

339+
/**
340+
* A re-cycled matrix used in hit test calculations.
341+
*
342+
* @name Phaser.Input.InputManager#_tempMatrix2
343+
* @type {Phaser.GameObjects.Components.TransformMatrix}
344+
* @private
345+
* @since 3.12.0
346+
*/
347+
this._tempMatrix2 = new TransformMatrix();
348+
339349
game.events.once('boot', this.boot, this);
340350
},
341351

@@ -1050,14 +1060,15 @@ var InputManager = new Class({
10501060
* @since 3.10.0
10511061
*
10521062
* @param {Phaser.GameObjects.GameObject} gameObject - The Game Object to test.
1063+
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera which is being tested against.
10531064
*
10541065
* @return {boolean} `true` if the Game Object should be considered for input, otherwise `false`.
10551066
*/
1056-
inputCandidate: function (gameObject)
1067+
inputCandidate: function (gameObject, camera)
10571068
{
10581069
var input = gameObject.input;
10591070

1060-
if (!input || !input.enabled || !gameObject.willRender())
1071+
if (!input || !input.enabled || !gameObject.willRender(camera))
10611072
{
10621073
return false;
10631074
}
@@ -1069,7 +1080,7 @@ var InputManager = new Class({
10691080
{
10701081
do
10711082
{
1072-
if (!parent.visible)
1083+
if (!parent.willRender(camera))
10731084
{
10741085
visible = false;
10751086
break;
@@ -1135,12 +1146,15 @@ var InputManager = new Class({
11351146
var point = { x: 0, y: 0 };
11361147

11371148
var matrix = this._tempMatrix;
1149+
var parentMatrix = this._tempMatrix2;
11381150

11391151
for (var i = 0; i < gameObjects.length; i++)
11401152
{
11411153
var gameObject = gameObjects[i];
11421154

1143-
if (!this.inputCandidate(gameObject))
1155+
// Checks if the Game Object can receive input (isn't being ignored by the camera, invisible, etc)
1156+
// and also checks all of its parents, if any
1157+
if (!this.inputCandidate(gameObject, camera))
11441158
{
11451159
continue;
11461160
}
@@ -1150,9 +1164,9 @@ var InputManager = new Class({
11501164

11511165
if (gameObject.parentContainer)
11521166
{
1153-
gameObject.getWorldTransformMatrix(matrix);
1167+
gameObject.getWorldTransformMatrix(matrix, parentMatrix);
11541168

1155-
TransformXY(px, py, matrix.tx, matrix.ty, matrix.rotation, matrix.scaleX, matrix.scaleY, point);
1169+
matrix.applyInverse(px, py, point);
11561170
}
11571171
else
11581172
{

0 commit comments

Comments
 (0)