Game Development Community

two scenegraphs?

by rennie moffat · in iTorque 2D · 03/31/2011 (11:59 am) · 17 replies

I have a map, where the locations are tappable. If one taps a location, up comes an info sheet. Easy enough. Problem is, I also have zoom on the map. So if one zooms out, currently the info sheet, will shrink in size as well. I don't want this. I am wondering how I can create two views so that the info sheets stay at one zoom setting while the map is flexible in this regard.


I created two scenegraphs and placed the info sheet in one, but of course that did not work. How can I separate the views and the effect of camera zoom on them?

About the author

My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.


#1
03/31/2011 (4:12 pm)
You can place a second t2dscene in your mainScreen.gui file. I know the forum post is floating around somewhere.
#2
04/01/2011 (4:49 am)
http://www.garagegames.com/community/forums/viewthread/80145/1


thanks.
I will look into this.
The one thing that gets me tho is how do I place objects in one and not the other as it seems this new "backgroundLevel" in the example is called at the startGame() and sits there till the game is exited? Idk, just my thoughts.

Thanks.
#3
04/01/2011 (7:53 am)
You have to create two separate levels, load one in each sceneGraph, then push the sceneGraphs to the same window.
#4
04/01/2011 (8:11 am)
If I recall, only the top most scenegraph will receive mouse updates, so be careful when layering scenegraphs.
#5
04/01/2011 (12:12 pm)
I think there's something about a pass-through in one of those posts but I'm unsure.
#6
04/01/2011 (6:18 pm)
Upon some reading.. cant I just create a single .t2d with 2 scenegraphs? I can not see how I can load 2 .t2d's into one window.






#7
04/01/2011 (9:34 pm)
You need to load two different t2ds. It isn't very hard. First you need to add a second scene window in your mainScreen.gui file. Normally, that file just has this:

%guiContent = new GuiControl(mainScreenGui) {
   canSaveDynamicFields = "0";
   isContainer = "1";
   Profile = "GuiDefaultProfile";
   HorizSizing = "width";
   VertSizing = "height";
   Position = "0 0";
   Extent = "480 320";
   MinExtent = "480 320";
   canSave = "1";
   Visible = "1";
   hovertime = "1000";
   
   new t2dSceneWindow(sceneWindow2D) {
      canSaveDynamicFields = "0";
      isContainer = "0";
      Profile = "GuiDefaultProfile";
      HorizSizing = "width";
      VertSizing = "height";
      Position = "0 0";
      Extent = "480 320";
      MinExtent = "480 320";
      canSave = "1";
      Visible = "1";
      tooltipprofile = "GuiDefaultProfile";
      hovertime = "1000";
      lockMouse = "0";
      useWindowMouseEvents = "1";
      useObjectMouseEvents = "1";
   };
};

Anyway, add another scene window by adding another entry. In my case, I wanted a hud scene, so I added this before the last brace:

new t2dSceneWindow(hudWindow) {
      canSaveDynamicFields = "0";
      isContainer = "0";
      Profile = "GuiDefaultProfile";
      HorizSizing = "width";
      VertSizing = "height";
      Position = "0 0";
      Extent = "480 320";
      MinExtent = "480 320";
      canSave = "1";
      Visible = "1";
      tooltipprofile = "GuiDefaultProfile";
      hovertime = "1000";
      lockMouse = "0";
      //change these next two values to 0 to pass through mouse events to next scene
      useWindowMouseEvents = "1";
      useObjectMouseEvents = "1";
   };

Then, open up game.cs and edit the startGame function to load your second scene after the first:

sceneWindow2D.loadLevel(%level);  //in game.cs by default
   hudWindow.loadLevel("game/data/levels/hudScene.t2d"); //added to load second scene


As someone else mentioned, the last scene loaded will catch your mouse events, unless you set the last two values in the mainscreen.gui file (which I commented above) to 0.

