Game Development Community

Clone problem

by Iain Craig · in Torque Game Builder · 08/17/2007 (4:50 am) · 5 replies

Hi all,

I'm playing with the 30-day TGB trial.

I have a sprite, class mite. A member function:
function mite::reproduce(%this)
{
   %baby = new t2dAnimatedSprite()
   {
     scenegraph = %this.scenegraph;
     layer = %this.layer;
     class = mite;
   };
   
   %baby.setPosition (-20, -12); // Temporary: Move it out the way
}
The onAdd of %baby gets called correctly, but whatever I do I can't get the new object to actually display.

Any ideas?

#1
08/17/2007 (4:53 am)
Further to my previous, if I get an instance of my mite and clone it (eg 1307.clone(); in console), the copy appears as it should but it's onAdd doesn't get called - fair enough, if it's an absolute clone of the current state of the source object - but the clone also doesn't respond to mouse events, although the source object does.

I'm just looking for a way to spawn from code.
#2
08/17/2007 (5:20 am)
More research :)

I tried removing the reproduce function and in the level editor, creating one mite named MasterMite.

Then I added a new sprite and gave it the Spawn Area behaviour from the BehaviourPlayground tutorial, and told it to clone the MasterMite.

It clones the mite fine, but again I'm unable to get them to respond to mouse events.

Any solution greatly welcomed; all I need is to be able to spawn these little blighters from code and my random Friday GID is back on track!!
#3
08/17/2007 (10:02 am)
Sorted - when creating a t2dAnimatedSprite like that, I needed to specify the animation:

function mite::reproduce(%this)
{
   %baby = new t2dAnimatedSprite()
   {
		animationName = "miteAnimation";
		scenegraph = %this.scenegraph;
		layer = %this.layer;
		class = mite;
   };
   
   %baby.setPosition (-20, -12); // Temporary: Move it out the way
}

Back to GID'ing.
#4
08/19/2007 (5:21 pm)
Hey Iain, do you know where you could get the scenegraph information if you didn't have a master-mite to copy it from? I'm trying to do something similar but I'm trying to create something without a "parent"..
#5
08/20/2007 (3:18 pm)
From another thread, if you don't have another object to get the scenegraph from you can use:

scenegraph = SceneWindow2D.getScenegraph();