Closed Kubrix closed 7 months ago
using Myra; using Myra.Graphics2D.UI;
public class Game1 :Game { private Desktop _desktop; Grid grid; }
protected override void LoadContent() { MyraEnvironment.Game = this; var grid = new Grid { RowSpacing = 8, ColumnSpacing = 8 }; _desktop = new Desktop(); _desktop.Root = grid; }
protected override void Draw(GameTime gameTime) { ... var panel = new Panel(); var positionedText = new Label(); positionedText.Text = "Positioned Text"; positionedText.Left = 50; positionedText.Top = 100; panel.Widgets.Add(positionedText); grid.Widgets.Add(panel); .. _desktop.Render(); base.Draw(gameTime); break;
Exception on grid.Widgets.Add(panel); grid was null.
Move the ui creation code into LoadContent. You don't want it to be recreated every frame.
Thanks!
Exception on grid.Widgets.Add(panel); grid was null.