Hope that helps. I can confirm that this worked for me. My regular scene moved around with the player character while the hud stayed in place.
#8
04/01/2011 (9:51 pm)
Great,
thank you Joe. So with this, there is no need for camera mount too. Thats amazing, but what about zoom? Will zoom only be applied to the one level? Also, if this, second level is in startGame(), how can I set it so that it only appears on selected levels?





Cheers, your a big help.
#9
04/01/2011 (11:46 pm)
I don't know about selected levels, unfortunately. You may be able to move the loadlevel call for your second scene to the onLevelLoaded call of an object in the levels where you need it. I'd play around with it a bit. I believe camera zoom is applied specifically for the scenegraph, so it will only affect the scene in which it is called. As long as you aren't calling zoom in the second scene, then that one shouldn't zoom.
#10
04/02/2011 (4:05 am)
Great thanks again, I will be playing with it soon enough and I will let you know how it goes.


Cheers.
#11
04/05/2011 (12:18 pm)
QUESTION:




Ok, so I have two scenegraphs up and functioning however. One appears to be stretched. My game is set to portrait. The new gui is set to 480 x 320, however so is the native scenewindow2D.


:?

Thanks
Ren
#12
04/05/2011 (12:33 pm)
edit.
#13
04/06/2011 (4:04 pm)
You may need to set the new gui to 320 x 480 since you're using portrait. I could be wrong, though. I only used my code for landscape and didn't see the problem you're describing.
#14
04/06/2011 (4:12 pm)
It is weird tho. My sceneWindow2D is 480x320. And looks fine. I believe when I set my HUDScreen to 320x480, it crashed. I will be looking into this more later.


Thanks.



#15
04/09/2011 (11:59 am)
I am still dealing with this and have not found a solution. My second scenegraph after my sceneWindow2D is still showing landscape/

please heeelp.

I have done all possible combinations of the gui's and their dimensions to no avail.
What Giveth?!


//--- OBJECT WRITE BEGIN ---
%guiContent = new GuiControl(mainScreenGui) {
   canSaveDynamicFields = "0";
   isContainer = "1";
   Profile = "GuiDefaultProfile";
   HorizSizing = "width";
   VertSizing = "height";
   Position = "0 0";
   Extent = "480 320";
   MinExtent = "480 320";
   canSave = "1";
   Visible = "1";
   hovertime = "1000";
   modal = false;

   new t2dSceneWindow(sceneWindow2D) {
      canSaveDynamicFields = "0";
      isContainer = "0";
      Profile = "GuiDefaultProfile";
      HorizSizing = "width";
      VertSizing = "height";
      Position = "0 0";
      Extent = "480 320";
      MinExtent = "480 320";
      canSave = "1";
      Visible = "1";
      tooltipprofile = "GuiDefaultProfile";
      hovertime = "1000";
      lockMouse = "0";
      useWindowMouseEvents = "1";
      useObjectMouseEvents = "1";
      modal = false;
   };
   
    new t2dSceneWindow(levelSelectInfoSheet) {
      canSaveDynamicFields = "0";
      isContainer = "0";
      Profile = "GuiDefaultProfile";
      HorizSizing = "width";
      VertSizing = "height";
      Position = "0 0";
      Extent = "480 320";
      MinExtent = "480 320";
      canSave = "1";
      Visible = "1";
      tooltipprofile = "GuiDefaultProfile";
      hovertime = "1000";
      lockMouse = "0";
      useWindowMouseEvents = "1";
      useObjectMouseEvents = "1";
      modal = false;
   };  

};
//--- OBJECT WRITE END ---
#16
04/09/2011 (4:25 pm)
Have you adjusted the code in game/main.cs 'function initializeProject()'?

#17
04/09/2011 (4:58 pm)
I did not. But I just tried a few variations with no results.



what I tried...
. add in my custom window (after mainScreen and sceneWindow)
..result: level will not load
.//out the landscape calls
..result: no effect


Not sure what else to try