npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@phaserquick/grid

v1.0.11

Published

<h1>Grid</h1>

Readme

Phaserquick Grid

A utility class for organizing objects within a Phaser scene into a grid layout. The grid allows you to arrange elements with customizable row and column configurations, as well as optional aspect ratio handling and debugging capabilities.

1. Usage

1.1. Installation

Install the package via npm.

npm install @phaserquick/grid

1.2. Example Usage

1.2.1. Basic Grid Example

See below for a default grid tht will fill the entire canvas with the specified number of rows and cols.

import { Grid } from '@phaserquick/grid';

// Create a new grid with 9 rows and 9 columns
const grid = new Grid(scene, 9, 9);

// Enable debugging to visualize the grid
grid.enableDebug();

Output:

Example 1

1.2.2. Aspect Ratio Specific Grid Example

In this example, the grid is created with an aspect ratio of 16:9. The grid is aligned in the center of the screen.

import { Grid } from '@phaserquick/grid';

/**
 * Create a 9x9 grid with an aspect ratio of 9:16, and align
 * it to the bottom of the canvas.
 */
const grid = new Grid(this, 9, 9, {
  aspectRatio: {
    height: 9,
    width: 16,
    align: 'bottom'
  }
});

// Enable debugging to visualize the aspect ratio-based grid
grid.enableDebug();

Output:

Example 2

1.2.3. Placing Items Throughout the Grid

This example demonstrates how to place items in specific cells of the grid. You can use the cell() method to retrieve the position of any cell and customize its alignment within the cell.

import { Grid } from '@phaserquick/grid';

const gem1 = this.add.image(0, 0, 'gem').setAlpha(0.4);
const gem2 = this.add.image(0, 0, 'gem').setAlpha(0.4);

const grid = new Grid(this, 9, 9);

// Enable debugging to visualize the aspect ratio-based grid
grid.enableDebug();

// Get cell 41 x & y. Center of the cell by default.
const cell29 = grid.cell(29);

// Place gem1 at cell 29.
gem1.setPosition(cell29.x, cell29.y);

// Get cell 52 x & y. Bottom right of the cell.
const cell52 = grid.cell(52, { x: 'right', y: 'bottom' });

// Place gem2 at the bottom right of cell 52.
gem2.setPosition(cell52.x, cell52.y);

Output:

Example 3

2. API Reference

2.1. Constructor

new Grid(scene: Phaser.Scene, rows: number, cols: number, options?: GridOptions)

Creates a new instance of the Grid class.

  • scene: The Phaser scene to which the grid belongs.
  • rows: The number of rows in the grid.
  • cols: The number of columns in the grid.
  • options (optional): Additional options for configuring the grid, including:
    • cellColor: The color of the grid cell outlines (default is red).
    • aspectRatio: Defines the width, height, and alignment of the grid based on a specified aspect ratio. This option can be omitted if you want the grid to automatically adjust to fit the canvas.

2.2. Properties

2.2.1. width

Retrieves the full width of the grid.

2.2.2. height

Retrieves the full height of the grid.

2.3. Methods

2.3.1. cell

cell(cellID: number, options?: { x?: 'left' | 'right' | 'center', y?: 'top' | 'bottom' | 'center' }): { x: number, y: number }

Retrieves the coordinates of the center of the specified cell in the grid.

  • cellID: The ID of the cell for which to retrieve the coordinates.
  • options (optional): Additional options for specifying the alignment of the cell coordinates.
    • x: Specifies horizontal alignment. Can be 'left', 'right', or 'center' (default).
    • y: Specifies vertical alignment. Can be 'top', 'bottom', or 'center' (default).

2.3.2. enableDebug

enableDebug()

Enables debugging for the grid by drawing rectangles with outlines and adding text to represent the cell IDs. This method is useful for visualizing and debugging the grid layout.

No parameters are required.

Example:

grid.enableDebug();

2.3.3. widthOf

widthOf(cells: number): number

Returns the total width of a specified number of cells. This is useful for calculating how much horizontal space a given number of cells will take up.

  • cells: The number of cells for which to calculate the width.

Example:

const totalWidth = grid.widthOf(3); // Gets the width of 3 cells

2.3.4. heightOf

heightOf(cells: number): number

Returns the total height of a specified number of cells. This is useful for calculating how much vertical space a given number of cells will take up.

  • cells: The number of cells for which to calculate the height.

Example:

const totalHeight = grid.heightOf(4); // Gets the height of 4 cells