Phaser API Documentation

  Version: 

Member of: Phaser.Structs.Size

setSnap([snapWidth], [snapHeight])

Description:

By setting a Snap To value when this Size component is modified its dimensions will automatically by snapped to the nearest grid slice, using floor. For example, if you have snap value of 16, and the width changes to 68, then it will snap down to 64 (the closest multiple of 16 when floored)

Note that snapping takes place before adjustments by the parent, or the min / max settings. If these values are not multiples of the given snap values, then this can result in un-snapped dimensions.

Call this method with no arguments to reset the snap values.

Calling this method automatically recalculates the width and the height, if required.

Parameters:

name type arguments Default description
snapWidth number <optional> 0

The amount to snap the width to. If you don't want to snap the width, pass a value of zero.

snapHeight number <optional> snapWidth

The amount to snap the height to. If not provided it will use the snapWidth value. If you don't want to snap the height, pass a value of zero.

Returns:
Description:

This Size component instance.

Examples:
Since: 3.16.0
Source: src/structs/Size.js (Line 187)