TorqueX/SplashScreen
From TDN
|
[edit] Introduction
[edit] Materials NeededYou will need the following materials in order to complete this tutorial.
[edit] Creating the Splash ScreenFollow these steps to create the splash screen for your game. 1. Add the 800x600 image to your data/images folders and make sure you have imported it into Visual C# Express. 2. Create a new file called SplashScreen.cs and copy/paste this into it:
#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 = @"data\images\YourFileNameHere";
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(@"data\levels\yourlevelfile.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
}
}
3. Edit YourFileName here with the name of your splash screen image file. 4. Open up the Game.cs file. Add the following changes to display the splash screen: In top of the file, add this line to the list of 'using' clauses: using GarageGames.Torque.GUI; In Private, Protected, Internal Methods in the BeginRun method after base.BeginRun(); add this:
// go to splash screen
SplashScreen splashScreen = new SplashScreen();
GUIStyle splashStyle = new GUIStyle();
GUISceneview splash = new GUISceneview();
splash.Style = splashStyle;
GUICanvas.Instance.SetContentControl("SplashScreen");
GraphicsDevice.VertexDeclaration = new VertexDeclaration(GraphicsDevice, VertexPositionColor.VertexElements);
This initializes the Splash Screen and displays it. [edit] Platformer Starter kitIf you are using the Platformer Starter kit replace OnSplashFinished method code with the following in the SplashScreen.cs file PlatformerStarter.Game.Instance.SceneLoader.Load(@"data\levels\sample_level.txscene"); GUIStyle playStyle = new GUIStyle(); GUISceneview play = new GUISceneview(); play.Name = "PlayScreen"; play.Style = playStyle; GUICanvas.Instance.SetContentControl(play); PlatformerDemoGUI.Instance.GUI.Folder = GUICanvas.Instance; This loads the sample_level file (change this to match your file) and initializes a new GUI that sticks the camera to the player [edit] Credits--Dro Sarhadian If there are any errors please let me know so I can fix them ASAP. |



