Transitioning From a Intro theora, cutscene etc to auto loading your level
by michael bailey · 03/12/2009 (10:11 pm) · 8 comments
Alrighty lets get going, our objective is to transition from an intro to loading a level. very simple.
in main.cs in your game folder add this!
THIS IS VERY important its how we are going to determine if the video is done. Make sure to put this at the top of your main.cs file.
your gui for your move should resemble this in some way.
i named this startupgui , theoraFile = movie etc etc. im sure you know this if you are looking at how to transition. the next part is Very important. Remember still in our gui file we are goin to add a function attached to our Intro named theora ctrl.
see how i set the GLOBAL introDone to true take note in that line.
now we are going to go to our game.cs file and finish things off.
with the name SceneCheck and the class of sceneChecker. thats right 1 object. this little object is whats going to control our if video is done.
Intro.loopCheck(); < is the function we added to our gui file remember? Yeah i thought you'd notice that :) if our check function sees its not done playing it schedules an event to fire rerunning the check ever 1 seconds.
so there you go simple or KISS . you could add in all kinds of things to this for a library of videos looping whatever looping would just be as simple as calling the video to play when it checks done.
my first resource so any comments are appreciated
Michael
in main.cs in your game folder add this!
//---------------------------------------------------------------------------------------------
// Torque Game Builder
// Copyright (C) GarageGames.com, Inc.
//---------------------------------------------------------------------------------------------
$introDone=false;
//---------------------------------------------------------------------------------------------
// initializeProject
// Perform game initialization here.
//---------------------------------------------------------------------------------------------
function initializeProject()
{
// Load up the in game gui.
exec("~/gui/mainScreen.gui");
exec("~/gui/startupGui.gui");
// Exec game scripts.
exec("./gameScripts/game.cs");
// This is where the game starts. Right now, we are just starting the first level. You will
// want to expand this to load up a splash screen followed by a main menu depending on the
// specific needs of your game. Most likely, a menu button will start the actual game, which
// is where startGame should be called from.
startGame( %bleh );
}
//---------------------------------------------------------------------------------------------
// shutdownProject
// Clean up your game objects here.
//---------------------------------------------------------------------------------------------
function shutdownProject()
{
endGame();
}
//---------------------------------------------------------------------------------------------
// setupKeybinds
// Bind keys to actions here..
//---------------------------------------------------------------------------------------------
function setupKeybinds()
{
new ActionMap(moveMap);
//moveMap.bind("keyboard", "a", "doAction", "Action Description");
}THIS IS VERY important its how we are going to determine if the video is done. Make sure to put this at the top of your main.cs file.
$introDone=false;YES you have to exec both of these
exec("~/gui/mainScreen.gui");
exec("~/gui/startupGui.gui");Why? well we are going to have a intro level and you can NOT load the level with out including mainScreen.gui nuff said?your gui for your move should resemble this in some way.
%guiContent = new GuiControl(startupGui) {
canSaveDynamicFields = "0";
isContainer = "1";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "0 0";
Extent = "640 480";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
new GuiControl(theContainer) {
canSaveDynamicFields = "0";
isContainer = "1";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "1 1";
Extent = "634 477";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
new GuiTheoraCtrl(Intro) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "0 0";
Extent = "800 600";
MinExtent = "8 2";
canSave = "0";
Visible = "1";
hovertime = "1000";
theoraFile = "~/data/videos/Comp1.ogv";
done = "0";
stopOnSleep = "0";
backgroundColor = "0 0 0 255";
};
};
};i named this startupgui , theoraFile = movie etc etc. im sure you know this if you are looking at how to transition. the next part is Very important. Remember still in our gui file we are goin to add a function attached to our Intro named theora ctrl.
function Intro::loopCheck(%this){
echo("check");
if(%this.done==true){
echo("this movie is done");
$introDone=true;
}
else
{
echo("continuing looping");
}
}ok you can see where im going with this. echos are debuging purposes.see how i set the GLOBAL introDone to true take note in that line.
now we are going to go to our game.cs file and finish things off.
function startGame(%level)
{
error("entering game start");
Canvas.setContent(startupGui);
Canvas.setCursor(DefaultCursor);
Canvas.hideCursor();
new ActionMap(moveMap);
moveMap.push();
$enableDirectInput = true;
activateDirectInput();
enableJoystick();
sceneWindow2D.loadLevel("game/data/levels/intro.t2d");
SceneCheck.checkIntro();
}
function sceneChecker::checkIntro(){
Intro.loopCheck();
if($introDone==true){
Canvas.setContent(mainScreenGui);
Canvas.setCursor(DefaultCursor);
$enableDirectInput = true;
activateDirectInput();
enableJoystick();
Intro.Visible = false;
sceneWindow2d.endlevel();
sceneWindow2D.loadLevel("game/data/levels/level1.t2d");
Canvas.showCursor();
}else{
error("not done");
SceneCheck.schedule(1000, "checkIntro");
}
}
//---------------------------------------------------------------------------------------------
// endGame
// Game cleanup should be done here.
//---------------------------------------------------------------------------------------------
function endGame()
{
sceneWindow2D.endLevel();
moveMap.pop();
moveMap.delete();
}the "magic" of this is our intro level has just 1 scene object added.with the name SceneCheck and the class of sceneChecker. thats right 1 object. this little object is whats going to control our if video is done.
Intro.loopCheck(); < is the function we added to our gui file remember? Yeah i thought you'd notice that :) if our check function sees its not done playing it schedules an event to fire rerunning the check ever 1 seconds.
so there you go simple or KISS . you could add in all kinds of things to this for a library of videos looping whatever looping would just be as simple as calling the video to play when it checks done.
my first resource so any comments are appreciated
Michael
#2
03/13/2009 (2:55 am)
Very nice. I'll have to give this a try.
#3
03/13/2009 (5:23 am)
How kind of you to share this. +1 for the nice guys.
#4
03/13/2009 (7:58 am)
def. seems interesting, book marked.
#5
03/13/2009 (10:00 am)
Great first resource Michael! Thank you!
#6
How do you modify it so that you can have:
1. TGB Splashscreen
2. Main Menu
3. -First Cut Scene-
4. Game Play
5. -Ending Cut Scene-
I tried to do a poor man's Video Intro>Game Play>Last Video, but the intro's code seems to block out my Theora code that would play a video but wouldn't end it which wouldn't matter at the end of the game because the player would just close the window.
The fact that I'm mainly a graphic designer, and not a coder doesn't help.
03/16/2009 (8:51 am)
The resource works great!How do you modify it so that you can have:
1. TGB Splashscreen
2. Main Menu
3. -First Cut Scene-
4. Game Play
5. -Ending Cut Scene-
I tried to do a poor man's Video Intro>Game Play>Last Video, but the intro's code seems to block out my Theora code that would play a video but wouldn't end it which wouldn't matter at the end of the game because the player would just close the window.
The fact that I'm mainly a graphic designer, and not a coder doesn't help.
#7
@Path
I'm trying to do the same thing, though I'm overwhelmed with other project at the moment. Will try it in a couple of days and if I make it work will get back to you.
Thanks again Michael! =)
03/18/2009 (6:24 pm)
Great resource, exactly what I was looking for!@Path
I'm trying to do the same thing, though I'm overwhelmed with other project at the moment. Will try it in a couple of days and if I make it work will get back to you.
Thanks again Michael! =)
#8
I don't mean to pester, but could you provide the code for how to run theora in the following example:
splash.t2d
menu.t2d
cutScene1.t2d (first theora video)
game.t2d
cutScene2.t2d (second and final theora video)
I've been trying to mod your above code for the past month but can't get it to work.
The actual game level, etc. is done, I just need to add in these two theora cut scenes to finish it.
Or at least suggest the best way to find out the code (website/book/etc.)
04/11/2009 (1:36 pm)
Michael,I don't mean to pester, but could you provide the code for how to run theora in the following example:
splash.t2d
menu.t2d
cutScene1.t2d (first theora video)
game.t2d
cutScene2.t2d (second and final theora video)
I've been trying to mod your above code for the past month but can't get it to work.
The actual game level, etc. is done, I just need to add in these two theora cut scenes to finish it.
Or at least suggest the best way to find out the code (website/book/etc.)
Torque Owner John E. Nelson
Suspicious Activity
Thanks for posting it!