Commit graph

174 commits

Author SHA1 Message Date
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
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
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
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
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
Paul
8b1c7625d4 Documentation - typo fix 2014-11-30 04:05:23 -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
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
874f60c1bc Removed CocoonJS hack - woohoo! 2014-11-21 10:40:18 +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
4220382376 Evolving the Tween engine. TweenMax string syntax now supported. 2014-11-20 05:26:49 +00:00
photonstorm
1d2b36fa1b Camera.preUpdate. 2014-11-18 12:36:25 +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
photonstorm
e7356fc575 Pixi 2.1.1 merge. 2014-11-12 22:38:51 +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
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
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
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
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
photonstorm
a471cfc235 Game.destroy now destroys either the WebGLRenderer or CanvasRenderer, whichever Pixi was using. 2014-10-27 22:09:39 +00:00
photonstorm
3f43637782 Happily removed the IE11 WebGL lock as Pixi now fully supports it :) 2014-10-14 01:10:17 +01:00
photonstorm
ac27f12c95 Fixes for Pixi update WebGL UV calls. 2014-10-11 04:18:42 +01:00
photonstorm
20551f9129 Lots of jsdocs fixes ready for the new doc generator. 2014-09-16 17:35:08 +01:00
photonstorm
79d873f47b If you are using CocoonJS, please set your game render type to CANVAS and not WEBGL or AUTO. You should also disable any of the ScaleManager screen resizing or margin setting code. By default in this mode CocoonJS will now set 'screencanvas=true' which helps with performance significantly. 2014-09-08 22:34:53 +01:00
photonstorm
cbc6ac8e7d New debug header. 2014-09-04 05:05:05 +01:00
photonstorm
2cc8e57808 Fixed issue with the ScaleManager. 2014-09-01 08:19:43 +01:00
photonstorm
1a60d641b1 Canvas.removeFromDOM(canvas) will remove a canvas element from the DOM.
Game.destroy now removes the games canvas element from the DOM.
2014-09-01 02:38:21 +01:00
photonstorm
97d771c4e8 ScaleManager has a new scaleMode called RESIZE which will tell Phaser to track the size of the parent container (either a dom element or the browser window if none given) and set the canvas size to match it. If the parent changes size the canvas will resize as well, keeping a 1:1 pixel ratio. There is also a new ScaleManager.setResizeCallback method which will let you define your own function to handle resize events from the game, such as re-positioning sprites for a fluid responsive layout (#642)
The width and height given to the Phaser.Game constructor can now be numbers or strings in which case the value is treated as a percentage. For example a value of "100%" for the width and height will tell Phaser to size the game to match the parent container dimensions exactly (or the browser window if no parent is given). Equally a size of "50%" would tell it to be half the size of the parent. The values are retained even through resize events, allowing it to maintain a percentage size based on the parent even as it updates.
2014-09-01 01:52:04 +01:00
photonstorm
5fb8c7eb85 ScaleManager window.resize handler would constantly dispatch enterPortrait and enterLandscape events on window resizing, regardless if it actually entered that orientation or not.
Stage.offset has been moved to ScaleManager.offset
Stage.bounds has been removed, you can access it via Stage.getBounds.
Stage.checkOffsetInterval has been moved to ScaleManager.trackParentInterval
ScaleManager.hasResized signal has been removed. Use ScaleManager.setResizeCallback instead.
2014-09-01 01:02:48 +01:00
photonstorm
3e1eb10673 First pass at fully resizable canvas tracking and parenting. 2014-08-31 10:17:02 +01:00
photonstorm
26a55bd202 SoundManager.destroy is a new method that will destroy all current sounds and reset any callbacks.
StateManager.clearCurrentState now handles the process of clearing down the current state and is now called if the Game is destroyed.
Game.destroy now clears the current state, activating its shutdown callback if it had one. It also now destroys the SoundManager, stopping any currently running sounds (#1092)
2014-08-29 11:37:47 +01:00
photonstorm
0c88ba041a If you used a single Game configuration object and didn't specify the enableDebug property it would crash on Debug.preUpdate (thanks @luizbills #1053) 2014-08-28 04:19:10 +01:00
photonstorm
6e2cd37776 ScaleManager.destroy now removes the window and document event listeners, which are no longer created anonymously (thanks @eguneys #1092)
Input.Gamepad.destroy now destroys all connected SinglePads and clears event listeners.
SinglePad.destroy now clears all associated GamepadButton objects and signals.
2014-08-28 03:31:47 +01:00
Federico Omoto
14028cafbc Game configuration object "renderer" property wrongly assigned to Game.renderer 2014-08-21 17:57:07 -03:00
Dan Cox
fbd2de5b23 Cordova 'deviceready' event check
A slightly obnoxious but necessary hack to prevent a race condition between the loading of Apache Cordova and Phaser itself. 

Without waiting for the 'deviceready' event, Phaser can often load first, preventing any console messages from appearing to the user. Because Cordova writes to the platform's console (via CordovaLog), it must first be loaded and signal its own 'deviceready' event before console or plugin usage can occur. Otherwise, all messages and functionality is ignored.
2014-08-21 00:11:41 -04:00
Txus Ordorika
b952884d9d Fix for scale issues in CocoonJS using webgl renderer and screencanvas 2014-07-23 17:16:25 +02:00
devinb83
4a632ed3a0 codePaused should be set if manually called
If pause is called manually, codePaused should be set regardless of whether the game is currently paused or not. This would fix issues where a developer might not want the game to automatically resume when the screen regains focus.
2014-07-14 12:57:37 -07:00
photonstorm
74679922d1 Debug.preUpdate was still being called in the Game Loop even if enableDebug was set to false (thanks @qdrj, #995) 2014-07-11 11:52:48 +01:00
photonstorm
d11d8051b1 You can now prevent the Debug class from being created or booted by using the Game configuration setting: enableDebug. By default it is true, set to false to prevent the class from being created. Please note you are responsible for checking if this class exists before calling it, but you can do that via if (game.debug) { ... } (request #984) 2014-07-10 10:46:18 +01:00
photonstorm
a182598c65 Using a Game configuration object you can now specify the value of the preserveDrawingBuffer flag for the WebGL renderer. By default this is disabled for performance reasons. But if you need to be able to take screen shots of your WebGL games using toDataUrl on the game canvas then you'll need to set this to true (#987) 2014-07-10 10:46:18 +01:00