Game Development Community

Creating/removing an object.

by Bo Powell · in TGB Platformer Kit · 11/20/2008 (4:55 pm) · 2 replies

I have this cannon, it shoots a fireball every so often at the player...

How do I get it to spawn the fireballs using the following:
datablock t2dSceneObjectDatablock(FireballTemplate)
{
        AnimationName		        = "FireballAnimation";
	Class 			  	= "Fireball";
	Size 			  	= "4.000 4.000";
	Layer 			  	= "1";
	_Behavior0 		  	= "FireballBehavior";
};

So far I have this:
%Fireball = new t2dSceneObject()
	{
		datablock     = FireballTemplate;
		Scenegraph    = %this.Scenegraph;
	};

But I don't know if that even creates the fireball, let alone where it appears if it does create.

Also...How would I remove the fireball when it hits something, I assume using the onCollision function, but I don't know what to put in it. I tried safeDelete, but it didn't seem to work.

#1
11/20/2008 (5:17 pm)
Oooooh, very close!

%Fireball = new t2dSceneObject()
{
    config = FireballTemplate;
    Scenegraph = %this.Scenegraph;
};

How do you handle the collision response in your behavior? To delete the underlying object, you will need to do something like this:

function FireballBehavior::onCollision(%ourObject, %theirObject, %ourRef, %theirRef, %time, %normal, %contacts, %points)
{
    // Do the explody stuff here
    
    // Delete the fireball
    %ourObject.Owner.safeDelete();
}
#2
11/20/2008 (5:22 pm)
Config, eh.

So, where does the object appear, after it's been created?

~Thanks. ^^