Game Development Community

Understanding T2DSceneGraph

by Kareem Glover · in Torque X 2D · 11/10/2009 (10:35 pm) · 2 replies


Okay the background. Currently I'm doing a Bejeweled remake to become familar with the code. I've created the board and have 81 sprite objects labeled as gamePiece with objectType as typeGamePiece.

gamePiece[i] = new T2DStaticSprite();
                gamePiece[i].Name = "gamePiece" + i;
                gamePiece[i].Visible = false;
                gamePiece[i].Material = TorqueObjectDatabase.Instance.FindObject<GarageGames.Torque.Materials.RenderMaterial>("green_jewelMaterial");
                gamePiece[i].Size = new Vector2(5, 5);
                gamePiece[i].Layer = 1;
                gamePiece[i].ObjectType = typeGamePiece;
                
                TorqueObjectDatabase.Instance.Register(gamePiece[i]);

When ran this produces the game grid. Now I want to start testing if the game recognizes that there is a typeGamePiece in a certain quadrant. Let says 0,0.

List<ISceneContainerObject> foundObjects = new List<ISceneContainerObject>();
            Vector2 location = new Vector2(20, 0);
            T2DSceneGraph mySceneGraph = TorqueObjectDatabase.Instance.FindObject<T2DSceneGraph>("DefaultSceneGraph");
            mySceneGraph.FindObjects(location, 1.0f, typeGamePiece, 0xFFFFFFFF, foundObjects);
            if (foundObjects.Count == 1)
            {
                Debug.WriteLine("Object Found! ");
            }
            else
            {
                Debug.WriteLine("Damn!");
            }

The problem with that is FindObjects is always zero no matter what position I set location. I know there is something that I am not understanding fully.

-Kareem

#1
11/11/2009 (2:20 pm)
Kareem,

I don't think FindObjects is what your looking for as it does a Radial search for objects (On Screen and in Screen space i believe)
per the documentation:

Find object in scene container within the given search radius and matching the specified object type and layers.

Param(s)
pos: Center of search radius.
radius: Radius of search.
findTypes: Object types to match.
layerMask: Layers to match.
list: List which will contain results. Note: list is not cleared.

So in your case your looking a a circle at X:20 y:0 with a radius of 1.
#2
11/11/2009 (8:34 pm)
Hrmm I was able to get it to work by using TorqueObjectType.AllObjects and then search the list. I was under the impression that I could define a TorqueObjectType gamepiece then under my T2DStaticSprite assign x.ObjectType += gamepiece. After that I was trying to do a FindObject search on gamepiece.

mySceneGraph.FindObjects(playerPiece.Position, 1.0f, TorqueObjectType.AllObjects, (uint)0xFFFFFFFF, foundObjects);