Did I screw up my copy of T2D? Shouldnt this simple code work?
by John Klimek · in Torque Game Builder · 03/05/2006 (1:50 pm) · 18 replies
I've loaded up the default T2D 1.1 Beta 1.1 and once loaded immediately hit F9 (so I have a somewhat blank screen that only is displaying the black Torque 2D logo). After that I hit tilde (~) to bring down the console and type in the following...
$s = new t2dStaticSprite() { sceneGraph = t2dScene; };
$s.setImageMap(ggLogoImageMap);
$s.setSize("10 10");
$s.setPosition("0 0");
Shouldn't I have a sprite on my screen? I don't get any errors from the above commands but nothing appears on my screen.... *sigh*
$s = new t2dStaticSprite() { sceneGraph = t2dScene; };
$s.setImageMap(ggLogoImageMap);
$s.setSize("10 10");
$s.setPosition("0 0");
Shouldn't I have a sprite on my screen? I don't get any errors from the above commands but nothing appears on my screen.... *sigh*
About the author
Recent Threads
#2
This is really driving me nuts...
I've gotten my sprite to display, but it seems as though position "0 0" is not the middle of my screen... something very strange seems to be going on (or I don't understand something, which is more likely, heh..)
In my game.cs, I have the following line:
To verify this, I run my game and type the following into the console:
This returns:
Ok, so the middle of my screen should be position "0 0", right? Well, in order to get the sprite to the center of my screen I must use position "-32 -25".
Does that make any sense? It would seem as though position "0 0" would be the middle of my screen.....
03/05/2006 (4:20 pm)
Yes, ggLogoImageMap exists... (setImageMap would have errored if it didn't).This is really driving me nuts...
I've gotten my sprite to display, but it seems as though position "0 0" is not the middle of my screen... something very strange seems to be going on (or I don't understand something, which is more likely, heh..)
In my game.cs, I have the following line:
sceneWindow2D.setCurrentCameraPosition("0 0 100 75");To verify this, I run my game and type the following into the console:
echo(sceneWindow2d.getCurrentCameraArea()); echo(sceneWindow2d.getCurrentCameraPosition());
This returns:
-50.000000 -37.500000 49.000000 36.500000 0.000000 0.000000
Ok, so the middle of my screen should be position "0 0", right? Well, in order to get the sprite to the center of my screen I must use position "-32 -25".
Does that make any sense? It would seem as though position "0 0" would be the middle of my screen.....
#3
The joys of game development ;)
Your code should work indeed. Are you sure don't modify the camera's or sprite's position/area after the calls you mentioned?
Are there any forces applied to the sprite, that change its position?
Maybe posting all of your game.cs (if it's not too big) would help.
03/05/2006 (5:26 pm)
Quote:
This is really driving me nuts...
The joys of game development ;)
Your code should work indeed. Are you sure don't modify the camera's or sprite's position/area after the calls you mentioned?
Are there any forces applied to the sprite, that change its position?
Maybe posting all of your game.cs (if it's not too big) would help.
#4
Here is only the relevant part of my game.cs:
As you can see there is really not much going on here... there are no forces being applied or anything like that..
Here is my mainScreenGui.gui in case it matters:
03/05/2006 (5:35 pm)
Could my mainScreenGui.sceneWindow2D have something to do with this? For some reason, my mainScreenGui.sceneWindow2D has an extent of "2912 2184" in the T2D GUI Editor. I've tried to set it to "800 600" and save it, but it seems to go right back to "2912 2184".Here is only the relevant part of my game.cs:
//---------------------------------------------------------------------------------------------
// setupT2DScene
// This function is the starting point for all game specific code.
//---------------------------------------------------------------------------------------------
function setupT2DScene()
{
// Create our scenegraph
new t2dSceneGraph(t2dScene);
// Associate Scenegraph with Window.
sceneWindow2D.setSceneGraph( t2dScene );
// Set the current camera position
sceneWindow2D.setCurrentCameraPosition("0 0 100 75");
// Enable networking debugging messages
$Debug::Networking = true;
// Display splash screen
// TorqueLogoGui.done = 1;
// Canvas.setContent(TorqueLogoGUI);
// schedule(100, 0, checkSplash);
// Initialize message vectors
$GameClient::LobbyMessages = new MessageVector();
$GameClient::GameChatMessages = new MessageVector();
// DEBUG:
$player = new t2dStaticSprite() { scenegraph = t2dScene; };
$player.setPosition("0 0");
$player.setSize( "5 5");
$player.setImageMap( ggLogoImageMap );
}As you can see there is really not much going on here... there are no forces being applied or anything like that..
Here is my mainScreenGui.gui in case it matters:
//--- OBJECT WRITE BEGIN ---
new GuiBitmapCtrl(mainScreenGui) {
canSaveDynamicFields = "0";
Profile = "GuiContentProfile";
HorizSizing = "width";
VertSizing = "height";
position = "0 0";
Extent = "800 600";
MinExtent = "8 8";
canSave = "1";
visible = "1";
internalName = "mainScreenGui";
hovertime = "1000";
bitmap = "~/data/images/custom/background.jpg";
wrap = "0";
new t2dSceneWindow(sceneWindow2D) {
canSaveDynamicFields = "0";
Profile = "GuiContentProfile";
HorizSizing = "width";
VertSizing = "height";
position = "0 0";
Extent = "800 600";
MinExtent = "8 8";
canSave = "1";
visible = "1";
internalName = "sceneWindow2D";
hovertime = "1000";
lockMouse = "0";
useWindowMouseEvents = "1";
useObjectMouseEvents = "0";
};
new GuiTextCtrl() {
canSaveDynamicFields = "0";
Profile = "GuiHeaderTextProfile";
HorizSizing = "relative";
VertSizing = "relative";
position = "729 569";
Extent = "57 14";
MinExtent = "8 2";
canSave = "1";
visible = "1";
hovertime = "1000";
text = "Alpha Version";
maxLength = "1024";
};
};
//--- OBJECT WRITE END ---
#5
This could very well be the reason, I suspect. Try to modify the extent value in a text editor and then launch the game. I have not worked with the GUI to much this sounds very strange at least. What's the resolution of your T2D window? 800x600 ?
03/05/2006 (5:44 pm)
Quote:
Could my mainScreenGui.sceneWindow2D have something to do with this? For some reason, my mainScreenGui.sceneWindow2D has an extent of "2912 2184" in the T2D GUI Editor. I've tried to set it to "800 600" and save it, but it seems to go right back to "2912 2184".
This could very well be the reason, I suspect. Try to modify the extent value in a text editor and then launch the game. I have not worked with the GUI to much this sounds very strange at least. What's the resolution of your T2D window? 800x600 ?
#6
03/05/2006 (5:48 pm)
T2dScene isn't created until you hit Launch->Run Game from the Level Builder menu. So instead of hitting F9 when its loaded, click the Run Game menu option :)
#7
@Matthew: When hit Launch --> Run Game my sprite still doesn't show up... (see the code above) The problem isn't just when I try to manually create a sprite via F9 :(
03/05/2006 (6:24 pm)
@Michael: According to the according .gui file, the t2dSceneWindow extent is 800x600, so apparantly that is what it's using...(the "2912 2184" is just a weird value showing up in the GUI editor). The resolution of my T2D window is 1152x864 (using the Level Editor and going into File --> Options --> Audio/Video tab)@Matthew: When hit Launch --> Run Game my sprite still doesn't show up... (see the code above) The problem isn't just when I try to manually create a sprite via F9 :(
#8
If its in the setupT2DScene() function try putting some echo() or error() statements in there to make sure its being run.
03/05/2006 (6:30 pm)
Hmm... do you run the sprite creation code after you hit Launch --> Run Game ?If its in the setupT2DScene() function try putting some echo() or error() statements in there to make sure its being run.
#9
03/05/2006 (6:32 pm)
ADD: Just adding that since setupT2DScene() is only called when you hit Run Game, so when you fire up the level builder and type "t2dScene.dump();" in the console whithout hitting Run Game it will say the t2dScene doesn't exist.
#10
However, in my case I'm launching T2D.EXE and immediately using Launch --> Run Game.
Here is my revised game.cs, SetupT2DScene function:
My echo statements are successfully being displayed in the console.
Check my screenshot located here.
You can see my sprite in the bottom right corner. The position was set to "0 0" but as you can see it's being drawn way off-screen...
03/05/2006 (6:41 pm)
Gotcha... what you're saying is that t2dScene isn't created until you execute setupT2DScene (eg. Launch --> Run Game). Therefore, you can't simply hit F9 and try to create sprites via the console... right?However, in my case I'm launching T2D.EXE and immediately using Launch --> Run Game.
Here is my revised game.cs, SetupT2DScene function:
function setupT2DScene()
{
// Create our scenegraph
new t2dSceneGraph(t2dScene);
// Associate Scenegraph with Window.
sceneWindow2D.setSceneGraph( t2dScene );
// Set the current camera position
sceneWindow2D.setCurrentCameraPosition("0 0 100 75");
// DEBUG - START Game
echo("About to create sprite!");
$player = new t2dStaticSprite() { scenegraph = t2dScene; };
$player.setPosition("0 0");
$player.setSize( "50 50");
$player.setImageMap( ggLogoImageMap );
echo("Sprite created!");
}My echo statements are successfully being displayed in the console.
Check my screenshot located here.
You can see my sprite in the bottom right corner. The position was set to "0 0" but as you can see it's being drawn way off-screen...
#11
03/05/2006 (6:57 pm)
Hmm, yeah that is weird... just copied your same code and got a big GGLogo in the center of my screen. Let me look into this more.
#12
mattl (at) garagegames.com
03/05/2006 (6:59 pm)
I can look into it more if you zip up your current working directory and e-mail it to mattl (at) garagegames.com
#14
03/05/2006 (7:12 pm)
Just remembered how picky my e-mail was lol, you might need to throw it on some web space and then link it to me =/
#15
03/05/2006 (7:16 pm)
Ok, I sent you an e-mail with the url to the file =)
#16
03/05/2006 (7:38 pm)
Ok found your problem... you have mainScreenGui.gui and a mainScreen.gui. The gui is named "mainScreenGui" so if you change it in the GUI Editor and save it out it defaults to the name "mainScreenGui.gui" but the file thats exec'd is "mainScreen.gui"... so just change it in the GUI editor and browse out and save it in the same place as "mainScreen.gui". You can just click the file you want the name to assume in the file browser :)
#17
Thanks a ton for figuring that out!! ...and sorry for me being such an idiot. :(
I really need to be more careful with the GUI editor... it's really an amazing tool but it does certain things that you wouldn't expect... (for example, no file over-write confirmation :))
Thanks again for the help!!
03/05/2006 (7:47 pm)
After all of that it was something simple...Thanks a ton for figuring that out!! ...and sorry for me being such an idiot. :(
I really need to be more careful with the GUI editor... it's really an amazing tool but it does certain things that you wouldn't expect... (for example, no file over-write confirmation :))
Thanks again for the help!!
#18
Lol yeah file overwrite confirmation would be ideal. Right now we are focusing purely on the Level Builder (the GUI Editor was inherited from TGE) though the Gui Editor is basically just scripts, so you can go in and tweak it if you want, to give you overwrite confirmation, etc.
03/05/2006 (7:49 pm)
No worries, if anything when things like this happens I remind myself its a good thing it was something so simple vs. something major and unpredicatble :) Happens to us all.Lol yeah file overwrite confirmation would be ideal. Right now we are focusing purely on the Level Builder (the GUI Editor was inherited from TGE) though the Gui Editor is basically just scripts, so you can go in and tweak it if you want, to give you overwrite confirmation, etc.
Torque Owner Jason Swearingen
you might try turning the debug flags on for this to see if you see the outline of the sprite's bounding box.