I've got a bug, who wants to figure out what it is?
by Chase Webb · in Torque 2D Beginner · 09/14/2014 (3:05 am) · 5 replies
Hello people with actual understanding of T2D's engine code. I've got another puzzler here, which I think lies in one of two places: The position setting for the Scenewindow, or the getRes() function. Another alternative would be something to do with using multiwindow function. What I'm actually trying to do is make a nice dynamically sizing secondary window within my main scene (it's a necessary evil of how my level creation for my game works).
Here's what you need to know to test it:
First, the piece of script that primarily calls upon the two windows when setting up the scenes:
The LevelBuilder's SceneWindow file is the standard script from either the tutorial or the sandbox (I forget which, they're probably the same either way).
The GameCore Scene Window script looks like this though:
As you can see, I've replaced the Position and extent lines from the original (which essentially was set to have about a 100 pixel border of the LevelBuilder scene, and worked fine until I started having to change the resolution - which began when I started testing on android devices and altering the window size on Windows). The goal of this is to have a 30% border of LevelBuilder Scene around 70% of the window, which is the GameCoreScene. As it is set now the extent loads correctly, and the Y position loads correctly, but the X Position does not.
If I start changing the other values for extent and position it appears to affect the output of everything. If I place static values they work appropriately. I need to be able to have the GCSceneWindow be created so that it always is 70% of the X and Y of the main SceneWindow, because that will be the easiest way to make it the correct proportions on a variety of mobile devices.
Any idea why my X Position seems to keep resetting to 0?
Here's what you need to know to test it:
First, the piece of script that primarily calls upon the two windows when setting up the scenes:
function LevelBuilder::create( %this )
{
exec("./scripts/scenewindow.cs");
exec("./scripts/scene.cs");
exec("./scripts/controls.cs");
LevelBuilder::createSceneWindow();
exec("./gui/guiprofiles.cs");
/////Blah blah a bunch of other script files load here, but they're irrelevant at this point)
LevelBuilder::createScene();
LBSceneWindow.setScene(LBScene);
// Add it as a child window.
LBSceneWindow.add( GCSceneWindow );
// Add window to the toy so it is destroyed.
LevelBuilder.add( GCSceneWindow );
//hideSplashScreen();
LevelBuilder::reset(%this);
}The LevelBuilder's SceneWindow file is the standard script from either the tutorial or the sandbox (I forget which, they're probably the same either way).
The GameCore Scene Window script looks like this though:
function GameCore::createSceneWindow()
{
%positionX = getres().X*0.15;
%positionY = getres().Y*0.15;
%extentX = getres().X*0.7;
%extentY = getres().Y*0.7;
echo("position is " SPC %positionX SPC %positionY);
echo("position original is " SPC getres().X*0.15 SPC getres().Y*0.15);
echo("extent is " SPC %extentX SPC %extentY);
// Sanity!
if ( !isObject(GCSceneWindow) )
{
// Create the scene window.
new SceneWindow(GCSceneWindow) {
Profile = GuiDefaultProfile;
//Position = getres().X*0.15 SPC getres().Y*0.15;
//Extent = getres().X*0.7 SPC getres().Y*0.7;
};
GCSceneWindow.setPosition(getres().X*0.15, getres().Y*0.15);
GCSceneWindow.setExtent(getres().X*0.7, getres().Y*0.7);
echo("Position is " SPC GCSceneWindow.getPosition() SPC " and Extent is " SPC GCSceneWindow.getExtent());
}
//Note that the SceneWindow's camera defaults to the following values, you could omit them entirely and
//obtain the same result.
//Default Version
GCSceneWindow.setCameraPosition( 0, 0 );
GCSceneWindow.setCameraSize( 100, 75 );
GCSceneWindow.setCameraZoom( 1 );
GCSceneWindow.setCameraAngle( 0 );
}As you can see, I've replaced the Position and extent lines from the original (which essentially was set to have about a 100 pixel border of the LevelBuilder scene, and worked fine until I started having to change the resolution - which began when I started testing on android devices and altering the window size on Windows). The goal of this is to have a 30% border of LevelBuilder Scene around 70% of the window, which is the GameCoreScene. As it is set now the extent loads correctly, and the Y position loads correctly, but the X Position does not.
If I start changing the other values for extent and position it appears to affect the output of everything. If I place static values they work appropriately. I need to be able to have the GCSceneWindow be created so that it always is 70% of the X and Y of the main SceneWindow, because that will be the easiest way to make it the correct proportions on a variety of mobile devices.
Any idea why my X Position seems to keep resetting to 0?
#2
Thanks!
09/15/2014 (7:08 pm)
Wow.... for some reason your code fixed it. I had to add the % marks to the variables at the end, but now it actually loads correctly. I wonder what was wrong with how I coded it originally. :/Thanks!
#3
Anyway, I've discovered that sometimes you just have to do it the long way - I guess Torque gets confused sometimes, maybe an issue in the parser....
09/15/2014 (7:11 pm)
lol - wow, didn't even notice I had skipped the %.... Anyway, I've discovered that sometimes you just have to do it the long way - I guess Torque gets confused sometimes, maybe an issue in the parser....
#5
09/16/2014 (8:34 am)
@Richard: lol man, that's the funniest .gif I've seen in awhile...thanks!
Torque Owner Richard Ranft
Roostertail Games
GCSceneWindow.setPosition(getres().X*0.15, getres().Y*0.15); GCSceneWindow.setExtent(getres().X*0.7, getres().Y*0.7); // decompose to individual steps - %res = getres(); echo(" --- resolution: " @ %res); %xPos = %res.x * 0.15; %yPos = %res.y * 0.15; %xExt = %res.x * 0.7; %yExt = %res.y * 0.7; GCSceneWindow.setPosition(%xPos, %yPos); GCSceneWindow.setExtent(%xExt, %yExt);I know that doesn't help, but it lets you step through the code and see what's going on.<EDIT>
I don't know why, but for some reason I thought this was related to Android builds....
<EDIT AGAIN>
Forgot some % marks....