Commit graph

77 commits

Author SHA1 Message Date
Casey Clyde
e935df328d Sprite vs Tilemap can now check for overlap, without trying to separate 2015-05-23 22:39:12 -07:00
photonstorm
432516fa0f Physics.Arcade.sort has a new property 'sortDirection'. If not specified it will use World.sortDirection. If the Group given as the first parameter has its physicsSortDirection property set that will override any other setting.
Physics.Arcade.sort now calls one of four functions: sortLeftRight, sortRightLeft, sortTopBottom and sortBottomTop. Each of which takes 2 Sprites as arguments.

Physics.Arcade.sort now doesn't bail out if the Group contains a mixture of physics and non-physics enabled objects, as the Group hash is now only ever populated with physics enabled objects. Also the sort comparison functions no longer return -1 if the bodies are invalid, but zero instead (#1721)
2015-04-13 16:29:34 +01:00
photonstorm
77eaa7e707 Optimised World.collideHandler and added SORT_NONE option. 2015-03-23 15:05:57 +00:00
photonstorm
f99f182a6f Arcade Physics is now using a spacial pre-sort for all Sprite vs. Group and Group vs. Group collisions. You can define the direction the sort will prioritise via the new sortDirection property. By default it is set to Phaser.Physics.Arcade.LEFT_RIGHT. For example if you are making a horizontally scrolling game, where the player starts on the left and moves to the right, then this sort order will allow the physics system to quickly eliminate any object to the right of the players bounds. This cuts down on the sheer volume of actual collision checks needing to be made. In a densely populated level it can improve fps rate dramatically.
There are 3 other directions available (`RIGHT_LEFT`, `TOP_BOTTOM` and `BOTTOM_TOP`) and which one you need will depend on your game type. If you were making a vertically scrolling shoot-em-up then you'd pick `BOTTOM_TOP` so it sorts all objects above and can bail out quickly.

