Commit graph

197 commits

Author SHA1 Message Date
Mike Headley
fca0a625b0 Distance comparison opposite of intended. Fixing so it will save the smaller distance instead of the greater. 2016-06-21 22:20:27 -07:00
Richard Davey
2bd4f68ea0 Small tweaks to #2577 and TS defs. 2016-06-21 22:18:09 +01:00
Mike Headley
48616c8854 Replacing lost Group.getClosestTo documentation lines. 2016-06-20 14:26:30 -07:00
Mike Headley
2e91588f87 Refactored original getClosestTo and getFurthestFrom functions to include optional filter callback. Removed the getClosestToFilter and getFurthestFromFilter. 2016-06-20 14:07:12 -07:00
Mike Headley
ad0f31be8d Added Group.getClosestToFilter() and Group.getFurthestFromFilter() 2016-06-19 10:45:35 -07:00
photonstorm
697a2ae94e Fixed issue in Group.align where the cell wouldn't increase if rows was great than -1 2016-06-17 15:28:39 +01:00
photonstorm
4da3b15ae2 Renamed alignTo to alignIn, and added the new method alignTo, to allow for Sprite to Sprite alignment. Updated all of the Bounds and TS defs. 2016-06-16 17:01:51 +01:00
Richard Davey
853d770764 Group.align is a new method that allows you to layout all the children of the Group in a grid formation. You can specify the dimensions of the grid, including the width, height and cell size. You can also control where children are positioned within each grid cell. The grid width and height values can also be set to -1, making them fluid, so the grid expands until all children are aligned. Finally an optional child index argument can be set. This is a great way to quickly and comprehensively align Group children, and has lots of use cases. 2016-06-16 02:50:24 +01:00
Richard Davey
fc7a3934d2 Group.align working. 2016-06-16 02:28:49 +01:00
Richard Davey
32cf1f1a9c Group.createMultiple can now accept Arrays for both the key and frame arguments. This allows you to create multiple sprites using each key and/or frame in the arrays, which is a great and quick way to build diverse Groups. See the JSDocs for complete details and code examples. 2016-06-15 22:36:23 +01:00
Richard Davey
5415d9b603 Stage and Group postUpdate methods iterate the same way now. 2016-06-09 23:14:24 +01:00
photonstorm
a65f9c7e4b Group.onChildInputDown is a new Signal that you can listen to. It will be dispatched whenever any immediate child of the Group emits an onInputDown signal itself. This allows you to listen for a Signal from the Group, rather than every Sprite within it.
Group.onChildInputUp is a new Signal that you can listen to. It will be dispatched whenever any immediate child of the Group emits an `onInputUp` signal itself. This allows you to listen for a Signal from the Group, rather than every Sprite within it.

Group.onChildInputOver is a new Signal that you can listen to. It will be dispatched whenever any immediate child of the Group emits an `onInputOver` signal itself. This allows you to listen for a Signal from the Group, rather than every Sprite within it.

Group.onChildInputOut is a new Signal that you can listen to. It will be dispatched whenever any immediate child of the Group emits an `onInputOut` signal itself. This allows you to listen for a Signal from the Group, rather than every Sprite within it.
2016-06-09 16:19:11 +01:00
photonstorm
458a67251d Fixed input property check. 2016-06-09 15:09:20 +01:00
photonstorm
24f4abe760 Group.add has a new optional argument index which controls the index within the group to insert the child to. Where 0 is the bottom of the Group.
Group.addAt has been refactored to be a simple call to `Group.add`, removing lots of duplicate code in the process.

Group.create has a new optional argument `index` which controls the index within the group to insert the child to. Where 0 is the bottom of the Group. It also now makes proper use of `Group.add`, cutting down on more duplicate code.

