Skip to main content
Version: Phaser v4.0.0

Phaser.Math.Snap

Scope: static

Source: src/math/snap/index.js#L7

Static functions

Ceil

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

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:

nametypeoptionaldefaultdescription
valuenumberNoThe value to snap.
gapnumberNoThe interval gap of the grid.
startnumberYes0Optional starting offset for gap.
dividebooleanYesfalseIf true it will divide the snapped value by the gap before returning.

Returns: number - The snapped value.

Source: src/math/snap/SnapCeil.js#L7
Since: 3.0.0


Floor

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

Description:

Snap a value to the nearest lower 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:

nametypeoptionaldefaultdescription
valuenumberNoThe value to snap.
gapnumberNoThe interval gap of the grid.
startnumberYes0Optional starting offset for gap.
dividebooleanYesfalseIf true it will divide the snapped value by the gap before returning.

Returns: number - The snapped value.

Source: src/math/snap/SnapFloor.js#L7
Since: 3.0.0


To

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

Description:

Snaps a value to the nearest grid slice, using rounding. Values that fall exactly halfway between two slices will snap to the higher slice.

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:

nametypeoptionaldefaultdescription
valuenumberNoThe value to snap.
gapnumberNoThe interval gap of the grid.
startnumberYes0Optional starting offset for the grid, allowing grid alignment to begin at a value other than zero.
dividebooleanYesfalseIf true it will divide the snapped value by the gap before returning.

Returns: number - The snapped value.

Source: src/math/snap/SnapTo.js#L7
Since: 3.0.0