More importantly you can switch the `sortDirection` at run-time with no loss of performance. Just make sure you do it *before* running any collision checks. So if you had a large 8-way scrolling world you could set the `sortDirection` to match the direction the player was moving in and adjust it in real-time, getting the benefits as you go. My thanks to Aaron Lahman for inspiring this update.
2015-02-26 21:24:07 +00:00
photonstorm
03a2db18cb Added extra protection in the case of mixed-type Groups.
Removed window vars and replaced with stats property.
Removed redundant if/else checks.
2015-02-25 06:06:40 +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
dee13d52d8 jshint fix. 2015-02-25 02:50:57 +00:00
photonstorm
c799dfe7da Fixed physics postUpdate issue causing particles and all kinds of things to go awry. 2015-02-25 02:18:05 +00:00
photonstorm
3d399f1b14 Removed the final few private vars from computeVelocity 2015-02-25 00:04:53 +00:00
photonstorm
42b316473d jsdoc fix. 2015-02-23 13:58:57 +00:00
photonstorm
eb732e1d90 Refactored ArcadePhysics.World to remove global property use and array length caches. 2015-02-19 04:59:55 +00:00
photonstorm
052b9a7e06 Separated the Tilemap specific code from World. 2015-02-17 15:49:53 +00:00
photonstorm
4bb1adcf36 Typo fix. 2015-02-17 06:00:18 +00:00
photonstorm
86f05160b7 Removed array length vars and added strict equalities. 2015-02-17 05:13:12 +00:00
photonstorm
18ff04810f ArcadePhysics.distanceToPointer now calculates the distance in world space values.
ArcadePhysics.moveToPointer no longer goes crazy if the maxTime parameter is given and the Sprite is positioned in a larger game world (thanks @AnderbergE #1472)
2015-02-10 22:16:35 +00:00
photonstorm
816a80f39a If Body.customSeparateX or customSeparateY is true then the Body will no longer be automatically separated from a **Tilemap** collision or exchange any velocity. The amount of pixels that the Body has intersected the tile is available in Body.overlapX and overlapY, so you can use these values to perform your own separation in your collision callback (#992) 2015-02-10 12:58:12 +00:00
Richard Davey
9efca46021 Merge pull request #1582 from micahjohnston/dev
Fix doc comment on Phaser.Physics.Arcade#getObjectsAtLocation.
2015-02-03 20:45:33 +00:00
zekoff
0ccd225e08 Allow max of 0 in computeVelocity
Previous method of setting default max did not allow falsey values.
2015-02-03 11:36:53 -06:00
Micah Johnston
34d443153f fix argument name in comment on Phaser.Physics.Arcade#getObjectsAtLocation. 2015-01-30 05:48:34 -07:00
Micah Johnston
401d2fe847 Fix doc comment on Phaser.Physics.Arcade#getObjectsAtLocation. 2015-01-29 18:13:03 -07:00
photonstorm
587c3e5f6a Arcade.Body.friction allows you to have more fine-grained control over the amount of velocity passed between bodies on collision. 2015-01-18 12:24:00 +00:00
photonstorm
0f42b530eb Physics.Arcade.isPaused allows you to toggle Arcade Physics processing on and off. If true the Body.preUpdate method will be skipped, halting all motion for all bodies. Note that other methods such as collide will still work, so be careful not to call them on paused bodies. 2015-01-10 00:30:02 +00:00
photonstorm
8cd98e2e36 jsdocs fixes. 2015-01-05 10:59:10 +00: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
Pete Baron
bc70ce74b5 Minor logic fix to nested loop counters. 2014-11-12 15:00:26 +13:00
Pete Baron
1c7059ea6c Merge remote-tracking branch 'phaser-github/dev' into dev
Conflicts:
	src/animation/FrameData.js
	src/core/Game.js
	src/particles/arcade/Emitter.js
	src/time/Time.js
	src/tween/Tween.js
2014-11-12 13:03:52 +13:00
Pete Baron
af09290cbf Add getObjectsAtLocation method in Arcade physics. 2014-11-12 11:24:38 +13:00
photonstorm
8bf93fb658 ArcadePhysics.skipQuadTree is now set to true by default. A QuadTree is a wonderful thing if the objects in your game are well spaced out. But in tightly packed games, especially those with tilemaps or single-screen games, they are a considerable performance drain and eat up CPU. We've taken the decision to disable the Arcade Physics QuadTree by default. It's all still in there and can be re-enabled via game.physics.arcade.skipQuadTree = false, but please only do so if you're sure your game benefits from this. 2014-11-11 01:05:58 +00:00
DanX
3a1ec3c5c1 Fix docs for collide and collideHandler 2014-09-26 22:37:11 -03:00
photonstorm
20551f9129 Lots of jsdocs fixes ready for the new doc generator. 2014-09-16 17:35:08 +01:00
Carlos Martinez
ec9a8b6903 Firxed for travis build. 2014-09-01 15:03:29 +01:00
Carlos Martinez
9843818f30 Merge branch 'dev' of https://github.com/photonstorm/phaser into dev 2014-09-01 14:19:50 +01:00
Carlos Martinez
0640cc0c03 Added support to pass 2 array in Arcade collide and overlap (response to an issue). 2014-09-01 14:01:36 +01:00
photonstorm
070e33f1e7 ArcadePhysics.overlap has been updated so that the Body.overlapX/Y properties are set to the amount the two bodies overlapped by. Previously they were zero and only populated during the separation phase, but now the data is available for just overlap checks as well. You can then use these values in your ovrelap callback as required - note that they are changed for every check, so a Sprite overlap tested against 10 other sprites will have the overlapX/Y values updated 10 times in a single collision pass, so you can only safely use the values in the callback (#641) 2014-09-01 03:54:55 +01:00
photonstorm
69b9e5eb7c Arcade.overlap and collide are now more consistent about allowing a Group vs. Group or Group vs. Array of Groups set (thanks @pyromanfo #877 #1147) 2014-08-29 01:28:43 +01:00
Allen Cook
5a3eeb8a9c Fix for group vs group within group collision (fixes #877) 2014-08-28 20:23:02 -04:00
photonstorm
36ecd81f29 Arcade Physics Body.skipQuadTree is a new boolean that if set to true when you collide the Sprite against a Group it will tell Phaser to skip using a QuadTree for that collision. This is handy if this Body is especially large.
Arcade Physics World.skipQuadTree will disable the use of all QuadTrees in collision methods, which can help performance in tightly packed scenes.
2014-08-04 13:04:11 +01:00
Charles Black
a90ab2e59b P2 bounds now collides with everything by default 2014-07-27 16:06:55 -04:00
photonstorm
2293b64c94 Removing debug / console.log output. 2014-07-09 05:49:13 +01:00
photonstorm
69525799d7 New build files for testing. 2014-06-11 12:46:49 +01:00
Richard Davey
13700148fb Merge pull request #891 from aivins/issue890
Separate from TilemapLayer after custom callbacks.
2014-06-11 00:00:20 +01:00
Lewis Lane
a16cb3f5a2 Added notes to overlap/collide regarding non-recursiveness
Made it clear that the overlap and collide methods do not recursively check for collisions, i.e. in the case of being passed a Group containing other Groups or Tilemaps.
2014-06-09 08:05:23 +01:00
Andrew Ivins
ccd914620d Separate from TilemapLayer after custom callbacks. 2014-06-09 14:28:14 +08:00
photonstorm
9c35dfde0c ArcadePhysics.Body has a new boolean property enable. If false the body won't be checked for any collision or overlaps, or have its pre or post update methods called. Use this for easy toggling of physics bodies without having to destroy or re-create the Body object itself. 2014-05-27 11:22:58 +01:00
photonstorm
2b40c8a7c7 Pointer.type and Pointer.exists properties added.
QuadTree.retrieve can now accept either a Sprite with a physics body or a Phaser.Rectangle as its parameter.
ArcadePhysics.getObjectsUnderPointer will return all children from a Group that overlap with the given Pointer.
2014-05-06 02:45:10 +01:00
photonstorm
713bd203ee ArcadePhysics.collideSpriteVsGroup checks if Sprite has a body before carrying on, now safely skips sub-groups or other non-Sprite group children.
QuadTree.retrieve now checks to see if the given Sprite has a body before carrying on.
2014-04-17 12:31:14 +01:00
photonstorm
9762bff5eb Updated docs to specify callback parameter order (#667) 2014-04-01 00:50:24 +01:00
Richard Davey
06c953a293 Merge pull request #647 from xtian/grunt-jshint
Run jshint as part of build process and fix jshint errors
2014-03-26 15:46:35 +00:00
photonstorm
fc0e239719 ArcadePhysics.Body preUpdate has been modified to stop Sprites with non-1 scaling from gaining delta and moving off the screen (fix #644).
Lots of ArcadePhysics.World methods have been marked as private where they shouldn't be called directly (separateX, etc)
2014-03-26 10:48:30 +00:00