Phaser API Documentation

  Version: 
Filter
Namespace: Snap
Phaser.Math.Snap
Source: src/math/snap/index.js (Line 7)

Methods

<static> Ceil(value, gap, [start], [divide])
Focus
Focus

Description:

Snap a value to nearest grid slice, using ceil.

Example: if you have an interval gap of 5 and a position of 12... you will snap to 15. As will 14 snap to 15... but 16 will snap to 20.

Parameters:

name type arguments Default description
value number

The value to snap.

gap number

The interval gap of the grid.

start number <optional> 0

Optional starting offset for gap.

divide boolean <optional> false

If true it will divide the snapped value by the gap before returning.

Returns:
Description:

The snapped value.

Type:
  • number
Since: 3.0.0
Source: src/math/snap/SnapCeil.js (Line 7)
Focus
Focus
<static> Floor(value, gap, [start], [divide])
Focus
Focus

Description:

Snap a value to nearest grid slice, using floor.

Example: if you have an interval gap of 5 and a position of 12... you will snap to 10. As will 14 snap to 10... but 16 will snap to 15.

Parameters:

name type arguments Default description
value number

The value to snap.

gap number

The interval gap of the grid.

start number <optional> 0

Optional starting offset for gap.

divide boolean <optional> false

If true it will divide the snapped value by the gap before returning.

Returns:
Description:

The snapped value.

Type:
  • number
Since: 3.0.0
Source: src/math/snap/SnapFloor.js (Line 7)
Focus
Focus
<static> To(value, gap, [start], [divide])
Focus
Focus

Description:

Snap a value to nearest grid slice, using rounding.

Example: if you have an interval gap of 5 and a position of 12... you will snap to 10 whereas 14 will snap to 15.

Parameters:

name type arguments Default description
value number

The value to snap.

gap number

The interval gap of the grid.

start number <optional> 0

Optional starting offset for gap.

divide boolean <optional> false

If true it will divide the snapped value by the gap before returning.

Returns:
Description:

The snapped value.

Type:
  • number
Since: 3.0.0
Source: src/math/snap/SnapTo.js (Line 7)
Focus
Focus