Commit graph

798 commits

Author SHA1 Message Date
Richard Davey
29b4bb3174 :) 2015-09-16 02:25:40 +01:00
photonstorm
3be0ed8849 FrameDebugger now hooked into Canvas Renderer. Better output coming. 2015-09-15 16:14:14 +01:00
photonstorm
4125e42a06 Sorted out setting the Stage backgroundColor. Much more concise now. 2015-09-15 13:34:07 +01:00
photonstorm
ff254ec33b Added clearBeforeRender boolean. 2015-09-15 12:53:44 +01:00
photonstorm
0ee95b22d6 Fixed rogue comma. 2015-09-15 12:53:44 +01:00
photonstorm
b99c9e22ec Removed PIXI.Stage. Phaser.Stage now handles everything it needs to do. 2015-09-15 12:53:44 +01:00
photonstorm
705cacf2ca Sorting out the Stage background color assignment so we can drop a boolean check in the render method. 2015-09-15 12:53:43 +01:00
photonstorm
5a1a918a5d Added FrameDebugger.
Tidying up the renderer constructors.
2015-09-15 12:53:43 +01:00
photonstorm
06ed961e81 Added FrameDebugger into the mix. 2015-09-15 12:53:43 +01:00
photonstorm
8db23545da jsdoc updates. 2015-09-10 15:57:55 +01:00
photonstorm
90a500ec1e Game.update could call updateLogic multiple times in a single frame when catching up with slow device frame rates. This would cause Tweens to advance at twice the speed they should have done (thanks @mkristo)
Time.desiredFpsMult is a pre-calculated multiplier used in Game.update.

Time.refresh updates the `Time.time` and `Time.elapsedMS` values and is called automatically by Game.update.
2015-09-09 12:09:18 +01:00
photonstorm
2de83328d9 Testing Tween timer fix. 2015-09-08 17:44:28 +01:00
Richard Davey
38eca4d5b9 Filter.addToWorld allows you to quickly create a Phaser.Image object at the given position and size, with the Filter ready applied to it. This can eliminate lots of duplicate code. 2015-09-03 00:46:47 +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
Paul
26a6338072 Change splice.call(arguments, ..) to use slice
- Bypasses issue of usage incorrectly omitting 2nd argument to `splice`

- More clear of intent; `slice` does not modifify `arguments`

- `slice` is faster across all desktop browsers, by varying degrees
  - Probably due to parameter-aliasing and de-opts when modified.
  - Both `slice` and `splice` create a new Array object