Group.createMultiple now returns an Array containing references to all of the children that the method created.
2016-06-09 14:58:35 +01:00
photonstorm
e8e7e27184 The DisplayObject.renderOrderID used to run in reverse. I.e. in a display list with 10 sprites on it, the first sprite (at the bottom of the list, rendering behind all the others) would have a renderOrderID of 9, where-as the top-most sprite, rendering above all others, would have a renderOrderID of 0. While this didn't cause any side-effects internally, it's arguably illogical. So the process has been reversed, and renderOrderIDs are now accumulative, starting at zero each frame, and increasing as it iterates down the display list. So the higher the ID, the more "on-top" of the output the object is.
`InputHandler.validForInput` and `Pointer.processInteractiveObjects` have been updated to reflect the new `renderOrderID` sequence (see above).
2016-06-09 12:32:37 +01:00
Richard Davey
de3d749385 Farthest swapped for the more common Furthest. 2016-06-05 23:01:00 +01:00
photonstorm
9ae43757b9 Group.removeAll has a new argument destroyTexture which allows you to optionally destroy the BaseTexture of each child, as it is removed from the Group (thanks @stoneman1 #2487) 2016-06-03 13:11:03 +01:00
photonstorm
dfa8b9dedc Refactored Group.getClosestTo and Group.getFurthestFrom. 2016-06-02 15:11:23 +01:00
Gustav
5a1cb006ec beautified 2016-05-28 00:27:35 +02:00
Gustav
5b4b41c958 added functions for getting closest child and farthest child 2016-05-26 21:51:56 +02:00
photonstorm
62d135cf1f Small tidy-up. 2016-04-19 03:39:04 +01:00
photonstorm
ecbff44354 Group.getByName searches the Group for the first instance of a child with the name property matching the given argument. Should more than one child have the same name only the first instance is returned. 2016-04-05 23:59:05 +01:00
photonstorm
f40cfbe2ae 2015 - 2016. 2016-04-04 22:16:16 +01:00
Rafael Barbosa Lopes
dd51a1724e Ensure a parent container is a Group before removing from its hash. 2016-03-24 13:44:49 -03:00
photonstorm
46cc05a377 Groups now check for child.parent before calling removeFromHash (thanks @spayton #2323 #2338) 2016-02-18 12:29:01 +00:00
Richard Davey
30b563085b The z property assigned to children of a Group now starts from zero instead of 1, this is an internal change mostly but if you relied on the z property for some reason then please be aware of this (thanks pantoninho) 2016-02-09 11:31:46 +00:00
Richard Davey
2cd76b7617 Docs update (#2166) 2016-02-04 00:13:32 +00:00
Richard Davey
a0eb44ec09 Group.add and Group.addAt would forget to remove the child from the hash of its previous Group if it had a physics body enabled, causing unbounded hash increase (thanks @strawlion @McIntozh #2232) 2016-02-03 21:51:01 +00:00
Richard Davey
e6aa9f83c9 Typo fix. 2015-10-19 23:18:23 +01:00
photonstorm
8db23545da jsdoc updates. 2015-09-10 15:57:55 +01:00
photonstorm
8833a509eb jsdoc fix. 2015-09-02 16:16:52 +01:00
photonstorm
32b0c98f7a Group.resetChild is a new method that allows you to call both child.reset and/or child.loadTexture on the given child object. This is used internally by getFirstDead and similar, but is made public so you can use it as a group iteration callback. Note that the child must have public reset and loadTexture methods to be valid for the call.
Group.getFirstDead, Group.getFirstAlive and Group.getFirstExists all have new optional arguments: `createIfNull`, `x`, `y`, `key` and `frame`. If the method you call cannot find a matching child (i.e. getFirstDead cannot find any dead children) then the optional `createIfNull` allows you to instantly create a new child in the group using the position and texture arguments to do so. This allows you to always get a child back from the Group and remove the need to do null checks and Group inserts from your game code. The same arguments can also be used in a different way: if `createIfNull` is false AND you provide the extra arguments AND a child is found then it will be passed to the new `Group.resetChild` method. This allows you to retrieve a child from the Group and have it reset and instantly ready for use in your game without any extra code.
2015-08-28 12:23:48 +01:00
photonstorm
f15fe6706c All undefined argument checks were changed from if (typeof x === 'undefined') to if (x === undefined) removing the typeof check and saving some bytes across the codebase in the process. 2015-07-22 10:37:15 +01:00
Richard Davey
4dec046c40 Added pendingDestroy to Groups. 2015-07-12 11:33:30 +01:00
photonstorm
d3525950a2 Group.addMultiple if given a Group.children array as the first parameter would fail as the original group length was decreased out of line with the children being added. Group.addMultiple now checks if the children argument is a Phaser.Group instance, and if so it uses Group.moveAll instead on it (thanks @AnderbergE #1898)
Group.moveAll allows you to move all of the children of a Group into another Group.
2015-07-10 17:05:54 +01:00
Richard Davey
f65bca1026 All Signals now have the ability to carry extra custom arguments with them, which are passed on to the callback you define after any internal arguments. For example a Phaser.Key has an onDown signal. When dispatched onDown sends a reference to the Key as the first and only argument. But you can now set the callback like this: fireKey.onDown.add(shoot, this, 0, 'lazer', 64). So when the onDown signal is dispatched internally the callback (shoot in this case) will receive 3 arguments: the Key reference that is raised internally and the string 'lazer' and value 64, which were the custom arguments provided when setting-up the callback. 2015-07-09 21:15:00 +01:00
Richard Davey
92f2742a26 When reusing a Tween created with an array of properties the values would get exponentially added to the TweenData internal array each time the tween was re-run (thanks @SBCGames #1747) 2015-07-07 04:21:55 +01:00
photonstorm
1438248388 Group.add and Group.addAt will only create a Physics Body on the child if it doesn't already have one. This is a change from 2.3 where it would replace the physics body property with the new body, but this could lead to garbage build-up over time, so you should now properly destroy the body before changing it. 2015-05-29 00:59:23 +01:00
photonstorm
23f2a7ca66 Removed 'scale' from Group as it comes from PIXI anyway. 2015-05-12 13:03:27 +01:00
photonstorm
a7db0e2c70 Group.hash is an array (previously available as Group._hash, but protected) into which you can add any of its children via Group.addToHash and Group.removeFromHash. Only children of the Group can be added to and removed from the hash. The hash is used automatically by Arcade Physics in order to perform non z-index based destructive sorting. However if you don't use Arcade Physics, or it isn't a physics enabled Group, then you can use the hash to perform your own sorting and filtering of Group children without touching their z-index (and therefore display draw order).
Group.physicsSortDirection is a new property allowing you to set a custom sort direction for Arcade Physics Sprites within the Group hash. Previously Arcade Physics used one single sort direction (defined on `Phaser.Physics.Arcade.sortDirection`) but this change allows you to specifically control how each and every Group is sorted, so you can now combine tall and wide Groups with narrow and thin in a single system.
2015-04-13 16:30:02 +01:00
photonstorm
1486e166bd Added physicsType property. 2015-03-23 15:04:27 +00:00
photonstorm
8aec760cd5 First pass at spacial sorting in World.collide. 2015-02-25 05:39:02 +00:00
photonstorm
a69e53f901 Copyright date change. 2015-02-25 03:36:23 +00:00
photonstorm
88f10f7f89 Updated fixedToCamera docs to reflect non-nesting (#1596) 2015-02-18 22:58:48 +00:00
photonstorm
b0261e4a5f Group.cursorIndex is the index of the item the Group cursor points to. This replaces Group._cache[8]. 2015-02-18 22:54:19 +00:00
photonstorm
0e7820bde5 Group.forEach (and many other Group methods) now uses the children.length value directly instead of caching it, which both helps performance and stops the loop from breaking should you remove a Group child in the invoked callback. 2015-02-11 17:19:56 +00:00
photonstorm
3c2725addc Typo. 2015-01-18 12:24:00 +00:00
Paul
fe8c5021fa Fixes #1410
As pointed out, `newChild.parent` could be accessed after it was set to
undefined. This fix unifies the code from the various `destroy` methods so
the previou issue does not occur.
2014-12-05 19:34:17 -08:00
Richard Davey
81f356c235 Merge pull request #1386 from pnstickne/wip-docs-1130
Assorted documentation/consistency updates
2014-12-01 12:07:10 +00:00
Paul
d15037e283 Event-Signal object count optimization
There are a bunch of signals added for Sprites; more when input is
enabled. However, very few of these signals are ever actually used. While
the previous performance update related to Signals addressed the size of
each Signal object, this update is to reduce the number of Signal objects
as used by the Events type.

As a comparison the "Particle: Random Sprite" demo creates 3200+ Signals;
with this change there less than 70 signals created when running the same
demo. (Each Event creates at 8 signals by default, and there is an Event
for each of the 400 particles.) While this is an idealized scenario, a
huge amount (of albeit small) object reduction should be expected.

It does this by creating a signal proxy property getter and a signal
dispatch proxy. When the event property (eg. `onEvent`) is accessed a new
Signal object is created (and cached in `_onEvent`) as required. This
ensures that no user code has to perform an existance-check on the event
property first: it just continues to use the signal property as normal.

When the Phaser game code needs to dispatch the event it uses
`event.onEvent$dispath(..)` instead of `event.onEvent.dispatch(..)`. This
special auto-generated method automatically takes care of checking for if
the Signal has been created and only dispatches the event if this is the
case. (If the game code used the `onEvent` property itself the event
deferal approach would be defeated.)

This approach is designed to require minimal changes, not negatively
affect performance, and reduce the number of Signal objects and
corresponding Signal/Event resource usage.

The only known user-code change is that code can add to signal (eg.
onInput) events even when input is not enabled - this will allow some
previously invalid code run without throwing an exception.
2014-11-30 21:39:25 -08:00