コンテンツにスキップ

PieSprite

Promete v1.3.0からサポート

PieSpriteは、テクスチャを扇状(円グラフ状)に描画するためのノードです。Spriteを継承しており、ローディングゲージ、クールダウンタイマー、円グラフなど、進行状況を視覚的に表現する際に便利です。

作成

PieSpriteの基本的な作成方法はSpriteと同じです。テクスチャを読み込み、コンストラクタに渡します。

基本的なPieSpriteの作成
public class GameScene : Scene
{
public override void OnStart()
{
// テクスチャを読み込み
var texture = Window.TextureFactory.Load("assets/gauge.png");
// PieSpriteを作成
var pieSprite = new PieSprite(texture);
// シーンに追加
Root.Add(pieSprite);
}
}

扇形の制御

描画範囲の指定

StartPercentPercentプロパティで、テクスチャの描画範囲を制御できます。

描画範囲の設定
var pieSprite = new PieSprite(texture);
// 開始位置: 真上(12時方向)
pieSprite.StartPercent = 0.0f;
// 終了位置: 25%(3時方向)
pieSprite.Percent = 25.0f;
Root.Add(pieSprite);

時計回りアニメーション

パーセントを変更することで、アニメーション効果を実現できます。

ローディングゲージの実装
public class LoadingScene : Scene
{
private PieSprite? _loadingGauge;
private float _progress = 0.0f;
public override void OnStart()
{
var texture = Window.TextureFactory.Load("assets/loading.png");
_loadingGauge = new PieSprite(texture)
.Location(Window.Width / 2, Window.Height / 2)
.Pivot(0.5f, 0.5f); // 中心を基準点に
Root.Add(_loadingGauge);
}
public override void OnUpdate()
{
if (_loadingGauge == null) return;
// 進行状況を更新
_progress += 0.5f; // 毎フレーム0.5%ずつ増加
if (_progress >= 100.0f)
{
_progress = 100.0f;
// ローディング完了
App.LoadScene<GameScene>();
}
// PieSpriteに反映
_loadingGauge.Percent = _progress;
}
}

部分的な扇形表示

StartPercentPercentを両方使用することで、円の一部だけを描画できます。

円の一部を表示
// 右半分のみ表示(3時 ~ 9時)
var rightHalf = new PieSprite(texture)
.Location(100, 100);
rightHalf.StartPercent = 25.0f; // 3時から開始
rightHalf.Percent = 75.0f; // 9時まで
// 上半分のみ表示(9時 ~ 3時)
var topHalf = new PieSprite(texture)
.Location(250, 100);
topHalf.StartPercent = 75.0f; // 9時から開始
topHalf.Percent = 25.0f; // 3時まで(次の周)
Root.AddRange(rightHalf, topHalf);

Spriteのプロパティ継承

PieSpriteSpriteを継承しているため、すべてのSpriteプロパティが使用できます。

Spriteプロパティの使用
var pieSprite = new PieSprite(texture)
.Location(200, 150)
.Scale(2.0f)
.Pivot(0.5f, 0.5f)
.TintColor(Color.FromArgb(200, 255, 200, 100))
.ZIndex(10);
pieSprite.StartPercent = 0.0f;
pieSprite.Percent = 50.0f;
Root.Add(pieSprite);

詳細はSpriteのドキュメントを参照してください。

実用例

クールダウンタイマー

スキルのクールダウン表示に使用できます。

クールダウンタイマー
public class SkillButton(Keyboard keyboard) : Container
{
private PieSprite? _cooldownOverlay;
private float _cooldownTime = 0.0f;
private const float MaxCooldown = 5.0f; // 5秒
public override void OnStart()
{
// スキルアイコン
var iconTexture = Window!.TextureFactory.Load("assets/skill_icon.png");
var icon = new Sprite(iconTexture);
Add(icon);
// クールダウンオーバーレイ(半透明の黒)
var overlayTexture = Window.TextureFactory.Load("assets/black_circle.png");
_cooldownOverlay = new PieSprite(overlayTexture)
.TintColor(Color.FromArgb(128, 0, 0, 0)); // 半透明
_cooldownOverlay.StartPercent = 0.0f;
_cooldownOverlay.Percent = 0.0f;
_cooldownOverlay.IsVisible = false;
Add(_cooldownOverlay);
}
public override void OnUpdate()
{
// スキル使用
if (keyboard.Space.IsKeyDown && _cooldownTime <= 0.0f)
{
UseSkill();
_cooldownTime = MaxCooldown;
_cooldownOverlay!.IsVisible = true;
}
// クールダウン更新
if (_cooldownTime > 0.0f)
{
_cooldownTime -= App.DeltaTime;
// 進行状況を計算(100% → 0%に減少)
var progress = (_cooldownTime / MaxCooldown) * 100.0f;
_cooldownOverlay!.Percent = progress;
if (_cooldownTime <= 0.0f)
{
_cooldownTime = 0.0f;
_cooldownOverlay.IsVisible = false;
}
}
}
private void UseSkill()
{
// スキル発動処理
}
}

円形のHPゲージ

円形HPゲージ
public class CircularHealthBar : Container
{
private PieSprite? _hpGauge;
private int _currentHp = 100;
private int _maxHp = 100;
public override void OnStart()
{
var gaugeTexture = Window!.TextureFactory.Load("assets/hp_gauge.png");
_hpGauge = new PieSprite(gaugeTexture)
.Pivot(0.5f, 0.5f);
_hpGauge.StartPercent = 0.0f;
_hpGauge.Percent = 100.0f; // 初期状態: 満タン
Add(_hpGauge);
}
public void TakeDamage(int damage)
{
_currentHp = Math.Max(0, _currentHp - damage);
UpdateGauge();
}
public void Heal(int amount)
{
_currentHp = Math.Min(_maxHp, _currentHp + amount);
UpdateGauge();
}
private void UpdateGauge()
{
var hpPercent = (_currentHp / (float)_maxHp) * 100.0f;
_hpGauge!.Percent = hpPercent;
// HPに応じて色を変更
if (hpPercent > 50.0f)
_hpGauge.TintColor = Color.Green;
else if (hpPercent > 25.0f)
_hpGauge.TintColor = Color.Yellow;
else
_hpGauge.TintColor = Color.Red;
}
}

注意事項

  • StartPercentPercentは自動的に0.0 ~ 100.0の範囲にクランプされます
  • テクスチャの中心を基準に扇形が描画されるため、通常はPivot(0.5f, 0.5f)に設定することを推奨します
  • PercentStartPercentより小さい場合、0%(真上)を跨いで描画されます