Phaser API Documentation

  Version: 

Member of: Phaser.Math

<static> ToXY(index, width, height, [out])

Description:

Returns a Vector2 containing the x and y position of the given index in a width x height sized grid.

For example, in a 6 x 4 grid, index 16 would equal x: 4 y: 2.

If the given index is out of range an empty Vector2 is returned.

Parameters:

name type arguments description
index number

The position within the grid to get the x/y value for.

width number

The width of the grid.

height number

The height of the grid.

out Phaser.Math.Vector2 <optional>

An optional Vector2 to store the result in. If not given, a new Vector2 instance will be created.

Returns:
Description:

A Vector2 where the x and y properties contain the given grid index.

Since: 3.19.0
Source: src/math/ToXY.js (Line 9)