Restarting a Fading Bitmap (GUI)
by Gavin Beard · in Torque X 2D · 04/01/2009 (7:08 am) · 3 replies
Hi all,
I used the Tutorial on TDN for making a fade in / fade out splash screen. I have more than one image i want to fade in / out, so was hoping that once the current image has faded out, i could check if the we are at the last image, if not load the next image and restart the gui. However, i have tried using .reset() to restart once i change the image. and that doesnt do the job, is there another way other than having to do it in the game.cs file, i.e in the onFadeFinished function call a function game.cs that then creates another gui etc. i was hoping to do it all within the SplashScreen.cs?
ta
I used the Tutorial on TDN for making a fade in / fade out splash screen. I have more than one image i want to fade in / out, so was hoping that once the current image has faded out, i could check if the we are at the last image, if not load the next image and restart the gui. However, i have tried using .reset() to restart once i change the image. and that doesnt do the job, is there another way other than having to do it in the game.cs file, i.e in the onFadeFinished function call a function game.cs that then creates another gui etc. i was hoping to do it all within the SplashScreen.cs?
ta
#2
this only handles 1 image, i was looking for a way to adjust it to support 3 - 4 images, one after the other, I've got code that when it finishes fading out, it loads another image, unless we are at the last image in which case it loads next level. what i cant get working is once i load the next image, is just restarting the fade in/out, tried using Splashstyle.reset(); but this just seems to reset values, not restart the fading process.
04/01/2009 (8:02 am)
Thanks for quick reply. What i have is this from TDN:#region Using Statements
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using GarageGames.Torque.Platform;
using GarageGames.Torque.Core;
using GarageGames.Torque.Sim;
using GarageGames.Torque.GUI;
using GarageGames.Torque.MathUtil;
using GarageGames.Torque.T2D;
//using TorqueCombat.Canvas;
#endregion
namespace StarterGame.UI
{
/// <summary>
/// Displays the splash ad for TankBuster, first GUI screen to become visible.
/// </summary>
public class SplashScreen : GUISplash, IGUIScreen
{
//======================================================
#region Constructors
public SplashScreen()
{
// 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 = @"dataimagesYourFileNameHere";
splashStyle.PreserveAspectRatio = true;
//splashStyle.Anchor = AnchorFlags.All;
// set some info for this control
Name = "SplashScreen";
Style = splashStyle;
Size = new Vector2(800, 600); // Changed System.Drawing.SizeF to Microsoft.Xna.Vector2
OnFadeFinished = OnSplashFinished;
// create a black letterbox
// only visible on widescreen displays
GUIStyle lbStyle = new GUIStyle();
lbStyle.IsOpaque = true;
lbStyle.FillColor[0] = Color.Black;
GUIControl letterbox = new GUIControl();
letterbox.Style = lbStyle;
GUICanvas.Instance.LetterBoxControl = letterbox;
}
#endregion
//======================================================
#region Public methods
/// <summary>
/// Callback from the Splashscreen when the splash has finished fading.
/// </summary>
public void OnSplashFinished()
{
//Load the txscene level file
StarterGame.Game.Instance.SceneLoader.Load(@"datalevelsyourlevelfile.txscene"); //Replace this with your own level loading code
//create a renderable canvas for the scene
GUIStyle stylePlayGui = new GUIStyle();
GUISceneview playGui = new GUISceneview();
playGui.Style = stylePlayGui;
//switch over to the new canvas
GUICanvas.Instance.SetContentControl(playGui);
}
#endregion
}
}this only handles 1 image, i was looking for a way to adjust it to support 3 - 4 images, one after the other, I've got code that when it finishes fading out, it loads another image, unless we are at the last image in which case it loads next level. what i cant get working is once i load the next image, is just restarting the fade in/out, tried using Splashstyle.reset(); but this just seems to reset values, not restart the fading process.
#3
then change
then change the public void OnSplashFinished() to
within your game.cs in your public methods add
make sure that somewhere in the game.cs you declare curFadeImg. I have 3 images for the splash so i use
for the rest of the info on getting it working read
http://tdn.garagegames.com/wiki/TorqueX/SplashScreen
04/02/2009 (4:07 am)
just incase anyone else wants to achieve multiple splash fade in's / outs, i evetually did it by changing public SplashScreen()to
public SplashScreen(int ImgNo)
then change
splashStyle.Bitmap = @"data\images\YourFileNameHere";to
splashStyle.Bitmap = @"data\images\" + ImgNo;
then change the public void OnSplashFinished() to
public void OnSplashFinished()
{
Game.Instances.UpdateFade();
}within your game.cs in your public methods add
public void UpdateFade()
{
curFadeImg--;
If(curFadeImg <= 0 )
{
StarterGame.Game.Instance.SceneLoader.Load(@"yourlevel.txscene");
}
else
{
SplashScreen splashScreen = new SplashScreen(curFadeImg);
GUIStyle splashStyle = new GUIStyle();
GUISceneview splash = new GUISceneview();
splash.Style = splashStyle;
GUICanvas.Instance.SetContentControl("SplashScreen");
}
}make sure that somewhere in the game.cs you declare curFadeImg. I have 3 images for the splash so i use
int curFadeImg = 3;
for the rest of the info on getting it working read
http://tdn.garagegames.com/wiki/TorqueX/SplashScreen
Torque Owner Matthew Hoesterey
Personaly I would create something like a SplashControler Class. I'd load that in my game.cs and have the SplashControler class create/fade the splash screens when appropriate.