Does opacity work?
by JohnT · in Torque X 2D · 05/31/2008 (12:03 pm) · 3 replies
Has anyone tried using the opacity setting on a gui control?
I am creating a splash screen that is supposed to fade in and out before starting the game and I am not able to modify the transparency with the following code. Hope someone can tell me what I'm doing wrong here. In the example I am trying to make the image 50% transparent.
I am creating a splash screen that is supposed to fade in and out before starting the game and I am not able to modify the transparency with the following code. Hope someone can tell me what I'm doing wrong here. In the example I am trying to make the image 50% transparent.
public SplashScreen(string imageName, float fadeInTime, float fadeOutTime)
{
GUIStyle baseStyle = new GUIStyle();
baseStyle.IsOpaque = false;
baseStyle.Focusable = true;
GUIBitmapStyle bitmapStyle = new GUIBitmapStyle();
bitmapStyle.SizeToBitmap = true;
bitmapStyle.IsOpaque = false;
_root = new GUIControl();
_root.Style = baseStyle;
_root.Layer = 50;
_root.FocusOnWake = true;
_root.Visible = true;
_splash = new GUIBitmap();
_splash.Style = bitmapStyle;
_splash.Bitmap = imageName;
float factor = GUICanvas.Instance.Size.Y / 768;
float offset = (GUICanvas.Instance.Size.X - 1024*factor) / 2;
Vector2 position = new Vector2(offset, 0);
Vector2 size = new Vector2(1024*factor, 768*factor);
_splash.Position = position;
_splash.Size = size;
_splash.Visible = true;
_splash.Opacity = .50f;
_splash.Folder = _root;
_InitInputMap();
ToggleMenu();
}About the author
#2
To get opacity to work you need to set IsColorBlended to true as in the post.
06/01/2008 (7:00 am)
Yes, use GUISplashScreen. But if you want to do it your way, see also: http://www.garagegames.com/mg/forums/result.thread.php?qt=75514. To get opacity to work you need to set IsColorBlended to true as in the post.
#3
The class works great.
Thanks for the help.
06/01/2008 (3:53 pm)
Sure does pay to look into the source code before trying to reinvent the wheel!The class works great.
Thanks for the help.
Associate John Kanalakis
EnvyGames
public class GuiSplashScreen : GUISplash, IGUIScreen { public GuiSplashScreen() { // create the Style for our splash ad GUISplashStyle splashStyle = new GUISplashStyle(); splashStyle.FadeInSec = 2; // black to image 2 seconds splashStyle.FadeOutSec = 2; // image to black 2 seconds splashStyle.FadeWaitSec = 4; // still image for 4 seconds splashStyle.Bitmap = @"data\images\splashscreen"; splashStyle.PreserveAspectRatio = true; // set some info for this control Name = "GuiSplashScreen"; Style = splashStyle; Size = new Vector2(800, 600); OnFadeFinished = OnSplashFinished; } }Then call it with something like this...
protected override void BeginRun() { base.BeginRun(); // show the splash screen GuiSplashScreen splash = new GuiSplashScreen (); GUICanvas.Instance.SetContentControl("GuiSplashScreen"); }John K.