Game Development Community

Spawn or cloning AnimatedSprite

by Juan Javier · in Torque Game Builder · 12/04/2012 (10:44 pm) · 5 replies

Hello,

I'm trying to cloning an AnimatedSprite (enemy) multiple times with a schedule.

I have my class, and my onLevelLoaded function, in there I got this:
...
%this.schedule(%this.timeDelaySpawn(), %this.spawnClone());
...

timeDelaySpawn() just returns a number, and spawnClone() is where I'm not pretty sure of what should I write.

What I want is just to put 1 object, and start spawning in random positions more of these... so the number of enemies would be increasing.

For example:
When I start to play there would be 1 enemy, after X seconds there would be 2 enemies, after more seconds there would be N enemies...


Currently I can only spawn 1 enemy (or respawn) and clone it (total enemies = 2).

Is there a way to clone the object multiple times, or do I need to create a new t2dAnimatedSprite every X seconds? How is it done?

Thanks in advance (=

About the author

Recent Threads


#1
12/05/2012 (5:00 am)
Depending on how many you'd want, but you can just loop through the spawn function itself to create multiple instances.

So.. in your example, you could add to your spawnClone() function...

function spawnClone(%enemy)
{
  for(%i = 0, %i<$Spawn;%i++)
  {
     %enemy = new t2dAnimatedSprite ...
  }
  $Spawn++;
}

You'd probably want $Spawn set at 1 initially, and you could always change it from ++ (increment by 1), to += $Spawn (thus increasing exponentially each time: 1->2->4->8 etc..)
#2
12/05/2012 (7:12 am)
Juan, it does sound like you are asking for how to make number of enemies increase exponentially. From a game design perspective, this is completely untenable. I don't think you want 65536 enemies after 16 seconds. An arithmetic progression would be much more suitable but still probably too much.

If you have no easy way of spawning enemies apart from copying them from an existing enemy, have the first enemy stay off the edge of the screen and just exist to have copies made of him. Then send his clones to fight, like star wars, or something. Learn how to programmatically create enemies, though for your purposes, cloning might be the best solution.
#3
12/05/2012 (3:03 pm)
Hmm. For the spawnpoint behavior in Psk there is such a function.
#4
12/14/2012 (5:09 pm)
This should not even work -
%this.schedule(%this.timeDelaySpawn(), %this.spawnClone());

It should be:
%this.schedule(%this.timeDelaySpawn(), spawnClone); // you can also surround spawnClone with quotes

See the docs for schedule.
#5
12/14/2012 (6:30 pm)
Thanks for all your replies, I did it like Doc308 told, but after reading Kevin James I fixed it to fit more what I was looking for.

Everytime the player killed an enemy it would respawn again (offscreen) and clone itself (almost same code that Doc308, but just one clone not N)

And well, it's working not exactly well but it fits perfect to what I was looking.

Thanks to the other ones that replied, I will try more in some spare time. But for now it's okay.

Thanks :D