Class: ScaleManager

Phaser. ScaleManager

Phaser.ScaleManager

new ScaleManager(game, width, height)

The ScaleManager object is responsible for helping you manage the scaling, resizing and alignment of your game within the browser.

Parameters:
Name Type Description
game Phaser.Game

A reference to the currently running game.

width number | string

The width of the game.

height number | string

The height of the game.

Source:

Members

<static, constant> EXACT_FIT :number

Type:
  • number
Source:

<static, constant> NO_SCALE :number

Type:
  • number
Source:

<static, constant> RESIZE :number

Type:
  • number
Source:

<static, constant> SHOW_ALL :number

Type:
  • number
Source:

<readonly> aspectRatio

Properties:
Name Type Description
aspectRatio number

The aspect ratio of the scaled game.

Source:

<readonly> bounds

Properties:
Name Type Description
bounds Phaser.Rectangle

The bounds of the scaled game. The x/y will match the offset of the canvas element and the width/height the scaled width and height.

Source:

enterFullScreen

Properties:
Name Type Description
enterFullScreen Phaser.Signal

The event that is dispatched when the browser enters full screen mode (if it supports the FullScreen API).

Source:

enterIncorrectOrientation

Properties:
Name Type Description
enterIncorrectOrientation Phaser.Signal

The event that is dispatched when the browser enters an incorrect orientation, as defined by forceOrientation.

Source:

enterLandscape

Properties:
Name Type Description
enterLandscape Phaser.Signal

The event that is dispatched when the browser enters landscape orientation having been in portrait.

Source:

enterPortrait

Properties:
Name Type Description
enterPortrait Phaser.Signal

The event that is dispatched when the browser enters portrait orientation having been in landscape.

Source:

event

Properties:
Name Type Description
event- any

The native browser events from full screen API changes.

Source:

forceLandscape

Properties:
Name Type Description
forceLandscape boolean

Set to true if the game should only run in a landscape orientation.

Default Value:
  • false
Source:

forcePortrait

Properties:
Name Type Description
forcePortrait boolean

Set to true if the game should only run in a portrait orientation.

Default Value:
  • false
Source:

fullScreenTarget

This is the DOM element that will have the Full Screen mode called on it. It defaults to the game canvas, but can be retargetted to any valid DOM element. If you adjust this property it's up to you to see it has the correct CSS applied, and that you have contained the game canvas correctly. Note that if you use a scale property of EXACT_FIT then fullScreenTarget will have its width and height style set to 100%.

Properties:
Name Type Description
fullScreenTarget any
Source:

game

Properties:
Name Type Description
game Phaser.Game

A reference to the currently running game.

Source:

grid

Properties:
Name Type Description
grid Phaser.FlexGrid

EXPERIMENTAL: A responsive grid on which you can align game objects.

Source:

height

Properties:
Name Type Description
height number

Height of the game after calculation.

Source:

incorrectOrientation

Properties:
Name Type Description
incorrectOrientation boolean

If forceLandscape or forcePortrait are true and the browser doesn't match that orientation this is set to true.

Default Value:
  • false
Source:

<readonly> isFullScreen

Properties:
Name Type Description
isFullScreen boolean

Returns true if the browser is in full screen mode, otherwise false.

Source:

<readonly> isLandscape

Properties:
Name Type Description
isLandscape boolean

Returns true if the browser dimensions match a landscape display.

Source:

<readonly> isPortrait

Properties:
Name Type Description
isPortrait boolean

Returns true if the browser dimensions match a portrait display.

Source:

leaveFullScreen

Properties:
Name Type Description
leaveFullScreen Phaser.Signal

The event that is dispatched when the browser leaves full screen mode (if it supports the FullScreen API).

Source:

leaveIncorrectOrientation

Properties:
Name Type Description
leaveIncorrectOrientation Phaser.Signal

The event that is dispatched when the browser leaves an incorrect orientation, as defined by forceOrientation.

Source:

<readonly> margin

Properties:
Name Type Description
margin Phaser.Point

If the game canvas is set to align by adjusting the margin, the margin calculation values are stored in this Point.

Source:

maxHeight

Properties:
Name Type Description
maxHeight number

Maximum height the canvas should be scaled to (in pixels). If null it will scale to whatever height the browser can handle.

Source:

maxIterations

Properties:
Name Type Description
maxIterations number

The maximum number of times it will try to resize the canvas to fill the browser.

Default Value:
  • 5
Source:

maxWidth

Properties:
Name Type Description
maxWidth number

Maximum width the canvas should be scaled to (in pixels). If null it will scale to whatever width the browser can handle.

Source:

minHeight

Properties:
Name Type Description
minHeight number

Minimum height the canvas should be scaled to (in pixels).

Source:

minWidth

Properties:
Name Type Description
minWidth number

Minimum width the canvas should be scaled to (in pixels).

Source:

offset

Properties:
Name Type Description
offset Phaser.Point

Holds the offset coordinates of the Game.canvas from the top-left of the browser window (used by Input and other classes)

Source:

onResize

Properties:
Name Type Description
onResize function

The callback that will be called each time a window.resize event happens or if set, the parent container resizes.

Default Value:
  • null
Source:

onResizeContext

Properties:
Name Type Description
onResizeContext object

The context in which the callback will be called.

Default Value:
  • null
Source:

orientation

Properties:
Name Type Description
orientation number

