Game Development Community

Mount / unmount question

by Rich Hudson · in Torque X 2D · 01/10/2009 (12:03 am) · 2 replies

Guys what am I doing wrong here:

if (selectedObj != null)
{
selectTemplate = TorqueObjectDatabase.Instance.FindObject("selectMonsterTemplate");
if (_targetSelectorObject != null)
{
//We have an old selected object so unselect it
T2DSceneObject mountedObject = _targetSelectorObject.GetMountedObject("SelectPoint");
mountedObject.Dismount();
_targetSelectorObject.Manager.Unregister(mountedObject);
mountedObject = null;
}
_targetSelectorObject = selectedObj;
_targetSelector = (T2DAnimatedSprite)selectTemplate.Clone();
_targetSelectorObject.Manager.Register(_targetSelector);
_targetSelector.Mount(_targetSelectorObject, "SelectPoint", false);
}

basically when i select an object I want to mount a selection image animation effect to it. when they select another object I then want that one "selected" with the animation (I get it from a template). But it doesn't work as posted above (I have tried other things as well). The first time it runs through it mounts the selection effect on the first object, but when I then select the second one, the selection animation shows up offscreen where the template resides....in other words even though it shows that its mounted, the animation shows up where its template is...

any ideas?

#1
01/10/2009 (11:21 am)
Hi Rich:

EDIT: I'd check this post also, seems that in the topic of the post they were trying to do the same thing: http://www.garagegames.com/mg/forums/result.thread.php?qt=82198

I'm not familiar with mounting / unmounting objects, however I did see something that may be an issue but I'm not sure:

if (selectedObj != null)
{
	selectTemplate = TorqueObjectDatabase.Instance.FindObject<T2DSceneObject>("selectMonsterTemplate");
	if (_targetSelectorObject != null)
	{
		//We have an old selected object so unselect it
		T2DSceneObject mountedObject = _targetSelectorObject.GetMountedObject("SelectPoint");
		mountedObject.Dismount();
		_targetSelectorObject.Manager.Unregister(mountedObject);
		mountedObject = null;
	}
	_targetSelectorObject = selectedObj;
	_targetSelector = (T2DAnimatedSprite)selectTemplate.Clone();
	_targetSelectorObject.Manager.Register(_targetSelector);
        [b]//Shouldn't this be _targetSelectorObject.Mount(...) ? Otherwise it seems we're mounting the selected    object onto the selector animation.[/b]
	_targetSelector.Mount(_targetSelectorObject, "SelectPoint", false);
}

Also is there a reason that you need to make the selector a template? It would seem easier to just have a T2DAnimatedSprite object that continuously gets dismounted and mounted rather then also destroying / creating and registering / unregistering objects.
#2
01/10/2009 (8:35 pm)
Thanks for the post.

1) No the way you have the mount is actually backwards - seems counterintuitive but thats the way it works.

2) This is what I ended up doing. I have many different colored selectors depending on the objects selected (enemies = red, neutral = yellow, merchants = blue, etc..).

In the end I just created one of each and mount/unmount it as appropriate.


I read that post and I think the issue might have been I did not have a physics component on the selectObject. I DID however try turning that Pool with Components off before reading the post as I thought that might be an issue.

Thanks again for the reply.