Referencing sprite object from component
by Kevin Derby · in Torque X 2D · 05/16/2007 (1:10 pm) · 6 replies
Hi all,
I have x number of animated sprites on screen, and all of them have the same component attached to them. In that component I'm trying to handle collisions within the OnCollision delegate, and when I try and access properties of the object, it doesn't work; I'm unable to see them.
I think the problem I can't see the properties is because OnCollision is static, but I'm not sure.
Can anyone offer some insight on this? I've been staring at this too long.. How do others approach this?
I have x number of animated sprites on screen, and all of them have the same component attached to them. In that component I'm trying to handle collisions within the OnCollision delegate, and when I try and access properties of the object, it doesn't work; I'm unable to see them.
I think the problem I can't see the properties is because OnCollision is static, but I'm not sure.
Can anyone offer some insight on this? I've been staring at this too long.. How do others approach this?
#2
I'm referring to my custom property. When I do ourObject.CurDirection it doesn't find the CurDirection property I've created. Shouldn't that be available?
Thanks Modern1
05/16/2007 (2:03 pm)
Yes, setting those properties works just fine. Say if I do ourObject.MarkForDelete = true; it does get deleted.I'm referring to my custom property. When I do ourObject.CurDirection it doesn't find the CurDirection property I've created. Shouldn't that be available?
Thanks Modern1
#3
05/17/2007 (9:44 am)
Kevin, post code of the component and delegate so we can help you better.
#4
The property I'm trying to access:
05/17/2007 (10:35 am)
This is in my GroundEnemyComponent which is attached to a variable number of animated sprites on a level:public static void OnCollision(T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info, ref T2DResolveCollisionDelegate resolve, ref T2DCollisionMaterial physicsMaterial)
{
if (theirObject.TestObjectType(TorqueObjectDatabase.Instance.GetObjectType("floor_blocks")))
{
ourObject.MarkForDelete = true; // this works
ourObject.CurDirection = Direction.right; // this doesn't
}
}The property I'm trying to access:
public Direction CurDirection
{
get { return _direction; }
set { _direction = value; }
}
#5
05/19/2007 (11:27 pm)
The problem is, CurDirection is on the component, not the scene object, but ourObject refers to the scene object that is doing the colliding. You would need something like this:public static void OnCollision(T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info, ref T2DResolveCollisionDelegate resolve, ref T2DCollisionMaterial physicsMaterial)
{
if (theirObject.TestObjectType(TorqueObjectDatabase.Instance.GetObjectType("floor_blocks")))
{
ourObject.MarkForDelete = true; // this works
ourObjectsComponent = ourObject.Components.FindComponent<GroundEnemyComponent>(); // find that component on the object
ourObjectsComponent.CurDirection = Direction.right; // this should work now
}
}
#6
05/21/2007 (7:08 am)
Ahhh...Thanks Graham for clearing that up for me! That bit of code works great.
Torque 3D Owner Will O-Reagan
Modern Intrigues