How to Properly change scenes in iTorque 2D (Solved)
by Daniel Liverance · in iTorque 2D · 05/19/2011 (1:32 pm) · 1 replies
Hello.
I just recently started to use iTorque 2D and torque script, and I am growing quite fond of it.
I made a game that has 3 scenes for now. I have buttons on each scene that call a torque script "onMouseUp" function for each button.
In each function I change to a different scene.
I am able to change scenes using:
I was wondering if this is the proper way to change scenes in torque script?
also, a problem arises after a random amount of time using this method:
If I change between 2 different scenes, back and forth, eventually the game will just crash when I click the button.
sometimes it even loads the 3rd scene even though I did not click the button to do so.
any help on this issue would be greatly appreciated!
-------------------------- EDIT -----------------------
so after 4 hours of programming, I FINALLY think that fixed the issue.
it seems that you CANNOT call sceneWindow2D.loadLevel inside ANY callback function (maybe I was just being a noob)
so instead I did this:
and it SEEMS to have solved the crashing / changing to the wrong screen issue.
BUT it is impossible to prove a negative (prove something NEVER happens) so I will keep testing and change the title to this thread to solved
IF this is the proper way to change scenes AND I do not encounter another error of the same sort.
I just recently started to use iTorque 2D and torque script, and I am growing quite fond of it.
I made a game that has 3 scenes for now. I have buttons on each scene that call a torque script "onMouseUp" function for each button.
In each function I change to a different scene.
I am able to change scenes using:
sceneWindow2D.endLevel();
sceneWindow2D.loadLevel("game/data/levels/LEVELNAME.t2d");I was wondering if this is the proper way to change scenes in torque script?
also, a problem arises after a random amount of time using this method:
If I change between 2 different scenes, back and forth, eventually the game will just crash when I click the button.
sometimes it even loads the 3rd scene even though I did not click the button to do so.
any help on this issue would be greatly appreciated!
-------------------------- EDIT -----------------------
so after 4 hours of programming, I FINALLY think that fixed the issue.
it seems that you CANNOT call sceneWindow2D.loadLevel inside ANY callback function (maybe I was just being a noob)
so instead I did this:
function loadLevel(%levelName)
{
schedule(31, 0, "_loadLevel", %levelName);
}
function _loadLevel(%levelName)
{
sceneWindow2D.endLevel();
sceneWindow2D.loadLevel("game/data/levels/" @ %levelName @ ".t2d");
}and it SEEMS to have solved the crashing / changing to the wrong screen issue.
BUT it is impossible to prove a negative (prove something NEVER happens) so I will keep testing and change the title to this thread to solved
IF this is the proper way to change scenes AND I do not encounter another error of the same sort.
About the author
I am 21 years old, and have just recently graduated from College for Game Programming (with honours) and I am now the Lead Programmer at Blinker Studios.
Torque Owner Richard Skala
Pixel Vandals Inc.