Class: TonPrimitive
幾何学図形の描画、エフェクト描画機能を提供します。
Ton.Gra とは異なり、テクスチャを使用せずに頂点計算によって図形を描画します。
※TonPrimitive のメソッドを呼び出すと、実行中のSpriteBatchが一時中断され、描画モードが切り替わります(描画順序に注意)。
Methods
Basic Shapes
void DrawCircle(Vector2 center, float radius, Color color, int segments = 36)
円を描画します。
center: 中心座標radius: 半径color: 色segments: 円の滑らかさ(分割数)。デフォルトは36。
void DrawCircle(Vector2 center, float radiusX, float radiusY, Color color, int
segments = 36)
楕円を描画します。
center: 中心座標radiusX: X方向の半径radiusY: Y方向の半径color: 色segments: 円の滑らかさ(分割数)。デフォルトは36。
void DrawRectangle(Vector2 position, Vector2 size, Color color, float rotation = 0f,
Vector2? origin = null)
矩形を描画します。回転も可能です。
position: 座標(originがnullの場合は左上、指定されている場合はそのoriginの位置)size: 幅と高さcolor: 色rotation: 回転角度(ラジアン)。デフォルトは0。origin: 回転の中心(ピボット)。nullの場合は中心 (size/2) が使用されます。
void DrawTriangle(Vector2 p1, Vector2 p2, Vector2 p3, Color color)
三角形を描画します。
p1,p2,p3: 3つの頂点座標color: 色
void DrawPolygon(List<Vector2> vertices, Color color)
凸多角形を描画します。頂点リストの順に結んで塗りつぶします。
vertices: 頂点リスト(3つ以上必要)color: 色
void DrawArc(Vector2 center, float radius, float startAngle, float endAngle, float
thickness, Color color, int segments = 24)
円弧(線)を描画します。
center: 中心座標radius: 半径startAngle: 開始角度(ラジアン)endAngle: 終了角度(ラジアン)thickness: 線の太さcolor: 色segments: 分割数。滑らかさに影響します。
void DrawRoundedRectangle(Vector2 position, Vector2 size, float cornerRadius, Color
color, float rotation = 0f, Vector2? origin = null)
角丸矩形を描画します。
position: 座標size: 幅と高さcornerRadius: 角の半径color: 色rotation: 回転角度(ラジアン)origin: 回転の中心。nullの場合は中心が使用されます。
Advanced Graphics
void DrawSpline(List<Vector2> points, float thickness, Color color)
複数の点を通る滑らかなスプライン曲線(Catmull-Rom)を描画します。
points: 通過点のリストthickness: 線の太さcolor: 色
void DrawArrow(List<Vector2> points, float thickness, Color color, float
headSize = 20f, Color? borderColor = null, float borderThickness = 2f)
矢印付きのスプライン曲線を描画します。
points: 通過点のリスト。最後の点が矢印の先端になります。thickness: 線の太さcolor: 色headSize: 矢印の先端(三角形部分)のサイズborderColor: 縁取りの色。nullの場合は縁取りなし。borderThickness: 縁取りの太さ
void DrawRibbon(List<Vector2> points, float startWidth, float endWidth, Color
startColor, Color endColor)
太さと色が変化するリボン(軌跡)を描画します。
points: 通過点のリスト(軌跡データの履歴など)startWidth: 始点(リストの最初)の太さendWidth: 終点(リストの最後)の太さstartColor: 始点の色endColor: 終点の色
void DrawBolt(Vector2 start, Vector2 end, float thickness, Color color, float
difficulty, float updatesPerSecond = 60f)
稲妻を描画します。形状はランダムに変化します。
start: 始点end: 終点thickness: 線の太さcolor: 色difficulty: 形状の複雑さ・激しさ (1.0が標準)。値が大きいほど大きく蛇行します。updatesPerSecond: 秒間の形状更新頻度。60なら毎フレーム変化、0以下なら固定形状になります。
void DrawFocusLines(Vector2 center, float outerRadius, float intensity, Color color,
float updatesPerSecond = 0f)
集中線を描画します。
center: 集中線の中心座標outerRadius: 外径(画面サイズ以上に設定することを推奨、大きくしないと端が見えてしまいます)intensity: 線の密度係数(0.0~)。1.0が標準。color: 色updatesPerSecond: 秒間のアニメーション更新頻度。0で静止画。
Utilities
void GetSplineInfo(List<Vector2> points, float t, out Vector2 position, out
float radians)
スプライン曲線上の任意の位置と角度を取得します。パスに沿ってオブジェクトを動かす場合に便利です。
points: スプライン曲線の通過点リストt: 進行度 (0.0 ~ points.Count - 1.0)。整数部が区間インデックスに対応します。position: 計算された座標 (出力)radians: 計算された角度(ラジアン) (出力)
Sample Code
// 稲妻を描画 (秒間20回アニメーション)
Ton.Primitive.DrawBolt(
new Vector2(100, 100),
new Vector2(500, 500),
5.0f,
Color.Yellow,
1.0f,
20f
);
// 集中線を描画
Ton.Primitive.DrawFocusLines(
center,
1000f,
0.8f,
Color.White,
12f
);
// 角丸矩形の描画
Ton.Primitive.DrawRoundedRectangle(
new Vector2(400, 300),
new Vector2(200, 100),
10f,
Color.Blue
);