geometry-and-math について
Phaser 4 開発者向けのジオメトリと数学のスキルです。ジオメトリのデータクラス、交差判定、数学ユーティリティを扱い、形状計算やゲームロジックに役立ちます。ジオメトリ自体は描画可能なゲームオブジェクトではありません。
主な機能
- 01Circle、Ellipse、Line などのジオメトリクラス
- 02点の包含判定と周辺点の取得
- 03形状の交差に関する真偽判定
- 04交点と重複領域の計算
- 05角度、距離、補間のユーティリティ
- 06イージング、スナップ、ファジー比較
活用シーン
- 01ゲームオブジェクト間の幾何学的な重なり判定
- 02線分と形状の交点計算
- 03形状の境界に沿った座標のサンプリング
- 04移動やアニメーション用の角度と補間の計算
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ phaserjs/ phaser --skill geometry-and-mathインストール後、Claude Code で/geometry-and-mathを入力して読み込まれたか確認します。
詳細
Phaser 4 — ジオメトリと数学
Geom クラス(Circle、Ellipse、Line、Polygon、Rectangle、Triangle)、交差判定、および Math ユーティリティ(Vector2、Vector3、Matrix4、角度、距離、補間、イージング、乱数、スナップ、クランプ)。
関連スキル: graphics-and-shapes.md、physics-arcade.md
クイックスタート
// Create geometry objects (these are data only, not renderable)
const rect = new Phaser.Geom.Rectangle(10, 20, 200, 100);
const circle = new Phaser.Geom.Circle(400, 300, 50);
const line = new Phaser.Geom.Line(0, 0, 100, 100);
// Point containment
rect.contains(50, 50); // true
circle.contains(410, 310); // true
// Intersection test
Phaser.Geom.Intersects.CircleToRectangle(circle, rect); // boolean
// Math utilities
const v = new Phaser.Math.Vector2(3, 4);
v.length(); // 5
v.normalize(); // {x: 0.6, y: 0.8}
const dist = Phaser.Math.Distance.Between(0, 0, 100, 100);
const angle = Phaser.Math.Angle.Between(0, 0, 100, 100);
const clamped = Phaser.Math.Clamp(150, 0, 100); // 100
基本概念
ジオメトリオブジェクトは、座標と寸法を保持する純粋なデータコンテナです。ゲームオブジェクトではなく、表示リストに追加することはできません。ジオメトリを描画するには、Graphics ゲームオブジェクトまたは Shape ゲームオブジェクトを使用します(graphics-and-shapes.md を参照)。
すべての Geom クラスには、高速な型チェックのために Phaser.Geom 定数が設定された type プロパティがあります。
すべての Geom クラスは、共通のインスタンスメソッドのパターンを共有しています:
contains(x, y)-- 図形内の点の判定getPoint(position, output?)-- 外周上の正規化された位置(0〜1)の点getPoints(quantity, stepRate?, output?)-- 外周上に等間隔に配置された点getRandomPoint(output?)-- 図形内のランダムな点setTo(...)-- すべてのプロパティをリセットsetEmpty()-- 図形をゼロにするsetPosition(x, y)-- 原点/中心を移動
各 Geom タイプには、静的ヘルパー関数のフォルダーもあります(例: Phaser.Geom.Rectangle.Contains、Phaser.Geom.Circle.Area)。
ジオメトリクラス
| クラス | 名前空間 | コンストラクター | 主なプロパティ |
|---|---|---|---|
| Circle | Phaser.Geom.Circle | (x, y, radius) | x、y、radius、diameter、left、right、top、bottom |
| Ellipse | Phaser.Geom.Ellipse | (x, y, width, height) | x、y、width、height、left、right、top、bottom |
| Line | Phaser.Geom.Line | (x1, y1, x2, y2) | x1、y1、x2、y2、left、right、top、bottom |
| Polygon | Phaser.Geom.Polygon | (points) | area、points(Vector2Like の配列) |
| Rectangle | Phaser.Geom.Rectangle | (x, y, width, height) | x、y、width、height、left、right、top、bottom、centerX、centerY |
| Triangle | Phaser.Geom.Triangle | (x1, y1, x2, y2, x3, y3) | x1、y1、x2、y2、x3、y3 |
Rectangle の静的ヘルパー
Phaser.Geom.Rectangle.*: Area、Ceil、CeilAll、CenterOn、Clone、Contains、ContainsPoint、ContainsRect、CopyFrom、Decompose、Equals、FitInside、FitOutside、Floor、FloorAll、FromPoints、FromXY、GetAspectRatio、GetCenter、GetPoint、GetPoints、GetSize、Inflate、Intersection、MarchingAnts、MergePoints、MergeRect、MergeXY、Offset、OffsetPoint、Overlaps、Perimeter、PerimeterPoint、Random、RandomOutside、SameDimensions、Scale、Union。
Circle の静的ヘルパー
Phaser.Geom.Circle.*: Area、Circumference、CircumferencePoint、Clone、Contains、ContainsPoint、ContainsRect、CopyFrom、Equals、GetBounds、GetPoint、GetPoints、Offset、OffsetPoint、Random。
Line の静的ヘルパー
Phaser.Geom.Line.*: Angle、BresenhamPoints、CenterOn、Clone、CopyFrom、Equals、Extend、GetEasedPoints、GetMidPoint、GetNearestPoint、GetNormal、GetPoint、GetPoints、GetShortestDistance、Height、Length、NormalAngle、NormalX、NormalY、Offset、PerpSlope、Random、ReflectAngle、Rotate、RotateAroundPoint、RotateAroundXY、SetToAngle、Slope、Width。
Triangle の静的ヘルパー
Phaser.Geom.Triangle.*: Area、BuildEquilateral、BuildFromPolygon、BuildRight、CenterOn、Centroid、CircumCenter、CircumCircle、Clone、Contains、ContainsArray、ContainsPoint、CopyFrom、Decompose、Equals、GetPoint、GetPoints、InCenter、Offset、Perimeter、Random、Rotate、RotateAroundPoint、RotateAroundXY。
Polygon の入力形式
Polygon コンストラクターは、points 引数に複数の形式を受け付けます:
- スペース区切りの文字列:
'40 0 40 20 100 20 100 80' {x, y}オブジェクトの配列- フラットな数値配列:
[x1, y1, x2, y2, ...] [x, y]サブ配列の配列
交差判定
すべて Phaser.Geom.Intersects 以下にあります。
真偽値テスト (true/false を返す)
| 関数 | 説明 |
|---|---|
CircleToCircle(circleA, circleB) | 2 つの円が重なっている |
CircleToRectangle(circle, rect) | 円が長方形と重なっている |
LineToCircle(line, circle) | 線分が円と交差している |
LineToLine(line1, line2, out?) | 2 つの線分が交差している。交点を out に書き込む |
LineToRectangle(line, rect) | 線分が長方形と交差している |
PointToLine(point, line, lineThickness?) | 点が直線上または直線の近くにある |
PointToLineSegment(point, line) | 点が有限の線分上にある |
RectangleToRectangle(rectA, rectB) | 2 つの長方形が重なっている |
RectangleToTriangle(rect, triangle) | 長方形が三角形と重なっている |
RectangleToValues(rect, left, right, top, bottom, tolerance?) | 長方形が LRTB 境界と重なっている |
TriangleToCircle(triangle, circle) | 三角形が円と重なっている |
TriangleToLine(triangle, line) | 三角形が直線と交差している |
TriangleToTriangle(triA, triB) | 2 つの三角形が重なっている |
交点の取得 (Vector2[] を返す)
| 関数 | 説明 |
|---|---|
GetCircleToCircle(circleA, circleB, out?) | 2 つの円の交点 |
GetCircleToRectangle(circle, rect, out?) | 円が長方形の辺と交わる点 |
GetLineToCircle(line, circle, out?) | 直線が円と交差する点 |
GetLineToLine(line1, line2, out?) | 2 つの直線の単一の交点 |
GetLineToPoints(line, points, out?) | 辺を形成する一連の点との交点 |
GetLineToPolygon(line, polygon, out?) | ポリゴンの辺との最も近い交点 |
GetLineToRectangle(line, rect, out?) | 直線が長方形と交差する点 |
GetRaysFromPointToPolygon(x, y, polygon) | 点からポリゴンの辺へのレイキャスト |
GetRectangleIntersection(rectA, rectB, out?) | 重なり合う長方形の領域 |
GetRectangleToRectangle(rectA, rectB, out?) | 辺の交点 |
GetRectangleToTriangle(rect, triangle, out?) | 辺の交点 |
GetTriangleToCircle(triangle, circle, out?) | 辺の交点 |
GetTriangleToLine(triangle, line, out?) | 辺の交点 |
GetTriangleToTriangle(triA, triB, out?) | 辺の交点 |
カテゴリ別の数学関数
特記がない限り、すべて Phaser.Math 以下にあります。
定数
| 定数 | 値 |
|---|---|
Phaser.Math.TAU | PI * 2 (v4 で追加) |
Phaser.Math.PI_OVER_2 | PI / 2 |
Phaser.Math.EPSILON | 1.0e-6 |
Phaser.Math.DEG_TO_RAD | PI / 180 |
Phaser.Math.RAD_TO_DEG | 180 / PI |
Phaser.Math.RND | グローバルな RandomDataGenerator インスタンス (ゲーム設定の seed でシードされる) |
角度関数 (Phaser.Math.Angle.*)
| 関数 | 説明 |
|---|---|
Between(x1, y1, x2, y2) | 2 点間の角度 (ラジアン) |
BetweenPoints(point1, point2) | 同上。{x,y} オブジェクトを受け取る |
BetweenY(x1, y1, x2, y2) | 垂直軸からの角度 |
BetweenPointsY(point1, point2) | 同上。オブジェクトを受け取る |
CounterClockwise(angle) | 反時計回りに変換 |
GetClockwiseDistance(from, to) | 時計回りの角度距離 |
GetCounterClockwiseDistance(from, to) | 反時計回りの角度距離 |
GetShortestDistance(from, to) | 最短の角度距離 (符号付き) |
Normalize(angle) | [0, 2PI) に正規化 |
Random() | ランダムな角度 (ラジアン) |
RandomDegrees() | ランダムな角度 (度) |
Reverse(angle) | 反転 (PI を加算) |
RotateTo(currentAngle, targetAngle, lerp?) | 目標角度に向かってステップ移動 |
ShortestBetween(angle1, angle2) | 度単位での最短の差 |
Wrap(angle) | (-PI, PI] にラップ |
WrapDegrees(angle) | (-180, 180] にラップ |
距離関数 (Phaser.Math.Distance.*)
| 関数 | 説明 |
|---|---|
Between(x1, y1, x2, y2) | ユークリッド距離 |
BetweenPoints(a, b) | 同様ですが、{x,y} オブジェクトを受け取ります |
BetweenPointsSquared(a, b) | 二乗距離(sqrt を回避します) |
Chebyshev(x1, y1, x2, y2) | チェビシェフ(チェス盤)距離 |
Power(x1, y1, x2, y2, pow) | カスタムの冪によるミンコフスキー距離 |
Snake(x1, y1, x2, y2) | マンハッタン/タクシー距離 |
Squared(x1, y1, x2, y2) | 二乗ユークリッド距離 |
補間 (Phaser.Math.Interpolation.*)
| 関数 | 説明 |
|---|---|
BezierInterpolation(v, k) | 制御点を通るベジェ曲線 |
CatmullRomInterpolation(v, k) | 点を通る Catmull-Rom スプライン |
CubicBezierInterpolation(t, p0, p1, p2, p3) | 4 つの値の間の三次ベジェ |
LinearInterpolation(v, k) | 値の配列を通る線形補間 |
QuadraticBezierInterpolation(t, p0, p1, p2) | 二次ベジェ |
SmoothStepInterpolation(t, min, max) | エルミートのスムーズステップ |
SmootherStepInterpolation(t, min, max) | Ken Perlin のスムーザーステップ |
スナップ関数 (Phaser.Math.Snap.*)
| 関数 | 説明 |
|---|---|
To(value, gap, start?, divide?) | 最も近い増分にスナップします |
Floor(value, gap, start?, divide?) | 増分に切り下げてスナップします |
Ceil(value, gap, start?, divide?) | 増分に切り上げてスナップします |
あいまい比較 (Phaser.Math.Fuzzy.*)
| 関数 | 説明 |
|---|---|
Equal(a, b, epsilon?) | a が b とほぼ等しい |
LessThan(a, b, epsilon?) | epsilon の範囲内で a < b |
GreaterThan(a, b, epsilon?) | epsilon の範囲内で a > b |
Ceil(value, epsilon?) | あいまいな切り上げ |
Floor(value, epsilon?) | あいまいな切り下げ |
イージング関数 (Phaser.Math.Easing.*)
各タイプには .In、.Out、.InOut のバリアントがあります。主にトゥイーンで使用されます('Sine.easeOut' のような文字列名を渡します)。
| タイプ | 文字列キー |
|---|---|
| Back | Back.easeIn、Back.easeOut、Back.easeInOut |
| Bounce | Bounce.easeIn、Bounce.easeOut、Bounce.easeInOut |
| Circular | Circ.easeIn、Circ.easeOut、Circ.easeInOut |
| Cubic | Cubic.easeIn、Cubic.easeOut、Cubic.easeInOut |
| Elastic | Elastic.easeIn、Elastic.easeOut、Elastic.easeInOut |
| Expo | Expo.easeIn、Expo.easeOut、Expo.easeInOut |
| Linear | Linear(バリアントなし) |
| Quadratic | Quad.easeIn、Quad.easeOut、Quad.easeInOut |
| Quartic | Quart.easeIn、Quart.easeOut、Quart.easeInOut |
| Quintic | Quint.easeIn、Quint.easeOut、Quint.easeInOut |
| Sine | Sine.easeIn、Sine.easeOut、Sine.easeInOut |
| Stepped | Stepped(バリアントなし) |
Power エイリアス: Power0 = Linear、Power1 = Quad.Out、Power2 = Cubic.Out、Power3 = Quart.Out、Power4 = Quint.Out。
短縮名も使用できます: 'Quad' = Quad.Out、'Sine' = Sine.Out など。
コア数学ヘルパー(Phaser.Math に直接)
| 関数 | 説明 |
|---|---|
Between(min, max) | [min, max] の範囲のランダムな整数 |
FloatBetween(min, max) | [min, max] の範囲のランダムな浮動小数点数 |
Clamp(value, min, max) | 値を範囲内に制限 |
Wrap(value, min, max) | 値を範囲内でラップ |
Within(a, b, tolerance) | a が b の許容範囲内かどうかを確認 |
Percent(value, min, max, upperMax?) | 範囲に対する割合としての値 |
FromPercent(percent, min, max) | 範囲の割合から値を取得 |
DegToRad(degrees) | 度をラジアンに変換 |
RadToDeg(radians) | ラジアンを度に変換 |
Linear(p0, p1, t) | 2 つの値の間を線形補間 |
LinearXY(v1, v2, t, out?) | 2 つの Vector2Like オブジェクトの間を線形補間 |
SmoothStep(x, min, max) | エルミートスムーズステップ |
SmootherStep(x, min, max) | パーリンスムーザーステップ |
Average(values) | 数値配列の平均 |
Median(values) | 数値配列の中央値 |
CeilTo(value, place?, base?) | 小数点以下で切り上げ |
FloorTo(value, place?, base?) | 小数点以下で切り捨て |
RoundTo(value, place?, base?) | 小数点以下で四捨五入 |
RoundAwayFromZero(value) | ゼロから遠い方向に丸め |
MaxAdd(value, amount, max) | 最大値で制限して加算 |
MinSub(value, amount, min) | 最小値で制限して減算 |
Difference(a, b) | 絶対差 |
IsEven(value) | 整数が偶数かどうか |
IsEvenStrict(value) | 厳密に偶数かどうか(ゼロを除く) |
Factorial(value) | 階乗 |
Rotate(point, angle) | 原点を中心に点を回転 |
RotateAround(point, cx, cy, angle) | カスタム中心を中心に点を回転 |
RotateAroundDistance(point, cx, cy, angle, dist) | 固定距離で回転 |
TransformXY(x, y, posX, posY, rotation, scaleX, scaleY, output?) | 完全な 2D 変換 |
GetSpeed(distance, time) | 距離と時間から速度を取得 |
RandomXY(vector, scale?) | ベクトルをランダムな単位方向に設定 |
2 のべき乗(Phaser.Math.Pow2.*)
| 関数 | 説明 |
|---|---|
GetPowerOfTwo(value) | value 以上の最小の 2 のべき乗 |
IsValuePowerOfTwo(value) | value が 2 のべき乗かどうかを確認 |
IsSizePowerOfTwo(width, height) | 両方の次元が 2 のべき乗かどうかを確認 |
Vector2 クイックリファレンス
Phaser.Math.Vector2 -- Phaser 全体で位置、速度、方向に使用される 2D ベクトルです。
コンストラクター: new Vector2(x?, y?) または new Vector2({x, y})。x のみを指定した場合、y は x と同じ値になります。
| メソッド | 戻り値 | 説明 |
|---|---|---|
set(x, y) / setTo(x, y) | this | 成分を設定します |
setToPolar(angle, length?) | this | 角度と長さから設定します |
copy(src) / setFromObject(obj) | this | Vector2Like からコピーします |
clone() | Vector2 | 新しいコピーを作成します |
add(src) / subtract(src) | this | 成分ごとの加算 / 減算 |
multiply(src) / divide(src) | this | 成分ごとの乗算 / 除算 |
scale(value) | this | 両方の成分にスカラーを乗算します |
negate() | this | 両方の成分の符号を反転します |
normalize() | this | 長さを 1 に設定します |
normalizeRightHand() | this | 垂直方向 (右手の法則) |
normalizeLeftHand() | this | 垂直方向 (左手の法則) |
limit(max) | this | 長さを最大値に制限します |
setLength(length) | this | 正確な長さにスケーリングします |
length() | number | 大きさ |
lengthSq() | number | 大きさの二乗 (sqrt なし) |
distance(src) | number | 別のベクトルまでの距離 |
distanceSq(src) | number | 距離の二乗 |
dot(src) | number | 内積 |
cross(src) | number | 2D 外積 (スカラー) |
angle() | number | 正の x 軸からの角度 (ラジアン) |
setAngle(angle) | this | 長さを維持したまま角度まで回転します |
rotate(delta) | this | delta ラジアン回転します |
lerp(src, t) | this | src に向けて線形補間します |
reflect(normal) | this | 表面法線に対して反射します |
mirror(axis) | this | 軸ベクトルに対してミラーリングします |
project(src) | this | 別のベクトルに射影します |
equals(v) | boolean | 完全一致 |
fuzzyEquals(v, epsilon?) | boolean | 近似一致 |
ceil() / floor() / invert() | this | 成分の変換 |
reset() | this | (0, 0) に設定します |
transformMat3(mat) | this | Matrix3 で変換します |
transformMat4(mat) | this | Matrix4 で変換します |
静的プロパティ: Vector2.ZERO、Vector2.RIGHT、Vector2.LEFT、Vector2.UP、Vector2.DOWN、Vector2.ONE。
Vector3 クイックリファレンス
Phaser.Math.Vector3 -- カメラの投影、ライティング、3D 数学のための 3D ベクトルです。
コンストラクター: new Vector3(x?, y?, z?) または new Vector3({x, y, z})。
主なメソッド (Vector2 と同じパターンに加えて): up()、min(v)、max(v)、addVectors(a, b)、subVectors(a, b)、crossVectors(a, b)、cross(v)、addScalar(s)、addScale(v, scale)、fromArray(array, offset?)、setFromMatrixPosition(mat4)、setFromMatrixColumn(mat4, index)、applyMatrix3(mat)、applyMatrix4(mat)、transformCoordinates(mat)、transformQuat(q)、project(mat)、projectViewMatrix(view, proj)、unproject(viewport, invProjView)。
Matrix4 クイックリファレンス
Phaser.Math.Matrix4 -- 3D 変換、投影、ビュー行列のための 4x4 行列です。Float32Array(16) に基づいています。
コンストラクター: new Matrix4(m?) -- 既存の Matrix4 からコピーするか、デフォルトで単位行列になります。
主なメソッド: clone()、set(src)、copy(src)、identity()、transpose()、invert()、adjoint()、determinant()、multiply(src)、multiplyLocal(src)、translate(v)、scale(v)、rotate(angle, axis)、rotateX(angle)、rotateY(angle)、rotateZ(angle)、fromRotationTranslation(q, v)、fromQuat(q)、frustum(...)、perspective(fovy, aspect, near, far)、perspectiveLH(width, height, near, far)、ortho(left, right, bottom, top, near, far)、lookAt(eye, center, up)、lookAtRH(eye, target, up)、setWorldMatrix(rotation, position, scale, viewMatrix?, projectionMatrix?)。
その他: Phaser.Math.Matrix3 -- 2D 変換と法線行列のための 3x3 行列です。
RandomDataGenerator
Phaser.Math.RandomDataGenerator -- シード付き PRNG です。グローバルインスタンスは Phaser.Math.RND にあります (ゲーム設定の seed プロパティでシードされます)。
const rnd = Phaser.Math.RND; // or new Phaser.Math.RandomDataGenerator(['my-seed'])
rnd.integer(); // random integer in [0, 2^32]
rnd.frac(); // random float in [0, 1)
rnd.between(1, 10); // random integer in [1, 10]
rnd.integerInRange(1, 10); // alias for between
rnd.realInRange(0.5, 1.5); // random float in [0.5, 1.5]
rnd.normal(); // normal distribution around 0
rnd.angle(); // random angle in radians (-PI to PI)
rnd.rotation(); // random rotation in radians (same range)
rnd.pick(array); // random element from array
rnd.weightedPick(array); // weighted toward end of array
rnd.sign(); // -1 or 1
rnd.uuid(); // RFC4122 v4 UUID string
rnd.shuffle(array); // in-place Fisher-Yates shuffle
rnd.state(state?); // get/set serializable state for save/load
シードを指定して再現可能なシーケンスを作成します: new RandomDataGenerator(['level-42'])。
カラーユーティリティ
Color クラス (Phaser.Display.Color)
WebGL の浮動小数点数、HSV、CSS 文字列、パックされた整数への自動変換を備えた、可変の RGBA カラー表現です。
// Construction
const color = new Phaser.Display.Color(255, 0, 0, 255); // RGBA (0-255)
// Creation helpers (return Color instances)
const c1 = Phaser.Display.Color.ValueToColor('#ff0000'); // hex string, integer, or object
const c2 = Phaser.Display.Color.HexStringToColor('#ff0000');
const c3 = Phaser.Display.Color.RGBStringToColor('rgb(255,0,0)');
const c4 = Phaser.Display.Color.HSVToRGB(0.5, 1, 1); // returns { r, g, b, color }
// Properties
color.r; color.g; color.b; color.a; // 0-255 integers
color.redGL; color.greenGL; color.blueGL; color.alphaGL; // 0-1 floats (WebGL)
color.color; // packed 24-bit integer (0xRRGGBB)
color.color32; // packed 32-bit integer (0xAARRGGBB)
color.rgba; // CSS string 'rgba(r,g,b,a)'
color.h; color.s; color.v; // HSV representation (read-only, auto-updated)
カラー操作
// Adjustment methods (amount is typically 0-100, returns the Color instance)
color.brighten(25); // increase brightness
color.saturate(50); // increase saturation
color.desaturate(30); // decrease saturation
color.lighten(20); // increase lightness
color.darken(10); // decrease lightness
// Utility methods
color.random(); // set to random RGB values (optional min/max range)
color.gray(128); // set to grayscale shade (0-255)
// Setting values
color.setTo(255, 128, 0, 255); // RGBA
color.setFromRGB({ r: 255, g: 128, b: 0, a: 255 });
color.setFromHSV(0.1, 0.8, 1.0); // HSV (0-1 range)
カラー補間 (Phaser.Display.Color.Interpolate)
指定された長さにわたってカラー間を補間します。{ r, g, b, a, color } を返します。
// Between raw RGB values
const result = Phaser.Display.Color.Interpolate.RGBWithRGB(
255, 0, 0, // start color (r, g, b)
0, 0, 255, // end color (r, g, b)
100, // length (number of steps)
50 // index (current step)
); // returns midpoint purple { r, g, b, a, color }
// Between two Color objects
const mid = Phaser.Display.Color.Interpolate.ColorWithColor(color1, color2, 100, 50);
// HSV interpolation (v4): smooth hue transition
const hsvResult = Phaser.Display.Color.Interpolate.HSVWithHSV(0, 1, 1, 0.5, 1, 1, 100, 50);
注意点
-
Geom オブジェクトはゲームオブジェクトではありません。
sceneも、ディスプレイリストからのsetPositionも、テクスチャもありません。それらを描画するには Graphics または Shape ゲームオブジェクトを使用してください。 -
Point クラスは v4 で削除されました。 代わりに
Phaser.Math.Vector2またはプレーンな{x, y}オブジェクトを使用してください。GEOM_CONST.POINT(3)は存在しますが、Point クラスは存在しません。 -
角度は数学 API 全体を通してラジアンです。変換には
Phaser.Math.DegToRad()とRadToDeg()を使用してください。Phaser.Math.TAU定数(2 * PI)は v4 で新しく追加されました。 -
Vector2 のメソッドはその場で値を変更し、チェーン化のために
thisを返します。元の値を保持する必要がある場合は、最初に.clone()を呼び出してください:const result = v.clone().add(other)。 -
二乗距離の方が高速です(
Math.sqrtを回避できます)。実際の距離の値が不要な比較には、Distance.Squaredまたはvec.distanceSq()を使用してください。 -
交差判定の Get 関数は配列を割り当てます。* ホットループでのガベージコレクションの負荷を避けるために、再利用可能な
out配列を渡してください。 -
EaseMap の短縮名はデフォルトで
.Outバリアントになります。'Quad'はQuadratic.Outを意味し、Quadratic.Inではありません。他のバリアントには'Quad.easeIn'のような完全な文字列キーを使用してください。 -
RandomDataGenerator の状態はシリアライズ可能です。
rnd.state()を呼び出すと保存できる文字列を取得でき、rnd.state(savedString)を呼び出すと決定論的な再生のためにそれを復元できます。 -
Polygon.contains はレイキャスティングを使用します(偶数/奇数ルール)。複雑な自己交差ポリゴンでは予期しない結果になる可能性があります。
-
Matrix4.val は Float32Array です。 列優先順序(OpenGL の慣例)で
mat.val[index]を通じて要素に直接アクセスしてください。
ソースファイルマップ
| 領域 | パス |
|---|---|
| Geom クラス | src/geom/{circle,ellipse,line,polygon,rectangle,triangle}/ |
| Geom 定数 | src/geom/const.js |
| 交差判定テスト | src/geom/intersects/ |
| Vector2 | src/math/Vector2.js |
| Vector3 | src/math/Vector3.js |
| Vector4 | src/math/Vector4.js |
| Matrix3 | src/math/Matrix3.js |
| Matrix4 | src/math/Matrix4.js |
| Quaternion | src/math/Quaternion.js |
| Euler | src/math/Euler.js |
| 角度関数 | src/math/angle/ |
| 距離関数 | src/math/distance/ |
| イージング関数 | src/math/easing/(+ 文字列キー用の EaseMap.js) |
| ファジー比較 | src/math/fuzzy/ |
| 補間 | src/math/interpolation/ |
| スナップ関数 | src/math/snap/ |
| 2 のべき乗 | src/math/pow2/ |
| RandomDataGenerator | src/math/random-data-generator/RandomDataGenerator.js |
| 数学定数 | src/math/const.js |
| Color クラス | src/display/color/Color.js |
| カラーユーティリティ | src/display/color/(ValueToColor、HexStringToColor、RGBStringToColor、HSVToRGB、Interpolate) |
| コア数学ヘルパー | src/math/(Clamp.js、Between.js、Wrap.js、Linear.js など) |