geometry-and-math

Document and demonstrate Phaser 4 geometry and math APIs for game development.

40.1k|7.2k|Updated Apr 12, 2013
One-click install
npx skills add https://github.com/phaserjs/phaser --skill geometry-and-math-phaserjs
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: geometry-and-math
Source: https://github.com/phaserjs/phaser/tree/main/skills/geometry-and-math
Command: npx skills add https://github.com/phaserjs/phaser --skill geometry-and-math-phaserjs

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Use this skill to quickly harness Phaser 4 math and geometry utilities. It covers vectors, rectangles, circles, triangles, polygons, random number generation, angles, distance, interpolation, and snapping to empower robust spatial reasoning in Phaser games.

Core Features & Use Cases

  • Geometry primitives and tests (Vector2, Rectangle, Circle, Ellipse, Polygon, Triangle) with fast helpers and distance, angle, and interpolation utilities.
  • Intersections, containment, snapping, and randomization for gameplay logic like collision checks, pathfinding, and layout alignment.
  • Use Case: Build a platformer or shooter requiring hit detection, precise snapping, and smooth motion using Phaser’s math helpers.

Quick Start

Install or import Phaser and immediately start creating and testing geometry objects, vectors, and math operations in your game loop.

Frequently Asked Questions about geometry-and-math

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I check if two Phaser game objects intersect?

Use the Phaser 4 Intersects utilities to test shapes like Rectangles, Circles, and Triangles for collisions and containment. This provides fast collision checks directly within your game loop.

What is the best way to snap coordinates to a grid in Phaser?

The best way to snap coordinates to a grid in Phaser is using the Snap utilities. They allow you to force precise spatial alignment for game objects, ensuring robust layout alignment during gameplay logic implementation.

Does Phaser 4 include built-in math utilities for vector calculations?

Yes, Phaser 4 includes built-in math utilities for vector calculations. The framework provides Vector2 classes and distance, angle, and interpolation helpers to manage spatial reasoning and precise movement across desktop and mobile games.

How do I calculate the distance and angle between two points in Phaser?

Calculate the distance and angle between two points using Phaser's dedicated Distance and Angle math APIs. These utilities provide precise spatial reasoning for smooth motion and pathfinding logic.

Can I generate random numbers within specific ranges using Phaser math helpers?

Yes, you can generate random numbers within specific ranges using Phaser math helpers. The Random utilities support randomization tasks for gameplay logic, enabling dynamic spawning and varied game mechanics across desktop and mobile platforms.

When do I need to use Phaser geometry primitives like Ellipse and Polygon?

You need to use Phaser geometry primitives like Ellipse and Polygon when creating complex hitboxes or defining custom spatial areas. They provide fast shape operations and containment tests for advanced collision detection.