Commit graph

186 commits

Author SHA1 Message Date
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
Paul
b66a32e3a1 Documentation - number refinement
Changed some {number} types to {integer} where such is trivially
verifiable.
2014-11-30 15:22:39 -08:00
Paul
fa95c53631 Documentation - Group
- Merged in group doc updates

- Added a DisplayObject stub type for better link-out across documentation
2014-11-30 15:13:55 -08:00
Paul
dab8772de0 Documentation - consistency updates
- Updated `readOnly` doclet to `readonly`

- `array` refined to `type[]`, where such information was immediately
determinable.

- Updated {Any}/{*} to {any}; {...*} is standard exception

- Udated {Object} to {object}
2014-11-30 04:03:35 -08:00
Paul
859e8f9f07 Group - fix extreme 'forEach' de-optimization
This de-optimization occurred between 2.0.7 and 2.1.0 and is currently
present through dev.

`Group.forEach`, which is used by QuadTree, had an extreme de-optimization
in assigning to `arguments` - _CPU profiling showed as much as 50% of the
time was used by Group.forEach_ (after the correction it is not
registered) due to this de-optimization making the "When Particles
Collide" demo run with an unsatisfactory performance, even on a Desktop.

The fix uses a separate array and push (which is optimizable; the previous
implementation was not optimizable in Chrome, FF, or IE!).

This also fixes usages of `slice(arguments,..); ushift` elsewhere in
Group, using the same convention. It applies the same update for `iterate`
as does https://github.com/photonstorm/phaser/pull/1353 so it can also
accept null/undefined for `args` from the invoking functions.
2014-11-24 01:55:16 -08:00
Paul
68f436ace8 Group - additional documentation refinement
General tidying/corrections of Group documentation.
2014-11-22 01:29:19 -08:00
Paul
946bb19dd7 Group - 'iterate' documentation and guard
Update iterate documentation to cover usage of `args` and added a guard so
that the callback can be used without requiring that `args` is specified.

Ref. https://github.com/photonstorm/phaser/issues/1352
2014-11-22 00:55:52 -08:00
photonstorm
2a7c0058e6 Tidied up code formatting. 2014-11-20 05:26:50 +00:00
Richard Davey
5fa06a241b Merge pull request #1325 from pnstickne/wip-collections
ArrayList/LinkedList updates
2014-11-16 18:54:24 +00:00
Richard Davey
cbaa36fdd6 Merge pull request #1291 from spayton/dev
Groups always had zero z index
2014-11-14 18:21:08 +00:00
Paul
aa3c21ade7 ArraySet/LinkedList - minor updates
- Renamed ArrayList to ArraySet
  - Added ArrayList is a deprecated proxy for compatibility
  - Updated internal code to use ArraySet

- ArraySet can be constructed with an array; if the caller is willing to
  accept some responsibility this can remove the O(n^2) behavior of
  repeatedly calling `add`.
  - Updated Group.filter to take advantage of this

- ArraySet.total is read-only proxy for for list.length

- Fixes ArraySet.setAll where it would only set properties with truthy
  values

- Updated documentation
2014-11-13 01:41:08 -08:00
Paul
a6d2da2a8a Math/Utils - various cleanup and deprecations/moves
There are no known breaking changes.

- Timer
  - Uses standard Math.min/Math.max (it's better 2, 3 items).

- Math
  - Updated documentation
  - Marked various Math functions as deprecated, proxying as appropriate
    - Array-based functions -> ArrayUtils
    - RNG-based functions -> Utils
    - Updated core-usage
    - floor/ceil should not be used (alternatives provided)
  - Altered for some equivalencies
  - Also fixes some assorted issues
  - Marked a few internal functions as private

- Utils
  - Moved polyfills to their own file for better visibility
  - Moved array functions to ArrayUtils and marked proxies as deprecated

- Created Phaser.ArrayUtils for array-related functions

- polyfills moved to their own file
  - Functions given function names
  - Added Math.trunc
2014-11-09 16:17:18 -08:00