2015-08-26 23:50:16 -07:00
nickryall
57aaf23238 Fix for fullscreen retina 2015-08-09 20:32:04 +12:00
Brice Thomas
ef536d276a doc(Signal): fix typo 2015-08-06 13:34:14 +02:00
photonstorm
b365ebf570 jshint fix. 2015-08-03 16:45:03 +01:00
photonstorm
f4a1f11429 PIXI.CanvasPool is a new static global created to deal with the issue of resource leaks and continuous DOM node build-up when creating lots of Text or BitmapData objects, or when calling generateTexture on any display object. The CanvasPool will do its best to re-use out dated canvas elements rather than filling up the DOM with new ones.
Sprite.setTexture has a new `destroyBase` parameter - set this to `true` if you know the base used a generated texture that isn't being used by any other sprites. This will free-up the canvas for further re-use by other calls to generateTexture or Text objects.
2015-08-03 16:09:16 +01:00
photonstorm
e901fb80f6 Merging in the CanvasPool changes to the core. 2015-08-03 14:46:55 +01:00
photonstorm
98ae410c34 Removed use of the deprecated enterFullScreen and leaveFullScreen signals from the Scale Manager (thanks @mmanlod #1972) 2015-08-03 11:44:00 +01:00
photonstorm
858ad51610 Phaser 2.4 release. 2015-07-22 15:31:30 +01:00
photonstorm
ffaa7d711f Removed BaseTextureCache requirement from BitmapData.
Fixed jshint.
Updated TS defs.
2015-07-22 13:23:40 +01:00
photonstorm
8eb34f96ce WebGL context loss and restoration is now handled directly by Phaser.
Cache.clearGLTextures empties out all of the GL Textures from Images stored in the cache. This is called automatically when the WebGL context is lost and then restored.
2015-07-22 12:59:32 +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
9e38bf974a World.stateChange is a new method that is called whenever the state changes or restarts. It resets the world x/y coordinates back to zero and then resets the Camera.
Sprites with Arcade Physics bodies that had `collideWorldBounds` enabled would be moved to the wrong position if you restarted a State (or swapped to a new State) that reset the world bounds (thanks @vulvulune #1775)
2015-07-22 01:24:26 +01:00
Richard Davey
5e33a2ea92 TS defs updates for the Cache changes. 2015-07-15 23:22:51 +01:00
Richard Davey
4dec046c40 Added pendingDestroy to Groups. 2015-07-12 11:33:30 +01:00
Richard Davey
1850e287bd Merge pull request #1899 from spayton/updev
Removed use of deprecated signals (enterLandscape & enterPortrait)
2015-07-10 17:09:35 +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
spayton
37e0efefe3 Removed use of deprecated signals (enterLandscape & enterPortrait) 2015-07-10 14:42:17 +01:00
Richard Davey
8e92c13412 Canvas.setSmoothingEnabled only applies the value of the property exists, which avoids the Chrome webkit prefix deprecation warnings. 2015-07-10 04:02:21 +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
photonstorm
5f611f83cb Fixed small texture bug. 2015-07-09 15:51:24 +01:00
photonstorm
8cf300fc11 Added Japanese Machine palette. 2015-07-09 14:29:18 +01:00
photonstorm
630886da28 Reverting Windows Phone WebGL - Canvas force #1706 2015-07-09 11:51:27 +01:00
Richard Davey
0dc8757781 Updates. 2015-07-09 01:30:03 +01:00
Richard Davey
6a8e6a7954 Adding in Phaser.Create. 2015-07-09 00:19:21 +01:00
photonstorm
b9dcf74726 If the device is detected as a Windows Phone the renderer is automatically set to use Canvas, even if WebGL or AUTO was requested (thanks @ramarro123 #1706) 2015-07-08 15:25:52 +01:00
photonstorm
1281bc52d7 Setting the scaleMode property of a Game configuration object would cause a ScaleManager TypeError in the resize method. It now stores the scale mode locally and applies it after boot (thanks @Mickawesomesque #1534) 2015-07-08 14:52:20 +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
Richard Davey
5f2b2df3d4 Yuma :) 2015-06-22 00:31:54 +01:00
photonstorm
102c74e121 Deprecated the following:
* Camera.screenView
* ScaleManager.maxIterations
* ScaleManager.enterPortrait (see onOrientationChange)
* ScaleManager.enterLandscape (see onOrientationChange)
* ScaleManager.enterFullScreen (see onFullScreenChange)
* ScaleManager.leaveFullScreen (see onFullScreenChange)
* ScaleManager.fullScreenFailed (see onFullScreenError)
* ScaleManager.checkResize
* ScaleManager.checkOrientation
* ScaleManager.setScreenSize (see updateLayout)
* ScaleManager.setSize (see reflowCanvas)
* ScaleManager.checkOrientationState (see reflowCanvas)
* ScaleManager.orientation (see screenOrientation)
* Gamepad.disabled (see enabled)
* Input.currentPointers (see totalActivePointers)
* Input.disabled (see enabled)
* Keyboard.disabled (see enabled)
* Mouse.disabled (see enabled)
* Mouse.mouseMoveCallback (see Input.addMoveCallback)
* MSPointer.disabled (see enabled)
* Touch.disabled (see enabled)
* Cache.getUrl (see getURL)
* Math.truncate (see Math.trunc)
* Math.snapToInArray (see Phaser.ArrayUtils.findClosest)
* Math.interpolateFloat (see Math.linear)
* Math.normalizeLatitude (use Phaser.Math.clamp(lat, -90, 90))
* Math.normalizeLongitude (use Phaser.Math.wrap(lng, -180, 180))
* Math.chanceRoll (use Phaser.Utils.chanceRoll)
* Math.numberArray (use Phaser.ArrayUtils.numberArray)
* Math.numberArrayStep (use Phaser.ArrayUtils.numberArrayStep)
* Math.limitValue (use Phaser.Math.clamp)
* Math.randomSign (use Phaser.Utils.randomChoice(-1, 1))
* Math.angleLimit (use Phaser.Math.clamp)
* Math.getRandom (use Phaser.ArrayUtils.getRandomItem)
* Math.removeRandom (use Phaser.ArrayUtils.removeRandomItem)
* Math.floor (use Math.trunc)
* Math.ceil (use Phaser.Math.roundAwayFromZero)
* Math.shift (use Phaser.ArrayUtils.rotate)
* Math.shuffleArray (use Phaser.ArrayUtils.shuffle)
* Math.distanceRounded (do the rounding locally)
* Canvas.getOffset (see Phaser.DOM.getOffset)
* Canvas.getAspectRatio (see Phaser.DOM.getAspectRatio)
* TilemapLayer.tileColor (use TilemapLayer.debugSettings.missingImageFill)
* Phaser.ArrayList alias removed, now use Phaser.ArraySet
* Utils.transposeArray (see Phaser.ArrayUtils.transposeMatrix)
* Utils.rotateArray (see Phaser.ArrayUtils.rotateMatrix)
* Utils.shuffle (see Phaser.ArrayUtils.shuffle)
2015-06-17 03:14:31 +01:00
photonstorm
00cf44eb22 If running under Cordova and iOS the Game.lockRender boolean will be set to true when the game pauses and false when it resumes. This avoids the gpus_ReturnNotPermittedKillClient app crash on iOS (thanks @cncolder #1800) 2015-06-16 14:54:42 +01:00
photonstorm
697a3f4f18 jsdoc tweak. 2015-06-16 11:57:28 +01:00
photonstorm
5c6eab86c0 Swapped to the shorter 'between' method. 2015-06-09 20:54:52 +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
18ae9268aa Scope fix. 2015-05-22 15:14:49 +01:00
photonstorm
c2f7520c7a StateManager.onStateChange is a new signal which is dispatched whenever the State changes from one to another. The callback you specify is sent two parameters: the string based key of the new state, and the second parameter is the string based key of the old / previous state. 2015-05-22 15:10:20 +01:00
photonstorm
23f2a7ca66 Removed 'scale' from Group as it comes from PIXI anyway. 2015-05-12 13:03:27 +01:00
photonstorm
7c123b5203 Add guards around scaleSprite. 2015-05-12 13:03:26 +01:00
photonstorm
714580f9a9 Manual fix #1752 2015-04-17 17:35:52 +01:00
photonstorm
333663731d Added the missing preRender function to the Phaser.State class template. 2015-04-15 01:37:18 +01:00
photonstorm
f2f8dcd061 Phaser.StateManager no longer calls preRender unless the State create method has finished. If the State doesn't have a create method then preRender runs immediately.
Phaser.StateManager.created is a new read-only boolean that tells you if the State has finished running its `create` method. If it doesn't have one it's always true.
2015-04-15 01:36:50 +01:00
photonstorm
9f493044d4 The StateManager would incorrectly call loadUpdate while the game was paused or if the State didn't have an update method defined even after the loader was completed.
The StateManager would incorrectly call `loadRender` while the game was paused or if the State didn't have an `render` method defined even after the loader was completed.
2015-04-14 15:34:32 +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
49be59b0c9 Added missing resumed method to Phaser.State class template. 2015-03-26 10:54:32 +00:00
photonstorm
8233b0a079 Phaser 2.3.0. 2015-03-26 02:37:31 +00:00
photonstorm
7e19f45350 When the Game first boots it will now call window.focus(). This allows keyboard events to work properly in IE when the game is running inside an iframe. You can stop this from happening by setting window.PhaserGlobal.stopFocus = true (thanks @webholics #1681) 2015-03-24 13:27:27 +00:00
photonstorm
7aa4d0ad0d When a State is started and linked to Phaser it has a new property created on it: key, which is the string identifier used by the State. 2015-03-24 10:21:03 +00:00
photonstorm
1486e166bd Added physicsType property. 2015-03-23 15:04:27 +00:00
photonstorm
53b1562eb6 jshint fix 2015-02-26 23:12:26 +00:00
photonstorm
74eeddf956 You can now set a resolution property in your Game Configuration object. This will be read when the Pixi renderer instance is created and used to set the resolution within that (#1621) 2015-02-26 10:52:30 +00:00
photonstorm
8aec760cd5 First pass at spacial sorting in World.collide. 2015-02-25 05:39:02 +00:00
photonstorm
321e11d0a5 A State swap now sets the Loader.reset hard parameter to true by default. This will null any Loader.preloadSprite that may have been set (#1636) 2015-02-25 05:18:49 +00:00
photonstorm
a69e53f901 Copyright date change. 2015-02-25 03:36:23 +00:00
photonstorm
ec19abb91c Component preUpdate changes. 2015-02-25 00:59:27 +00:00
photonstorm
35b4926eb8 Undoing previous change - doesn't actually work at all! #1620 2015-02-18 23:32:12 +00:00
photonstorm
4699770520 Adjusted function order. 2015-02-18 23:15:54 +00:00
photonstorm
9effb4a946 Stage.visibilityChange now has a second parameter fromPhaser. This is set to true by the Stage._onChange callback. This should mean that when Phaser is listening for window.onblur and window.onfocus events it will only trigger the visibilityChange if that event was generated by Phaser itself. If it was generated by something else on the page or iframe it should now be ignored (thanks @austinhallock #1620) 2015-02-18 23:12:08 +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
9fd5ae119b jsdocs update. 2015-02-17 06:01:09 +00:00
photonstorm
8892f46a83 PIXI.WebGLRenderer.destroy has been fixed to decrement the glContextId and remove it from the PIXI.instances global. Game.destroy now hooks into this. This now means that you can now delete and create your Phaser game over and over without it crashing WebGL after the 4th attempt (#1260) 2015-02-11 21:02:15 +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
42c75c0ad2 Updated jsdocs to mention roundPixels (#1377) 2015-02-11 15:32:52 +00:00
photonstorm
6506e8d7e6 JSdocs update (fix #1520) 2015-02-11 13:47:58 +00:00
photonstorm
7a066a3a8c World.setBounds will now adjust the World.x/y values to match those given (#1555) 2015-02-10 21:40:53 +00:00
photonstorm
0054dc996b The Loader now directly calls StateManager.loadComplete rather than the StateManager listening for the loadComplete event, because Loader.reset unbinds this event (and it's easy to accidentally remove it too)
Loader.onLoadComplete is dispatched *before* the Loader is reset. If you have a `create` method in your State please note that the Loader will have been reset before this method is called. This allows you to immediately re-use the Loader without having to first reset it manually.
2015-02-10 17:04:04 +00:00
photonstorm
2b2ee27912 If for whatever reason you wish to hide the Phaser banner in the console.log you can set window.PhaserGlobal.hideBanner to true and it will skip the output. Honestly I'd rather if you didn't, but the option is now there. 2015-02-09 20:10:51 +00:00
photonstorm
5bd231d532 JSDoc fixes. 2015-02-05 05:13:22 +00:00
photonstorm
569483ab17 Game._kickstart forces Phaser to always call at least one logic update before being allowed to render. 2015-02-05 05:12:59 +00:00
Richard Davey
21823f65e3 Merge pull request #1576 from vulvulune/jsdoc
Correct comments
2015-02-03 20:47:32 +00:00
Richard Davey
ad9b8ae8e1 Merge pull request #1568 from Bilge/patch-1
Added missing plugins member in Phaser.Game class.
2015-02-03 20:31:26 +00:00
Bilge
92b89fb549 Added plugins property to Phaser.Game.
Property was previously being declared late without initialization at allocation time.
2015-01-29 22:51:38 +00:00
vulvulune
2e49f07b77 Correct comment Phaser.Stage
Replace @name => @method on some functions
2015-01-27 14:05:47 +01:00
vulvulune
8ef32f044c Correct comments
Correct comments:
-Phaser.Camera: checkWorldBounds =>checkBounds
-Phaser.RetroFont: Set correct @name for name and smoothed
-Phaser.DOM: inViewport => inLayoutViewport
2015-01-27 13:46:18 +01:00
photonstorm
3c2725addc Typo. 2015-01-18 12:24:00 +00:00
photonstorm
8973423e98 Sprite.frame and AnimationManager.frame wouldn't return the correct index if a sprite sheet was being used unless it had first been set via the setter. 2015-01-08 01:28:38 +00:00
photonstorm
30ef362e59 jsdoc fixes / typos. 2015-01-06 12:58:19 +00:00
photonstorm
4bc8fb3c8f Docs update #1489 2015-01-05 11:57:46 +00:00
Paul
81c872adf1 Simplified call to updateTransform
This change implements the original suggestion of using `updateTransform`,
but applies so globally instead of within a particular postUpdate
function.

Now the game loop calls `updateTransform` after each `updateLogic` call
unconditionally; it is updates that change the world that are accounted
for, not the rendering. This removes some previous checks that were
preventing correct behavior with the previous patch.

This makes the assumption that game objects (eg. Sprites) are only
modified within callbacks triggered before the completion of the
`postUpdate` walking of the scene graph.
- User code that runs outside of the "game update", such as a `setTimeout`
  timer, will need to explicitly update transformations so that the world
  is synced by the next `preUpdate`: but this is not the expected case and
  is already outside the Phaser update model.
- If this assumption does not hold or is too weak, the transformations
  could also be applied once at the start of every game update loop
  (before any render or update). This change would at most double the time
  spent on apply the transformations.

The constant application of `updateTransform` passes all reported failing
cases and resolves #1424 just as the original proposal of having the
change performed in the Sprite postUpdate but will work more consistently
across all scene-bound game objects.

On a desktop Chrome browser the inclusion also has minimal relative impact
as shown by the summarized results. The percentages given are the summed
CPU time of relevant required operations along with that of the
updateTransform itself:

- 10,000 non-collision particles:
  - 12% pre/post update, 2.4% updateTransform
- 100 colliding particles:
  - 2% pre/post update & collision, 0.3% updateTransform
- 1000 colliding particles:
  - 40% pre/post update & collision, 1% updateTransform

With this patch the updateTransform time does creep up _slightly_ (vs just
in `Sprite.postUpdate`) but it is still dominated by required game
updates, and more so, by any actual work like Physics.
2015-01-01 18:01:23 -08:00
photonstorm
ef610c7c10 Added init to State template class. 2014-12-17 13:07:19 +00:00
Richard Davey
091cb93ccd Merge pull request #1417 from pnstickne/wip-1410
Fixes #1410 where newChild.parent could be set to undefined before use
2014-12-11 21:52:55 +00:00
Richard Davey
9ef87ad395 Merge pull request #1428 from pnstickne/wip-1422-vertical-align
ScaleManager documentation updates
2014-12-10 17:16:46 +00:00
photonstorm
028943baad Moved the updateTransform to a Game level update on Stage and replaced the Pixi version.
Added a boolean check, so it can be either updated from updateLogic or render without duplicating the process.
#1424
2014-12-10 10:37:37 +00:00
Paul
6764517823 ScaleManager documentation updates
- Clarified proper usage of `pageAlignVertically` and add note about 2.2
  change and how to obtain 2.1 behavior.

- Removed the `@readonly` status of the `parentIsWindow` and `parentNode`;
  these can be updated in a controlled manner.

- Added intra-hyperlinks

- Updated some ancillary documentation
2014-12-08 18:06:26 -08:00
Paul
388ab1d98b Fix Full Screen launching in Android Chrome
The click trampoline added for IE prevents Chrome for Android from being
able to launch Full Screen mode with the default parameters for
`ScaleManger#startFullScreen`. (The desktop version of Chrome is not
affected.)

This fix adds an additional compatibility settings (`clickTrampoline`)
that can be used to configure when such is used. By default the
'when-not-mouse' mode is only enabled for Desktop browsers, where the
primary input is ubquitously a mouse.

There are no known breaking compatibility changes - the Full Screen should
be initiatable in Chrome for Android as it was in 2.1.x. The default
Android browser does not support Full Screen.
2014-12-06 12:30:40 -08: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
photonstorm
3371f9ff1e Added Game.debug reset method for when the debug manager is disabled (thanks @DanielSitarz #1407) 2014-12-03 20:56:39 +00:00
photonstorm
84e845db71 Various doc fixes. 2014-12-03 03:19:25 +00:00
photonstorm
3018eaece9 Setting forceMinimumDocumentHeight default to false. This is an iOS edge-case and messes with desktop browsers.
Fix #1399
2014-12-02 14:37:07 +00:00
photonstorm
35e2893db4 Game.lockRender is a new property. If false Phaser will automatically render the display list every update. If true the render loop will be skipped. You can toggle this value at run-time to gain exact control over when Phaser renders. This can be useful in certain types of game or application. Please note that if you don't render the display list then none of the game object transforms will be updated, so use this value carefully. 2014-12-02 09:03:55 +00:00
photonstorm
03ebb8d11c Docs update. 2014-12-02 09:03:55 +00:00
Richard Davey
152b26a668 Merge pull request #1378 from pnstickne/wip-minor-updatelogic-fix
Minor logic fix for Sprite life update
2014-12-01 12:07:56 +00: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
bedab931a9 Documentation - Signal 2014-11-30 15:56:20 -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
8b1c7625d4 Documentation - typo fix 2014-11-30 04:05:23 -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
photonstorm
cfbad72881 Documentation - general
Updated some documentation for formatting, consistency, and minor
corrections.
2014-11-30 04:02:45 -08:00
Paul
dfe7279090 Minor logic fix for Sprite life update
The substraction of `physicsElapsedMS` needs to be done for all individual
updates. (When current FPS ~ target FPS this is a 1-1 mapping, but catchup
updates can throw off the calculations.)

Also renamed `Game#updateNumber` (a poor initial name on my part) to
`currentUpdateID`. This matches the naming of
`Stage#currentRenderOrderID`.
2014-11-28 23:02:31 -08:00
photonstorm
fb733ddcca onPreRenderCallback wasn't being cleared on a State swap. 2014-11-26 13:12:51 +00:00
photonstorm
fc457f5aca Added missing docs. 2014-11-26 04:16:52 +00:00
photonstorm
3d3920efab Various jsdoc fixes. 2014-11-25 21:13:25 +00:00
photonstorm
72eaee3139 Adjusted Sprite.preUpdate to remove the lifespan calculation. 2014-11-25 14:18:18 +00:00
Paul
e8869e057a Game/Time - updateNumber and updatesThsiFrame
- Changed `count` from 0d9678e512 to
  `updateNumber` and expanded documentation; also moved primary usage back
  to local variable.

- Added `updatesThisFrame` which allows (logic) code to detect if it is
  the last update, or if there are pending updates the same frame. While
  it could be adventageous in certain cases it will be problematic if such
  update logic relies in the supplied delta time, as such should change if
  fixed-timing is deviated from or extended updates are done.

- Formatting and documentation.
2014-11-25 01:04:36 -08:00
photonstorm
0d9678e512 Promoted Game time loop count to protected public var. Checked in Sprite.lifespan decrement to avoid over-decreasing the lifespan (#1358) 2014-11-25 02:50:39 +00:00
photonstorm
c4b81ff6ea jsdoc fixes. 2014-11-25 00:24:28 +00:00
Richard Davey
386c6df4fc Merge pull request #1359 from pnstickne/wip-optimize-signal
Signal - memory optimization / reductions
2014-11-24 13:35:29 +00:00
Paul
e62442bcb7 Signal - memory optimization / reductions
There are a fair amount of Signal objects created. In the current
implementation these are somewhat "fat" objects for two reasons:

- A closure / ad-hoc `dispatch` is created for each new Signal - this
  increases the retained size by 138+ bytes/Signal in Chrome.

- There are a number of instance variables that never change from their
  default value, and the bindings array is always created, even if never
  used.

This change "lightens" the Signals such that there is significantly less
penalty for having many (unusued) signals.

As an example of how much this _does_ play a role, in the "Random Sprite"
demo ~2000 Signals are created, with only 12 of these signals being
subscribed to. This results in a shallow size of ~300K and a retained size
of ~600K (which is almost as much memory as required by the
Sprites/Sprites themselves!) for .. nothing.

With these changes the shallow and retained sizes are less than 50K each -
and this is with only ~200 sprites!

This change addresses these issues by

- Changing it so there is _no_ `dispatch` closure created. This is a
  _breaking change_ (although there is no usage of such in core where it
  breaks); the code referenced "#24", but no such issue could be found on
  github.

  In the rare case that code needs to obtain a dispatch-closure, the
  `boundDispatch` property can be used to trivially obtain a (cached)
  closure.

- The properties and default values are moved into the prototype; and the
  `_bindings` array creation is deferred. This change, coupled with the
  removal of the automatic closure, results in a very lightweight
  ~24bytes/object (in Chrome) for unbound signals.

This is minor breaking change, as per the removal of the automatic
closure; but no such need/usage was found in the core. (There may be cases
in the examples, which were not checked.)

If merely opting for the array creation delay and keeping the default
properties in the prototype the shallow size is still halved; less
significant but still a consideration.
2014-11-24 04:55:29 -08:00
Paul
beeda75ff5 Signal - object optimizations
Optimizing object creation, mainly of the backing array in situations when
there is no backing array.
2014-11-24 02:43:56 -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
874f60c1bc Removed CocoonJS hack - woohoo! 2014-11-21 10:40:18 +00:00
Richard Davey
ca3ecd796e Merge pull request #1346 from pnstickne/wip-scalemanager-windowbounds2
ScaleManager + DOM - window constraint updates
2014-11-20 20:34:24 +00:00
photonstorm
2589000435 Tweens have been completely rewritten. They're now much more flexible and efficient than before:
When specifying the ease in `Tween.to` or `Tween.from` you can now use a string instead of the Function. This makes your code less verbose. For example instead of `Phaser.Easing.Sinusoidal.Out` and you can now just use the string "Sine".The string names match those used by TweenMax and includes: "Linear", "Quad", "Cubic", "Quart", "Quint", "Sine", "Expo", "Circ", "Elastic", "Back", "Bounce", "Power0", "Power1", "Power2", "Power3" and "Power4". You can append ".easeIn", ".easeOut" and "easeInOut" variants. All are supported for each ease types.
Tweens now create a TweenData object. The Tween object itself acts like more of a timeline, managing multiple TweenData objects. You can now call `Tween.to` and each call will create a new child tween that is added to the timeline, which are played through in sequence.
Tweens are now bound to the new Time.desiredFps value and update based on the new Game core loop, rather than being bound to time calculations. This means that tweens are now running with the same update logic as physics and the core loop.
Tween.timeScale allows you to scale the duration of a tween (and any child tweens it may have). A value of 1.0 means it should play at the desiredFps rate. A value of 0.5 will run at half the frame rate, 2 at double and so on. You can even tween the timeScale value for interesting effects!
Tween.reverse allows you to instantly reverse an active tween. If the Tween has children then it will smoothly reverse through all child tweens as well.
Tween.repeatAll allows you to control how many times all child tweens will repeat before firing the Tween.onComplete event. You can set the value to -1 to repeat forever.
Tween.loop now controls the looping of all child tweens.
Tween.onRepeat is a new signal that is dispatched whenever a Tween repeats. If a Tween has many child tweens its dispatched once the sequence has repeated.
Tween.onChildComplete is a new signal that is dispatched whenever any child tweens have completed. If a Tween consists of 4 sections you will get 3 onChildComplete events followed by 1 onComplete event as the final tween finishes.
Chained tweens are now more intelligently handled. Because you can easily create child tweens (by simply calling Tween.to multiple times) chained tweens are now used to kick-off longer sequences. You can pass as many Tween objects to `Tween.chain` as you like as they'll all be played in sequence. As one Tween completes it passes on to the next until the entire chain is finished.
Tween.stop has a new `complete` parameter that if set will still fire the onComplete event and start the next chained tween, if there is one.
Tween.delay, Tween.repeat, Tween.yoyo, Tween.easing and Tween.interpolation all have a new `index` parameter. This allows you to target specific child tweens, or if set to -1 it will update all children at once.
Tween.totalDuration reports the total duration of all child tweens in ms.
There are new easing aliases:
* Phaser.Easing.Power0 = Phaser.Easing.Linear.None
* Phaser.Easing.Power1 = Phaser.Easing.Quadratic.Out
* Phaser.Easing.Power2 = Phaser.Easing.Cubic.Out
* Phaser.Easing.Power3 = Phaser.Easing.Quartic.Out
* Phaser.Easing.Power4 = Phaser.Easing.Quintic.Out
2014-11-20 06:06:26 +00:00
photonstorm
2a7c0058e6 Tidied up code formatting. 2014-11-20 05:26:50 +00:00
photonstorm
4220382376 Evolving the Tween engine. TweenMax string syntax now supported. 2014-11-20 05:26:49 +00:00
Paul
e7fd527c72 ScaleManager + DOM - window constraint updates
ScaleManager.windowContraints now allows specifing 'visual' or 'layout' as
the constraint. Using the 'layout' constraint should prevent a mobile
device from trying to resize the game when zooming.

Including the the new changes the defaults have been changed to

   windowContraints = { right: 'layout', bottom: '' }

This changes the current scaling behavior as seen in "Game Scaling" (as it
will only scale for the right edge) but also prevents such scaling from
going wonkers in some mobile environtments like the newer Android browser.
(Automatic scroll-to-top, albeit configurable, enabled for non-desktop by
default is not a fun situation here.)

To obtain the current semantics on a desktop the bottom should be changed
to 'layout'; although this will result in different behavior depending on
mobile device. To make the sizing also follow mobile zooming they should
be changed to 'visual'.

Also added temp Rectangle re-used for various internal calculations.

---

Phaser.DOM now also special-cases desktops to align the layout bounds
correctly (this may disagree with CSS breakpoints but it aligns the with
actual CSS width), without applying a window height/width expansion as
required on mobile browsers.

(And the jshint error isn't mine..)
2014-11-19 15:42:08 -08:00
photonstorm
1d2b36fa1b Camera.preUpdate. 2014-11-18 12:36:25 +00:00
photonstorm
683f1a3a10 Tiny bit of tidying up. 2014-11-18 12:30:14 +00:00
photonstorm
21479acd8e Sprite.autoCull now properly works if the camera moves around the world.
Sprite.inCamera uses a much faster check if auto culling or world bounds checks are enabled and properly adjusts for camera position.
2014-11-18 12:29:55 +00:00
Paul
644f87b15d ScaleManager + DOM 2014-11-17 23:56:30 -08:00
Paul
884353d71e ScaleManager + DOM
"Final" changes for a solid 2.2-worthy ScaleManager.

This adds in official support for USER_SCALE, which allows a flexible way
to control the scaling dynamically.

It fixes a visible display bug in desktop browsers (viewport clipping was
off) and mitigates some potential issues all around by using a unified
visualBound calculations in Phaser.DOM.

It applies some protected/deprecated attributes, but does not remove any
behavior of already-established (as in, outside-dev) means.

There are no known [signficant] breaking changes; any known breaks (not
considered fixes) are constrained to dev with no known consumers.

Phaser.DOM

  There are no known significant breaking changes; Phaser.DOM was
  internal.

  - Added visualBounds; this should be the true visual area, minus the
    scrollbars. This should be used instead of clientWidth/clientHeight to
    detect the visual viewport.

  - Expose various viewport sizes as dynamically updated properties on
    Rectangle objects. These are visualBounds, layoutBounds,
    documentBounds.

  - Updated documentation the different bounds; in particular drawing
    distinction between viewport/layout bounds and visual bounds.

  - Renamed `inViewport` to `inLayoutViewport` to indidcate behavior.
    - Minor breaking, but dev-only

  - Changed `getAspectRatio` to work on Visual viewport. This will yield
    the expected behavior on mobiles.
    - Minor breaking, but dev-only

  - Removed some quirks-mode and legacy-browser special casing

Phaser.ScaleManager

  There are no known significant breaking changes.

  - USER_SCALE is 'made public'. It can used to flexibly configure any
    custom-yet-dynamic scaling requirements; it should now be able to
    replace any sane usage of manual sizing invoking the deprecated
    setSize/setScreenSize.
    - Added additional usage documentation and links to such
    - Added the ability to specify a post-scale trim factor.

  - Change the arguments the resize callback and document what is passed
    - Minor breaking, but the previous arguments were undocumented

  - `compatiblity.showAllCanExpand` renamed to `canExpandParent` and made
    generalized over possibly-expanding scaling.
    - Minor breaking, dev-only, for coding changing this settin

  - Switched from direct usage of of window innerWidth/Heigth to
    Phaser.DOM visualViewport - this change correctly accounts for
    scrollbars in desktop environments
    - Although it does slightly alter the behavior, this is a fix.

  - Removed usage of window outerWidth/outerHeight which didn't make much
    sense where it was used for desktops and was catostrophic for mobile
    browser
    - Although it may slightly alter the behavior, this is a fix.

  - Removed `aspect` and `elementBounds` because they are duplicative of
    Phaser.DOM (which can not be accessed as `scale.dom`).
    - Minor breaking, but internal methods on dev-only

  - Marked the minWidth/maxWidth/minHeight/maxHeight properties as
    protected. They are not removed/obsoleted, but should be revised later
    for more flexibility.

  - Orientation handling; non-breaking forward deprecations
    - Added `onOrientationChange` and deprecated the 4 separate leave,
      enter, landscape and portrait signals. They are not removed, so this
      is a future-migration change.
    - Fixed issue where state not updated prior to callback
    - Fixed issue where orientation callbacks were not always delayed

  - Fullscreen events: non-breaking forward deprecations
    - Added `onFullScreenChange` and deprecated `enterFullScreen` and
      `leaveFullScreen`.
    - Renamed (with proxy) `fullScreenFailed` to `onFullScreenError`.

Phaser.Device

  - Improved `whenReady` to support Phaser.DOM better
    - Allows a ready handler to be added without starting the
      device-detection proccess. This allows it to be registered to
      internally (eg. from System.DOM) without affecting current behavior.
    - Passes the device object as the first parameter to the callback
      function.

  - Fixed code where Silk detection not applied to `desktop` detection.

Manifest: System.Device moved before System.DOM
2014-11-17 23:48:06 -08:00
Richard Davey
5fa06a241b Merge pull request #1325 from pnstickne/wip-collections
ArrayList/LinkedList updates
2014-11-16 18:54:24 +00:00
Paul
d72d4c41dc ScaleManger - better FS init, documentation
- Added `onFullScreenInit` signal which is the correct place for a client
  to alter the FS target element, such as to set a background color or add
  a CSS class.

- Increased documentation overview and specificity including expected
  Parent behavior, sizing calculations, and when `refresh` may be required.

- Grouped documentation for scale modes (in 'scaleMode')

- Separated out internal/deprecated `setScreenSize` method from
  `updateLayout`.

There are no known breaking changes.
2014-11-16 00:34:26 -08:00
Richard Davey
497a9ecd70 Merge pull request #1328 from pnstickne/wip-device-to-1
Phaser.Device - inverted from Game
2014-11-14 18:34:38 +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
599479dfdf Phaser.Device - inverted from Game
The only known breaking change is if user-code relied on `device.game` or
manually called `checkFullScreenSupport`, as both have been removed.

- Phaser.Device is now a singleton object that does not belong to a
  particular game. The only thing that it belongs to is the window/host
  context.
  - `game.device` (shared between all games) and `Phaser.Device` are the
    same object.
  - There is no more `Device#game` property.

- The specific device-ready detection is moved out of Game into the Device
  code
  - It is possible for multiple Games (or even non-Games) to use
    `Device.whenReady`.
  - Initialization is done immediately upon device-ready; there is an
    onInitialized signal that is dispatched that can be subscribed to
    extend the default initialization.

- The fullscreen-detection code (that was the only dependent of game) now
  uses an new element.

- Updated jsdoc documentation
2014-11-13 18:21:28 -08: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
794c9f65fe ArrayList/LinkedList - moved from core to utils
- ArrayList is also renamed to ArraySet to better reflect the nature
2014-11-13 00:59:42 -08:00
Sean
ef49f9bede Modify value of PIXI.scaleMode.DEFAULT instead of PIXI.scaleMode.LINEAR since LINEAR and NEAREST are constants 2014-11-13 15:01:44 +08:00
photonstorm
497b00d781 Tidying up a little. 2014-11-13 00:27:47 +00:00
photonstorm
e7356fc575 Pixi 2.1.1 merge. 2014-11-12 22:38:51 +00:00
Richard Davey
7366854f9b Merge pull request #1307 from pnstickne/wip-math-util-cleanup
Math/Utils - various cleanup and deprecations/moves
2014-11-12 22:21:34 +00:00
Richard Davey
d786d4e455 Merge pull request #1317 from pjbaron/dev
prevent multiple catch-up frames which cause physics objects to 'tunnel'
2014-11-12 13:04:25 +00:00
Pete Baron
7bd0a8db71 Temporary fix to prevent huge numbers of catch-up frames happening all at once if the user navigates away from the game. Limits them to 3 now (which allows it to still detect and react to spiralling).
A proper fix involves putting the physics collision into the same update as the physics motion.
2014-11-13 00:00:13 +13:00
Richard Davey
26e74fef18 Merge pull request #1315 from pjbaron/dev
Minor logic fix and updateRender change
2014-11-12 09:18:36 +00:00
Richard Davey
b5ed3324b2 Merge pull request #1316 from pnstickne/wip-1306
ScaleManager - orientation updates/fixes
2014-11-12 09:17:47 +00:00
Paul
cf3bebd00c ScaleManager - orientation, minor 2014-11-11 23:02:43 -08:00
Paul
59dddece0b ScaleManager - orientation
- A few minor quibbles
2014-11-11 22:53:00 -08:00
Paul
e36027f599 ScaleManager - orientation
- Removed some "debug" logging, oops.

- And a dab of documentation updates while I'm at it..
2014-11-11 22:41:53 -08:00
Paul
0fd6a4a5b6 ScaleManager - orientation
- FIX #1306, hopefully, where an orientation change did not correclty
  cause a screen/layout update.

- FIX/CHANGE where Paused games would not update the scale
  - The new behavior "runs" the ScaleManager in a paused state via
    `pauseUpdate`; a User paused game will now correctly track scale
    changes. This is closer to the 2.1.3 behavior in some cases, such as
    window resizing, when the updates were done in the DOM event.
  - This change also affects device orientation change monitoring and
    events, which are also deferred to the update cycle
  - The update cycle is set to the maximum and is still dependent on the
    RAF / primary loop running, so it should not affect background
    apps/tabs

- FIX/CHANGE New better backoff timing; ie. continuous window resizing is
  limited to ~10 fps update calculations. This makes it much harder to
  crash Chrome by rapidly and continously resizing the window.  Also
  increases the scaling from 0..10..20..40 to 0..25..50..100.

- FIX an issue where the incorrect orientation was "one frame behind" the
  scaling.

- UPDATE The contract for when the change orientation events occurs is
  better defined - it now always happens in the update context as with
  game sizing.

- UPDATE Unifies orientation-change code / handling and duplicate.

- CHANGE Added DOM.getScreenOrientation which obtains the orientation via
  the Device Orientation API (WD) and provides comprehensive fallbacks
  - This should cover all modern browsers
  - FIX: Orientation on desktops now computed as screen ratio by default
    which fixesi the false-portrait chain/detection when the page is made
    more narrow than it is tall.
  - CHANGE/FIX: window.orientation is now only used as fallback, if
    requested (due to device differences). It may be appropriate to enable
    this (via `scale.compatibility` on boot, for instance) in some
    environments.

Signed-off-by: Paul <pstickne@gmail.com>
2014-11-11 22:30:07 -08:00
Pete Baron
1c5a106b17 Modify updateRender call to use desiredFps rate when spiralling is detected. 2014-11-12 15:01:09 +13:00
photonstorm
da031d8bbb Phaser games should now work again from the CocoonJS Launcher. 2014-11-11 14:31:20 +00:00
photonstorm
e63988fe6e Additional RESIZE handler. 2014-11-11 13:59:56 +00:00
photonstorm
bf70df2658 Game.forceSingleUpdate will force just a single logic update, regardless of the delta timer values. You can use this in extremely heavy CPU situations where you know you're about to flood the CPU but don't want Phaser to get stuck in a spiral. 2014-11-11 05:51:56 +00:00
Paul
50729b33a2 DOM Functions
No known breaking changes - as it's still dev/internal stuff.

- Added Phaser.DOM to house new DOM functions, moved stuff
  over from ScaleManager as appropriate

- Fixed a fiew cases of missing functions

- Changed some of the new signatures to protected for the interim.
  (Maybe a `beta` tag would fit better? Public is promises!)

- Moved generic support from Canvas to DOM and added proxy/notes
  - Updated internal usages

- Updated some comments for consistency
  - Access always on bottom for members/properties, public assumed
2014-11-10 00:45:13 -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
Paul
24c4cf2be3 Merge remote-tracking branch 'upstream/dev' into wip-scalemanager
Conflicts:
	src/core/ScaleManager.js
2014-11-08 19:29:47 -08:00
Paul
f5b9d4067e ScaleManager: additional cleanup
- Added `compatibility` settings
  - CHANGE (2.1.2-4): moved `supportsFullScreen` and `noMargins` into it
  - Added additional properties for greater control and up-front settings.
    - `scrollTo`: where the browser will scrollTo, if anywhere
    - `forceMinimumDocumentHeight`: apply document element style?
    - `allowShowAllExpand`: allow SHOW_ALL to try to expand? (It already
      could, this allows configuration.)

- Removed `windowConstraints.top/left`. This may be a feature in the
  future, but scrubbed for now.

- Added `USER_SCALE` scale mode. This is like NO_SCALE but it scales off
  of a user-specified scale factor, as set by `setUserScale`. This is
  marked as "experimental" as the exactly semantics of non-adjusting modes
  (e.g. NO_SCALE and USER_SCALE) wrt. Canvas and "maximum" size clamps
  need to be re-examined.

- FIX: `onSizeChange` now works as documented, which means it is also
  fired if the game size changes even though the game canvas size does
  not.

- CHANGE (no known breaking): `margins` is now non-Point/non-Rectangle
  that uses top/left/bottom/right properties (any quasi-updated x/y). This
  is to get around the issue that Rectangle is only designed for positive
  width/height cases.

- Cleaned up property access / quotes for consistency

- Various documentation cleanup and consistency

- Fixed issue with not clearing an unparented `_createdFullScreenTarget`

- Added Phaser.Rectangle.sameDimensions which does a strict equality check
  over the `width` and `height` properties of two objects, perhaps
  Rectangles.
2014-11-08 18:17:30 -08:00
photonstorm
0fc70db14c this._gameSize wasn't being populated other than via setSize, which broke games using dimensions set in the constructor that used FlexGrid for scaling. 2014-11-09 01:43:28 +00:00
photonstorm
0a86a7ef51 Time.now can no longer be relied upon to contain a timestamp value. If the browser supports requestAnimationFrame then Time.now will contain the high resolution timer value that rAf generates. Otherwise it will contain the value of Date.now. If you require the actual time value (in milliseconds) then please use Time.time instead. Note that all Phaser sub-systems that used to rely on Time.now have been updated, so if you have any code that extends these please be sure to check it. 2014-11-08 20:01:10 +00:00
photonstorm
88eae3aed0 Build files for testing. 2014-11-08 19:11:28 +00:00
photonstorm
a0cc4c3777 A large refactor to how the internal game timers and physics calculations has been made. We've now swapped to using a fixed time step internally across Phaser, instead of the variable one we had before that caused glitchse on low-fps systems. Thanks to pjbaron for his help with all of these related changes.
We have separated the logic and render updates to permit slow motion and time slicing effects. We've fixed time calling to fix physics problems caused by variable time updates (i.e. collisions sometimes missing, objects tunneling, etc)

Once per frame calling for rendering and tweening to keep things as smooth as possible

Calculates a `suggestedFps` value (in multiples of 5 fps) based on a 2 second average of actual elapsed time values in the `Time.update` method.  This is recalculated every 2 seconds so it could be used on a level-by-level basis if a game varies dramatically. I.e. if the fps rate consistently drops, you can adjust your game effects accordingly.

Game loop now tries to "catch up" frames if it is falling behind by iterating the logic update. This will help if the logic is occasionally causing things to run too slow, or if the renderer occasionally pushes the combined frame time over the FPS time. It's not a band-aid for a game that floods a low powered device however, so you still need to code accordingly. But it should help capture issues such as gc spikes or temporarily overloaded CPUs.

It now detects 'spiralling' which happens if a lot of frames are pushed out in succession meaning the CPU can never "catch up". It skips frames instead of trying to catch them up in this case. Note: the time value passed to the logic update functions is always constant regardless of these shenanigans.

Signals to the game program if there is a problem which might be fixed by lowering the desiredFps

Time.desiredFps is the new desired frame rate for your game.

Time.suggestedFps is the suggested frame rate for the game based on system load.

Time.slowMotion allows you to push the game into a slow motion mode. The default value is 1.0. 2.0 would be half speed, and so on.

Time.timeCap is no longer used and now deprecated. All timing is now handled by the fixed time-step code we've introduced.
2014-11-08 18:54:54 +00:00
photonstorm
a7710c504e jshint fixes. 2014-11-08 14:04:17 +00:00
photonstorm
17de8fdcae ScaleManager updates and fixes
Conflicts:
	src/core/ScaleManager.js
2014-11-08 13:38:19 +00:00
photonstorm
f9d899ba1b Tidying up FlexGrid. 2014-11-08 13:31:35 +00:00
photonstorm
2777c2a463 ScaleManager.elementBounds is a cross-browser element.getBoundingClientRect method with optional cushion.
ScaleManager.calibrate is a private method that calibrates element coordinates for viewport checks.
ScaleManager.aspect gets the viewport aspect ratio (or the aspect ratio of an object or element)
ScaleManager.inViewport tests if the given DOM element is within the viewport, with an optional cushion parameter that allows you to specify a distance.
ScaleManager.scaleSprite takes a Sprite or Image object and scales it to fit the given dimensions. Scaling happens proportionally without distortion to the sprites texture. The letterBox parameter controls if scaling will produce a letter-box effect or zoom the sprite until it fills the given values.
ScaleManager.viewportWidth returns the viewport width in pixels.
ScaleManager.viewportHeight returns the viewport height in pixels.
ScaleManager.documentWidth returns the document width in pixels.
ScaleManager.documentHeight returns the document height in pixels.
2014-11-08 13:31:35 +00:00
Paul
910627df8a ScaleManager: (passing jshint) 2014-11-08 05:29:12 -08:00
Paul
e075a735e3 ScaleManager: back-port of "window constraints".
- Adds `ScaleManager#windowContraints`
  - In 2.1.3 and prior the scale modes (EXACT_FIT, SHOW_ALL) were actually
    based off the window dimensions, even though the parent element did
    not correctly reflect this nature.
  - When set (the default now is that right and bottom are set) the
    behavior will mostly correctly mimic the 2.1.3 (minus bugs) and
    before.
  - CHANGE (from 2.1.3): The window constraints also affect the RESIZE
    mode, arguably this is more consistent.
  - To disable this "constrain to window" behavior, simply set the
    appropriate property to false, as in:
    `game.scale.windowConstraints.bottom = false`
2014-11-08 05:21:13 -08:00
Paul
223d444f16 ScaleManager: additional cleanup / fixes
- Sizing events:
  - CHANGE: The `onResize` callback is called only from `preUpdate` (which
    may be triggered from a window resize) and it will be called on
    refreshes even if the parent size has not actually changed.
  - A new `onSizeChange` Signal has been added. It is called _only_ when
    the Game size or Game canvas size has changed and is generally more
    applicable for performing layout updates.

- Game documentation now links to ScaleManager#setGameSize (which was
  renamed from #setGameDimensions)

- Removed extra/legacy full-screen restore code

- Margins:
  - Added `noMargins` flag; if set to true the Canvas margins will never
    be altered. This also means that
  - Margins are now set/cleared individually to avoid conflict with
    'margins' style compound property

- Code consistency updates
2014-11-08 04:35:42 -08:00
Paul
7de70adf42 ScaleManager: more updates, fixes (eg. SHOW_ALL)
- NOTE: Changing `game.width/game.height` via user code was always
  problematic. This commit updates the documentation for such members as
  read-only. The only supported way to change the GAME SIZE after it is
  created is to use `ScaleManager#setGameDimensions`, which has been
  added.

- The GAME SIZE will be reset to the initial (or as set by
  `setGameDimensions`) values upon changing the scale mode or
  entering/leaving full screen. This may be a breaking from 2.1.2 (but
  many mode changes acted oddly prior).

- SHOW_ALL will now EXPAND it's parent container if it can. As per
  @tjkopena 's notes, this should more closely represented the expected
  behavior.
  - SHOW_ALL will first try to expand by the OVERFLOW AXIS and then
    attempt to resize to fit into the possibly larger area; use the
    parent's max-height/max-width properties to limit how far SHOW_ALL can
    expand.
  - RE-BREAKING: This changes the behavior from 2.1.4 and makes it more like
    2.1.3, with fixes.

- As per previous commit the ScaleManager _owns_ the margins and size of
  the GAME CANVAS. To control the dimensions of the GAME CANVAS, use the min/max
  height/width of the parent. Setting padding on the parent is _NOT_
  supported.

- Fixes various issues with switching between Scale Modes
2014-11-07 23:24:57 -08:00
Paul
10d0f1943a ScaleManager - scaling consistency and bug-fixes
This includes some minor breaking changes.

- Unifies SHOW_ALL and NO_SCALE being stretched in Firefox and IE
  - As suggested by MDN: "..to emulate WebKit's behavior on Gecko, you
    need to place the element you want to present inside another
    element.."
  - This done via an (overwritable) `createFullScreenTarget` function.
    The (new) DOM element returned from this is placed into the DOM and
    the canvas is added to (and later removed) as the full screen mode
    changes.
  - MINOR BREAK: may affect code that assumes the Phaser canvas has a
    fixed DOM/CSS path (which should hopefully be nobody).  To use to the
    original behavior, where the canvas is not moved, simply set
    `this.fullScreenTarget = game.canvas` manually.

- Updates the refresh/queue to be unified and uses a smarter back-off to
  detect and react to parent dimension changes
  - Cleans up some odd browser issues; not tried on mobile
  - Fixes an issue were update might be called too much and spend time
    doing nothing useful.
  - `maxIterations` is no longer user and marked as deprecated
  - MINOR BREAK: previous approach would occasionally (but not always)
    back off updates the entire iteration/setTimeout sequence; under the
    new approach "onResize" may be called more frequently.

- Fixes a number various transition issues, mostly around RESIZE
  - MINOR BREAK, but correct: leaving RESIZE restores the original game
    size possible
  - Fixes assorted quirks with scales not being updated

- Layout
  - MINOR BREAK: All Canvas margins are "OWNED" by the ScaleManager. They
    will be reset in all modes as appropriate. This is for consistency
    fixes as well as coping with the updated full screen.
  - MINOR BREAK: Canvas right/bottom margins are set to negative margins
    to counter left/top margins. This prevents Canvas margin adjustments
    from affecting the flow .. much.
  - `getParentBounds` rounds to the nearest pixel to avoid "close to"
    value propagation from CSS.
  - Fixes page-align center pushing canvas out of parent

- Misc.
  - MINOR BREAK: `setScreenSize` will update the game size if the mode is
    RESIZE. User-code shoulde use `refresh` instead to ensure that any
    relevant changes are propagated.

- Corrected incorrect documentation
2014-11-07 16:06:33 -08:00
photonstorm
2469e45649 Rounding out new dimensions. 2014-11-04 23:57:21 +00:00
photonstorm
b6b478f214 Small jsdoc fixes. 2014-11-04 23:57:21 +00:00
spayton
5b6671a634 removed this.z =0, missed from last push 2014-11-03 20:24:56 +00:00
spayton
b51c162b4d Fixed new groups incorrectly always adding with a z index of 0 2014-11-03 18:19:41 +00:00
Richard Davey
fc0d423a7b Merge pull request #1278 from pnstickne/wip-1255
ScaleManager - bugfixes and updates for #1255
2014-11-02 14:01:23 +00:00
photonstorm
65618a7ec6 docs fix. 2014-11-02 12:08:54 +00:00
Paul
5b16bd45a5 ScaleManager - minor fullscreenerror fixes
- IE9 compatibility (no setWindow arguments)
- And removed code that assumpted event.target was the canvas..

(Actually adding the changes this time..)
2014-11-01 01:23:14 -07:00
Paul
d89c709020 ScaleManager - minor fullscreenerror fixes
- IE9 compatibility (no setWindow arguments)
- And removed code that assumpted event.target was the canvas..
2014-10-31 19:41:55 -07:00
Paul
9b319019e7 ScaleManager - backport for API compatibility
- "Backported" some changed API, all marked as @deprecated
- Minor regression fix for `supportsFullScreen`.
2014-10-31 18:06:36 -07:00
Paul
6e9f435245 ScaleManager - IE11 & Fullscreen error updates
- Added prefixed event handlers for IE; it still doesn't work in IE, but that is for other reasons
- Added monitoring of the fullscreenerror event, exposed as a fullScreenFailed signal
- Added `supportsFullScreen` a read-only flag that indicates that this ScaleManager even attempts to support such
2014-10-31 15:31:03 -07:00
Paul
6144b57651 ScaleManager - documentation updates 2014-10-31 03:29:54 -07:00
Paul
53541529e9 ScaleManager
- Specific bug fixes (example)
   - Scale modes can now be set independently
   - Switching between fullscreen and normal correctly restores modes
   - Alignment does not incorrectly offset in fullscreen mode
   - Changing scale/alignment promptly refreshes layout
   - `isFullScreen` returns a boolean, as it should
   - Faster parent checks (if required)
   - NO_SCALE should not not scale (vs previous behavior of having no behavior)
   - Correct usage of scaleMode depending on mode

 - Removed / unified code-paths, which helped address several issues
 - fullScreenTarget adjustment/restoration is less brutal
 - Updated documentation
 - pageAlign* works as alignment on the containing element. It should still work were it worked before (so this is not a breaking change) as well as being more universal.
 - Added @protected and @private attributes
   - Some methods were (implicitly) @public even though using them out of context is invalid

 - API Breaking:
   - Renamed some INTERNAL/@private methods
     - Should only affect methods that were not valid/sane to use publically
     - Event callbacks (ie. checkResize changed to resizeWindow) renamed for meaning
   - Changed some INTERNAL semantics to better align with usage
     - eg. `check*` methods separated from response-to-check
2014-10-31 01:41:06 -07:00
Paul
3cfe200ed1 Minor documentation cleanup 2014-10-28 06:12:48 -07:00
Paul
37a77c674f Add support for "rgba" to Phaser.Stage.backgroundColor
- backgroundColor now uses valueToColor which supports hex strings, web/rgba strings, and hex numbers.
 - valueToColor normalizes across hexToColor/webToColor/getRGB; see comments
 - hexToColor now documents the prefix being optional and allows the `0x` prefix.
 - webToColor now exctracts an alpha channel if present - as a slight misfeature it will also accept `rgb(..,a)`.
2014-10-28 05:45:00 -07:00
photonstorm
08a2b12d7d Tidied up the jsdocs. 2014-10-28 01:48:56 +00:00
photonstorm
9efa5efa0f Tidied up the Signal class and added a call counter to SignalBinding. 2014-10-28 01:48:24 +00:00
photonstorm
a471cfc235 Game.destroy now destroys either the WebGLRenderer or CanvasRenderer, whichever Pixi was using. 2014-10-27 22:09:39 +00:00
photonstorm
474fd8e055 JSDoc fixes. 2014-10-21 23:08:16 +01:00
Alvin
7f31cfba62 fixed type in the cached previous point in mouse uniform (filter) 2014-10-20 14:39:16 +02:00
photonstorm
35d29170d0 Lots of small jsdoc fixes and DocGen updates. 2014-10-20 00:54:56 +01:00
photonstorm
d70406588c Filter.update now caches the previous pointer position to avoid flooding the uniform. Also the mouse uniform is now a value between 0 and 1 depending on the position within the game view. 2014-10-17 19:29:50 +01:00