Game Development Community

Behavior Playground Asteroids Solution

by Deozaan · in Torque Game Builder · 10/14/2007 (1:16 am) · 0 replies

In the Behavior Playground Asteroids level you will find that there are no asteroids when you play the game. This is because there is a bug (or two) in the behaviors that control the spawning of the asteroids.

Quote:When an object is cloned with obj.cloneWithBehaviors, the cloned object does not have its onAddToScene callback called. Among other effects, this makes the Spawn Area functionality quite limited right now, because although the spawned objects appear properly, their initialization is not run.

An example effect is that the Random Velocity behavior no longer works for spawned objects. You can see this in full effect by loading the asteroids.t2d level in behaviorPlayground... the asteroids never appear. They ARE there, just outside the screen edge... they just don't move onto the screen.

The solution is to add a couple of lines of code to the behaviors that are misbehaving:

In spawnArea.cs, at the very end of the function SpawnAreaBehavior::spawn add this line:

%clone.onAddToScene(%this.owner.scenegraph);

And in spawnOnRemove.cs at the end of the function SpawnOnRemoveBehavior::spawnChildren add this line:

%newObject.onAddToScene(%this.owner.scenegraph);

And the Asteroids demo should now be working properly.