The orientation value of the game (as defined by window.orientation if set). 90 = landscape. 0 = portrait.

Source:

pageAlignHorizontally

Properties:
Name Type Description
pageAlignHorizontally boolean

If you wish to align your game in the middle of the page then you can set this value to true. It will place a re-calculated margin-left pixel value onto the canvas element which is updated on orientation/resizing events. It doesn't care about any other DOM element that may be on the page, it literally just sets the margin.

Default Value:
  • false
Source:

pageAlignVertically

Properties:
Name Type Description
pageAlignVertically boolean

If you wish to align your game in the middle of the page then you can set this value to true. It will place a re-calculated margin-left pixel value onto the canvas element which is updated on orientation/resizing events. It doesn't care about any other DOM element that may be on the page, it literally just sets the margin.

Default Value:
  • false
Source:

<readonly> parentIsWindow

Properties:
Name Type Description
parentIsWindow boolean

If the parent container of the game is the browser window, rather than a div, this is set to true.

Source:

<readonly> parentNode

Properties:
Name Type Description
parentNode object

The fully parsed parent container of the game. If the parent is the browser window this will be null.

Source:

<readonly> parentScaleFactor

Properties:
Name Type Description
parentScaleFactor Phaser.Point

The scale of the game in relation to its parent container.

Source:

<readonly> scaleFactor

Properties:
Name Type Description
scaleFactor Phaser.Point

The scale factor based on the game dimensions vs. the scaled dimensions.

Source:

<readonly> scaleFactorInversed

Properties:
Name Type Description
scaleFactorInversed Phaser.Point

The inversed scale factor. The displayed dimensions divided by the game dimensions.

Source:

scaleMode

Properties:
Name Type Description
scaleMode number

The scaling method used by the ScaleManager.

Source:

<readonly> sourceAspectRatio

Properties:
Name Type Description
sourceAspectRatio number

The aspect ratio (width / height) of the original game dimensions.

Source:

trackParentInterval

Properties:
Name Type Description
trackParentInterval number

The interval (in ms) upon which the ScaleManager checks if the parent has changed dimensions. Only applies if scaleMode = RESIZE and the game is contained within another html element.

Default Value:
  • 2000
Source:

width

Properties:
Name Type Description
width number

Width of the game after calculation.

Source:

Methods

boot()

Calculates and sets the game dimensions based on the given width and height.

Source:

checkOrientation(event)

window.orientationchange event handler.

Parameters:
Name Type Description
event Event

The orientationchange event data.

Source:

checkOrientationState()

Checks if the browser is in the correct orientation for your game (if forceLandscape or forcePortrait have been set)

Source:

checkResize(event)

window.resize event handler.

Parameters:
Name Type Description
event Event

The resize event data.

Source:

forceOrientation(forceLandscape, forcePortrait)

If you need your game to run in only one orientation you can force that to happen.

Parameters:
Name Type Argument Default Description
forceLandscape boolean

true if the game should run in landscape mode only.

forcePortrait boolean <optional>
false

true if the game should run in portrait mode only.

Source:

<protected> fullScreenChange(event)

Called automatically when the browser enters of leaves full screen mode.

Parameters:
Name Type Description
event Event

The fullscreenchange event

Source:

parseConfig(config)

Parses the Game configuration object.

Parameters:
Name Type Description
config object

The game configuration object.

Source:

<protected> preUpdate()

The ScaleManager.preUpdate is called automatically by the core Game loop.

Source:

refresh()

Re-calculate scale mode and update screen size. This only applies if ScaleMode is not set to RESIZE.

Source:

setExactFit()

Sets the width and height values of the canvas, no larger than the maxWidth/Height.

Source:

setMaximum()

Sets this.width equal to window.innerWidth and this.height equal to window.innerHeight.

Source:

setResizeCallback(callback, context)

Sets the callback that will be called when the window resize event occurs, or if set the parent container changes dimensions. Use this to handle responsive game layout options. Note that the callback will only be called if the ScaleManager.scaleMode is set to RESIZE.

Parameters:
Name Type Description
callback function

The callback that will be called each time a window.resize event happens or if set, the parent container resizes.

context object

The context in which the callback will be called.

Source:

setScreenSize(force)

Set screen size automatically based on the scaleMode. This is only needed if ScaleMode is not set to RESIZE.

Parameters:
Name Type Description
force boolean

If force is true it will try to resize the game regardless of the document dimensions.

Source:

setShowAll()

Calculates the multiplier needed to scale the game proportionally.

Source:

setSize()

Sets the canvas style width and height values based on minWidth/Height and maxWidth/Height.

Source:

setupScale(width, height)

Calculates and sets the game dimensions based on the given width and height.

Parameters:
Name Type Description
width number | string

The width of the game.

height number | string

The height of the game.

Source:

startFullScreen(antialias)

Tries to enter the browser into full screen mode. Please note that this needs to be supported by the web browser and isn't the same thing as setting your game to fill the browser.

Parameters:
Name Type Description
antialias boolean

You can toggle the anti-alias feature of the canvas before jumping in to full screen (false = retain pixel art, true = smooth art)

Source:

stopFullScreen()

Stops full screen mode if the browser is in it.

Source:
Phaser Copyright © 2012-2014 Photon Storm Ltd.
Documentation generated by JSDoc 3.3.0-dev on Wed Oct 22 2014 21:46:05 GMT+0100 (BST) using the DocStrap template.