Accessing a method from another component
by Viktor Rumanuk · in Torque X 2D · 12/20/2007 (12:27 pm) · 6 replies
So I have two components right now, the default movement component and a drum component. I want to bind my command in the movement component and have it access a method in the drum component. But the movement component does not recognize the method. The method is set to public.
Thanks, Viktor
Thanks, Viktor
#2
12/20/2007 (6:20 pm)
Thanks Joshua this seems like it will help me a lot but I can't test it because both components are not on the same object. I figured I would use T2DSceneGraph.Instance.FindObjects()to find the closest object. Only T2DSceneGraph now contains no Instance. I have this working fine in the airplane tutorial, and they both have the same using directives. I might suspect that it was changed with the update if not for it working fine in another project. I'll keep trying to figure out what's going on.
#3
12/20/2007 (7:28 pm)
Ahh, sorry I haven't had any experience with the beta yet.
#4
12/21/2007 (7:40 am)
Well I looked in the API and it doesn't seem like it has been updated yet (atleast not for this method). I think that it works in the airplane tutorial because I haven't converted it.
#5
T2DSceneObjects now have a SceneGraph property that you can use to find the scenegraph that an object is in.
12/21/2007 (9:40 am)
Yes, 1.5 added the ability to have multiple scenegraphs (which is cool) but we didn't update the docs to reflect this (not so cool).T2DSceneObjects now have a SceneGraph property that you can use to find the scenegraph that an object is in.
#6
12/21/2007 (10:05 am)
Thanks Dan that helped me out immensely. This is working now: private void AttackInit()
{
List<ISceneContainerObject> Drums = new List<ISceneContainerObject>();
T2DSceneGraph sg = (T2DSceneGraph)_sceneObject.SceneGraph;
sg.FindObjects(_sceneObject.Position, 20, TorqueObjectType.AllObjects, 0xFFFFFFF, Drums);
foreach (T2DSceneObject Drum in Drums)
{
DrumComponent dc = Drum.Components.FindComponent<DrumComponent>();
dc.Attack();
}
} I bind this method to the spacebar and it calls the method that is in the drum component.
Torque Owner Joshua A. Thomas
If both components are on the same object, you could say...