Layout

Set some important variables for other classes to use, based on the size and orientation of the viewport

Author
  • Mark Mayes / mm-dev
License
  • GPL-3.0-only
Source

Methods

(static) getAlignedPos(_alignmentH, _alignmentV, _itemWidth, _itemHeight, _offsetHopt, _offsetVopt) → {object}

Source
Based on a desired alignment and size of an item, calculate its coordinates
Parameters
Name Type Attributes Description
_alignmentH HORIZ_ALIGN

Horizontal alignment

_alignmentV VERT_ALIGN

Vertical alignment

_itemWidth number

The height of the item

_itemHeight number

The width of the item

_offsetH number optional

A horizontal offset to be applied after the basic calculation

_offsetV number optional

A vertical offset to be applied after the basic calculation

Returns
  object

x/y coordinates for the item

(static) getRectangle(_type) → {object}

Source
Based on current layout/dimensions, get a rectangle describing the position and size of a specific object (eg gameplay area, title image, sound icon)
Parameters
Name Type Description
_type RECTANGLE

Which rectangle do we want?

Returns
  object

A rectangle with top, right, bottom, left properties

(static) init()

Source
Simple initialisation

This just calls the update function with a default gameplay area size so that the caclulations have something to work with

(static) setProportionalSizes()

Source
Calculate some values which are used heavily throughout the app
  • Layout.proportionalMultiplier - Used to shrink/grow things in relation to an ideal (GAME.SCALING_TARGET_SIZE), to try to make things feel consistent between highly variable screen sizes
  • Layout.mainPaddingProportional - Common padding used eg between text/icons and the edge of the screen
  • Layout.textBgPaddingProportional - Extra spacing around text and the borders of its background
  • Layout.hitAreaPaddingProportional - Invisible spacing around tappable items (eg icons) to make them easier to hit

(static) update(_data)

Source
Calculate sizes (particularly recctangles) for lots of important parts of the game and UI
Parameters
Name Type Description
_data object
Name Type Description
gameplayAreaToCanvasLateralRatio number

This value is set per-level and sets the size of the gameplay area (between the pipe walls) as a ratio of the canvas size