stride3d/stride-community-toolkit

Updated Stride.UI Example

Aperta

#275 aperta il 22 mag 2025

 (0 commenti) (1 reazione) (1 assegnatario)C# (31 fork)auto 404
examplehelp wanted

Metriche repository

Star
 (125 stelle)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

I meant to add this code snippet here a while ago but was reminded with the recent issue Keepsie brought up in the Discord.

I will update the examples soon but I just want to document it here in case people wonder how to add SpriteSheet buttons to their UI.

public class TestUI : StartupScript
{
    private SpriteSheet _uiSpriteSheet;

    private SpriteFromSheet _buttonPressed;
    private SpriteFromSheet _buttonNotPressed;
    private SpriteFromSheet _buttonHover;

    public override void Start()
    {
        var buttonSheet = Content.Load<SpriteSheet>("StrideUIDesigns");

        _buttonNotPressed = new()
        {
            Sheet = _uiSpriteSheet,
            CurrentFrame = 1,
        };

        _buttonHover = new()
        {
            Sheet = _uiSpriteSheet,
            CurrentFrame = 0,
        };

        _buttonPressed = new()
        {
            Sheet = _uiSpriteSheet,
            CurrentFrame = 2,
        };
    }

    private void CreateButton()
    {
        var button = new Button
        {
            MouseOverImage = _buttonHover,
            PressedImage = _buttonPressed,
            NotPressedImage = _buttonNotPressed,
        };
    }
}

Guida contributor