Commit graph

51 commits

Author SHA1 Message Date
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
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
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
b6b478f214 Small jsdoc fixes. 2014-11-04 23:57:21 +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
photonstorm
0c5438038d Allowed the orientation checks to still work when using RESIZE scale mode. 2014-10-10 20:35:50 +01:00
photonstorm
a1c9b64327 Now bails out of a few methods if RESIZE is set. 2014-09-09 12:48:21 +01:00
photonstorm
0af4ec4da2 The StateManager will now check if a State has a method called resize. If it does, and if the game is running in the RESIZE Scale Mode then this method will be called whenever the game resizes. It will be passed two parameters: width and height that will match the games new dimensions. Resizing can happen as a result of either the parent container changing shape, or the browser window resizing. 2014-09-05 06:22:10 +01:00
photonstorm
0c9eef8a91 FlexGrid added to the ScaleManager. 2014-09-05 06:02:25 +01:00
photonstorm
ac9c9a1f9b Fixed the assignment of the fullScreenTarget so FS mode works again now. 2014-09-05 01:07:51 +01:00
photonstorm
2cc8e57808 Fixed issue with the ScaleManager. 2014-09-01 08:19:43 +01:00
photonstorm
7fc37751b2 ScaleManager.orientationSprite has been removed because it never displayed correctly anyway (it would be distorted by the game scale), it will be bought back in a future version by way of a custom orientation state. 2014-09-01 03:30:02 +01:00
photonstorm
047839d806 Fixed preUpdate so that the offset is reset regardless of the RESIZE scaleMode. 2014-09-01 03:20:09 +01:00
photonstorm
80d1df4705 ScaleManager.setMinMax(minWidth, minHeight, maxWidth, maxHeight) is a handy function to allow you to set all the min/max dimensions in one call. 2014-09-01 03:07:17 +01:00
photonstorm
c6493b59c3 Removed use of _startHeight, left over from the Phaser v1 days that's no longer required. 2014-09-01 02:44:35 +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
004deff508 Note: This commit will break all input, don't pull it down until I finish this work off later today please!
Moved the DOM offset from Stage to ScaleManager (a more logical location for it) and updated Pointer to use that.
Moved the Pointer offset check to look at the ScaleManager.
Used getBoundingClientRect(), will see if that works better than Phaser.Canvas.getOffset.
2014-08-31 12:17:07 +01:00
photonstorm
8c7a699f74 Getting ready to test auto resizing renderer. 2014-08-31 11:09:27 +01:00
photonstorm
4d0cae0e2d jshint fixes for CocoonJS.App and continuing work on the new ScaleManager. 2014-08-31 10:17:02 +01:00
photonstorm
3e1eb10673 First pass at fully resizable canvas tracking and parenting. 2014-08-31 10:17:02 +01:00
Richard Davey
ffb413b741 Fixed issue with callbacks not having the correct context. 2014-08-28 21:54:30 +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
Johan Rosén
ba62326ce7 OritentationSprite fix, not using PIXI.TextureCache anymore 2014-07-16 17:07:53 +02:00
photonstorm
d2fc42520b stopFullScreen has been changed to run against document instead of the canvas since the cancelFullScreen method is created on the document (thanks @j0hnskot, #863) 2014-07-01 15:46:32 +01:00
photonstorm
0c675f741f Wrapped all events that CocoonJS doesn't support in conditional checks to avoid Cocoon Warnings. 2014-05-29 22:25:40 +01:00
photonstorm
7b876d5fc4 ScaleManager.bounds is a Rectangle object that holds the exact size of the game canvas, taking DOM offset and game scale into account.
Pointer.withinGame is now accurate based on game scale and updated as the Pointer moves.
Stage.bounds is now updated if the game canvas offset changes position. Note that it gives the un-scaled game dimensions.
2014-05-19 18:49:59 +01:00
photonstorm
fa613c5fe1 ScaleManager seeds _check private var with null to avoid later comparison check (thanks @jflowers45, fix #782)
P2.Body.applyForce should have used pxmi instead of pxm (thanks @Trufi, fix #776)
P2 fixed creation of RevoluteConstraint by passing maxForce in the options (thanks @woutercommandeur, fix #783)
2014-04-29 19:34:38 +01:00
photonstorm
6e0c182fa5 Added _startHeight mod, but disabled until further testing. 2014-04-27 10:17:37 +01:00
Christian Wesselhoeft
debb6bdcf9 Fix jshint issues in src/core 2014-03-25 14:56:05 -07:00
Christian Wesselhoeft
61f18b675c Trim trailing whitespace. 2014-03-25 14:56:04 -07:00
photonstorm
85d5fdfb2f Sorted out orientationImage in ScaleManager, throwing a preUpdate error (fix #534)
Tightened up the currentFrame allocation in AnimationManager.
2014-03-10 19:06:16 +00:00
photonstorm
45ab4673cc ScaleManager.fullScreenTarget allows you to change the DOM element that the fullscreen API is called on (feature request #526) 2014-03-10 01:13:01 +00:00
photonstorm
e3d53ad6a3 Game no longer pauses if you've forced orientation and change it, also doesn't resize a NO_SCALE game.
If the game was set to NO_SCALE and you swapped orientation, it would pause and resize, then fail to resize when you swapped back (thanks starnut, fixes #258)
2014-02-28 04:15:28 +00:00
photonstorm
db2e3733c2 Fullscreen mode now uses window.outerWidth/Height when using EXACT_FIT as the scale mode, which fixes input coordinate errors (fixes #232)
Fullscreen mode now works in Internet Explorer and uses the new fullscreen non-prefix call.
2014-02-25 21:16:56 +00:00
photonstorm
741249043c ScaleManager has 2 new events: ScaleManager.enterFullScreen and ScaleManager.leaveFullScreen, so you can respond to fullscreen changes directly.
Fullscreen mode now uses window.outerWidth/Height when using EXACT_FIT as the scale mode, which fixes input coordinate errors (fixes #232)
2014-02-25 17:10:37 +00:00