Object Order
Last updated
Was this helpful?
Was this helpful?
// Initialize
for(int i = 0; i < 10; i++)
{
Button button = new();
button.AddToRoot();
button.X = i * 30;
button.Y = i * 5;
button.Click += (_, _) =>
{
var buttonIndex = GumUi.Root.Children.IndexOf(button.Visual);
GumUi.Root.Children.Move(buttonIndex, GumUi.Root.Children.Count - 1);
};
}protected override void Update(GameTime gameTime)
{
GumUi.Update(gameTime);
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
GumUi.Draw();
base.Draw(gameTime);
}public class Game1 : Game
{
private GraphicsDeviceManager _graphics;
SpriteBatch _spriteBatch;
GumBatch _gumBatch;
GumService GumUi => GumService.Default;
ContainerRuntime _belowEverythingContainer;
ContainerRuntime _aboveEverythingContainer;
Texture2D _gumLogoTexture;
public Game1()
{
_graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
}
protected override void Initialize()
{
GumService.Default.Initialize(this);
_spriteBatch = new SpriteBatch(this.GraphicsDevice);
_gumLogoTexture = Texture2D.FromFile(GraphicsDevice, "Content/GumLogo.png");
_gumBatch = new GumBatch();
_belowEverythingContainer = new();
_belowEverythingContainer.HasEvents = false;
_belowEverythingContainer.Dock(Dock.Fill);
_aboveEverythingContainer = new();
_aboveEverythingContainer.HasEvents = false;
_aboveEverythingContainer.Dock(Dock.Fill);
Window belowEverythingWindow = new ();
_belowEverythingContainer.AddChild(belowEverythingWindow);
Window aboveEverythingWindow = new();
_aboveEverythingContainer.AddChild(aboveEverythingWindow);
base.Initialize();
}
List<GraphicalUiElement> itemsToUpdate = new List<GraphicalUiElement>();
protected override void Update(GameTime gameTime)
{
itemsToUpdate.Clear();
itemsToUpdate.Add(_belowEverythingContainer);
itemsToUpdate.Add(GumUi.Root);
itemsToUpdate.Add(_aboveEverythingContainer);
GumUi.Update(gameTime, itemsToUpdate);
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
_gumBatch.Begin();
_gumBatch.Draw(_belowEverythingContainer);
_gumBatch.End();
_spriteBatch.Begin();
_spriteBatch.Draw(_gumLogoTexture, Vector2.Zero, Color.White);
_spriteBatch.End();
GumUi.Draw();
_gumBatch.Begin();
_gumBatch.Draw(_aboveEverythingContainer);
_gumBatch.End();
base.Draw(gameTime);
}
}