Skip to content

Updated Stride.UI Example #275

@Doprez

Description

@Doprez

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,
        };
    }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions