Help, can't get overlay to work

alfredma

12-12-2006 07:49:39

So I was trying to display a string using Overlay. But I couldn't get it to display. I couldn't see what is wrong with my code. Please help me >.<


Overlay panel;
OverlayContainer healthbar;
OverlayElement textBox;

public override void CreateViewports()
{
panel = OverlayManager.Singleton.Create("GUI/panel");
healthbar = (OverlayContainer) OverlayManager.Singleton.CreateOverlayElement("Panel", "healthbar1");
panel.Add2D(healthbar);
healthbar.SetDimensions(100, 100);
healthbar.SetPosition(100, 100);

textBox = OverlayManager.Singleton.CreateOverlayElement("TextArea", "textarea1");
textBox.SetDimensions(100, 100);
textBox.SetPosition(0, 0);
textBox.SetParameter("metric_mode", "pixels");
textBox.SetParameter("font_name", "MyFont");
textBox.SetParameter("char_height", "40");

textBox.SetParameter("colour", "1.0, 1.0, 1.0");
textBox.SetParameter("caption", "Show it to me!");

healthbar.AddChild(textBox);
panel.Show();
...
}

Bekas

12-12-2006 13:32:09

By default dimension/position is in relative mode (1 is full width/height of screen), so before setting them you need to change it to pixel mode:
panel = OverlayManager.Singleton.Create("GUI/panel");
healthbar = (OverlayContainer)OverlayManager.Singleton.CreateOverlayElement("Panel", "healthbar1");
panel.Add2D(healthbar);
healthbar.MetricsMode = GuiMetricsMode.GMM_PIXELS;
healthbar.SetDimensions(100, 100);
healthbar.SetPosition(100, 100);

textBox = OverlayManager.Singleton.CreateOverlayElement("TextArea", "textarea1");
textBox.MetricsMode = GuiMetricsMode.GMM_PIXELS;
textBox.SetDimensions(100, 100);
textBox.SetPosition(0, 0);
textBox.SetParameter("metric_mode", "pixels");
textBox.SetParameter("font_name", "MyFont");
textBox.SetParameter("char_height", "40");

textBox.SetParameter("colour", "1.0, 1.0, 1.0");
textBox.SetParameter("caption", "Show it to me bitchs!");

healthbar.AddChild(textBox);
panel.Show();