Spawn a New Enemy
by CharlesL · in iTorque 2D · 01/29/2013 (6:59 am) · 7 replies
Hi everyone,
This is sort of a noob question, but I can't figure out how to spawn a new enemy. Here is my current code:
Thanks,
Charles
This is sort of a noob question, but I can't figure out how to spawn a new enemy. Here is my current code:
function spawner::onLevelLoaded(%this, %scenegraph);
{
%enemy = new enemy();
%scenegraph.addToScene(%enemy);
}I'm trying to spawn a new object with the class of enemy. I looked around on the forum, but I still can't understand.Thanks,
Charles
#2
01/29/2013 (9:50 am)
OK, that clears some things up, but how do I define the class on a t2dStaticSprite?
#4
01/29/2013 (10:46 am)
OK, thanks! I think that works... do I use %enemy.addToScene(%scenegraph), or do I use %scenegraph.addToScene(%enemy). Neither one seems to work.
#5
01/29/2013 (10:55 am)
It should be %scenegraph.addToScene(%enemy). Don't forget you need to set it's position, imageMap, and size.
#6
01/29/2013 (11:28 am)
That works! Thanks!
#7
01/29/2013 (9:29 pm)
To improve performance, make sure you're loading all of your enemies when the level loads. If you spawn a new enemy during gameplay you'll probably see the game hitch for a second.
Employee Michael Perry
ZombieShortbus
What is the enemy class? Is that something you added to the source code? If not, you need to use a t2dStaticSprite or t2dAnimatedSprite instead.