Commit graph

149 commits

Author SHA1 Message Date
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
photonstorm
a70a938505 docs fix 2014-07-09 05:38:59 +01:00
photonstorm
7c624f409f Updated console.log and README. 2014-07-03 10:50:26 +01:00
photonstorm
8c41f6cc10 Game.onBlur and Game.onFocus events are now dispatched regardless if Stage.disableVisibilityChange is true or false, so you can respond to these events without your game automatically pausing or resuming (#911) 2014-07-02 14:57:28 +01:00
photonstorm
58fc73348c The StateManager has a preRenderCallback option, which checks for a preRender function existing on the State, but it was never called. Have decided to add this in, so the core Game loop now calls state.preRender right before the renderer runs (thanks @AnderbergE #869) 2014-07-02 05:32:40 +01:00
photonstorm
db22b019be Swapped the ScaleManager creation order in Game, so both start and stop fullScreen requests work now. 2014-07-01 16:50:33 +01:00
photonstorm
ee5f6457c8 Swapped to using escaped Unicode characters for the console output. 2014-06-09 16:15:41 +01:00
photonstorm
b63900f669 Testing frame crop support. 2014-06-05 02:33:29 +01:00
photonstorm
1e9d0b2438 Tidying up. 2014-05-30 05:33:30 +01:00
photonstorm
6e8694d5f7 A Canvas style set from a game config object used an incorrect property (thanks @TatumCreative, fix #861) 2014-05-30 02:01:33 +01:00
photonstorm
edc1507b4e Resolved issue where Cocoon won't render a scene in Canvas mode if there is only one Sprite/Image on it. 2014-05-29 23:52:13 +01:00
photonstorm
eee1183a6a Forces use of a Canvas Renderer under CocoonJS automatically.
The SoundManager no longer requires a touch to unlock it, defaults to unlocked.
2014-05-29 23:17:18 +01:00
photonstorm
937085afda Added Uint32Array polyfill for BitmapData manipulation, and optional dataview polyfill for IE9 P2 requirements in the resources folder. 2014-04-29 02:09:58 +01:00
photonstorm
a5cbd8f2a6 Fixed an issue where Sounds that had been paused via game code would un-mute if the game paused and resumed. 2014-04-28 20:30:47 +01:00
photonstorm
1d48b3c5f2 Your State can now have a pauseUpdate method, which is called constantly when the game is paused.
The Input system is now updated even while the game is paused.
2014-04-28 00:07:40 +01:00
photonstorm
bcd64fd44b More Timer tests. 2014-04-26 16:16:18 +01:00
photonstorm
0f1e0a3d4e Updated the Device little / big endianess check. 2014-04-23 23:35:36 +01:00
photonstorm
b6cc150a15 Game.scratch is a single handy BitmapData instance that can be used as a visual scratch-pad, for off-screen bitmap manipulation (and is used as such by BitmapData itself).
Updated TS defs.
2014-04-23 22:14:47 +01:00
photonstorm
4ec5665148 Fixed #750 - Invalid typescript mapping for TileSprite.autoScroll function in TS defs.
Game checks if window.console exists before using it (should fix IE9 issues when dev tools are closed), however it is still used deeper in Pixi.
Body.loadData flagged as deprecated.
2014-04-22 23:31:07 +01:00
photonstorm
be52515ed4 PluginManager parent parameter removed as it's redundant. Also most core functions tidied up and jsdocs fixed. 2014-04-09 16:12:25 +01:00
photonstorm
01eec6cef5 Keyboard.stop nulls the function references after removing the event listeners (thanks @bmceldowney, #691) 2014-04-07 12:29:26 +01:00
photonstorm
bf32590cfe Fixed a few jsdoc errors. 2014-04-07 12:29:26 +01:00
photonstorm
f4dc686028 New build files for testing. 2014-04-01 16:13:00 +01:00
Ralph Smith
7e9fbd3c27 issue#661 update state before values are cleared
this prevent loosing state values related to physics bodys
and inputs before `state.update` is called.
2014-03-28 09:12:32 -05:00
Christian Wesselhoeft
debb6bdcf9 Fix jshint issues in src/core 2014-03-25 14:56:05 -07:00
photonstorm
111164e221 If no seed was given in the Game config object, the RandomDataGenerator wouldn't be started (thank tylerjhutchison fix #619) 2014-03-21 11:22:56 +00:00