Behavior Bugs: Spawn Area, Random Velocity etc.
by Spider · in Torque Game Builder · 07/26/2007 (2:16 pm) · 7 replies
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.
A quick fix for now is to add the line
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.
A quick fix for now is to add the line
%clone.onAddToScene(%this.owner.scenegraph);to the very end of the SpawnAreaBehavior::spawn function in spawnArea.cs
#2
At the bottom of the for loop in spawnOnRemove.cs in the function SpawnOnRemoveBehavior::spawnChildren, add the following line:
That fixes it.
08/03/2007 (5:46 pm)
It was the same problem! It was just from a different behavior.At the bottom of the for loop in spawnOnRemove.cs in the function SpawnOnRemoveBehavior::spawnChildren, add the following line:
%newObject.onAddToScene(%this.owner.scenegraph);
That fixes it.
#3
08/03/2007 (9:09 pm)
Nice... yeah I caught that the other day, too. Shoulda pre-emptively posted here:)
#4
08/25/2007 (5:41 pm)
Thanks for this one guys. Its totally appreciated. This was bugging the hell out of me for ages.....just updated my little tgb almost 100% behaviours game ....its alive again ..yay!
#5
When I apply the suggested fix to the SpawnOnRemove.cs, the behaviors only get passed along to the first object spawned -- in other words, if I have the "asteroid" fragment into four pieces, only one of the four will actually inherit the next behaviors (for example, Random Angle) and fly off; the others just appear in place and won't move or trigger their other behaviors (for example, Contrail). This is annoying, the Space Invaders, Breakout and Galalaga games I programmed for my students as examples are now all broken as behaviors; I'll have to just do them as scripts, but that makes them inaccessible to the nonprogrammers in the class.
08/26/2007 (8:00 pm)
Not quite solved!When I apply the suggested fix to the SpawnOnRemove.cs, the behaviors only get passed along to the first object spawned -- in other words, if I have the "asteroid" fragment into four pieces, only one of the four will actually inherit the next behaviors (for example, Random Angle) and fly off; the others just appear in place and won't move or trigger their other behaviors (for example, Contrail). This is annoying, the Space Invaders, Breakout and Galalaga games I programmed for my students as examples are now all broken as behaviors; I'll have to just do them as scripts, but that makes them inaccessible to the nonprogrammers in the class.
#6
All three of the spawned fragments in the Asteroids demo seem to be working properly to me. Be sure the new code is entered INSIDE the for loop.
08/26/2007 (8:05 pm)
I'm not sure what the problem is Michael.All three of the spawned fragments in the Asteroids demo seem to be working properly to me. Be sure the new code is entered INSIDE the for loop.
#7
08/26/2007 (8:53 pm)
Yes, it is in the loop. I'm also having an issue with the "shoots" behavior, which I should just re-write anyway. As it stands, even with the bounding box of the projectile object set to KILL, the behavior has no cleanup function and just seems to either fill up the schedule queue or generate a max number of sprites and just stops shooting after a while. In the case of some of the games it is a short while. I'll keep experimenting (and trash my DSOs)
Torque Owner Deozaan
Thanks for the tip! I wondered why GG would release a new version demonstrating the new behavior system with a broken demo.
Adding that line to the end of the function made the big asteroids appear just fine, but when I shoot them and the smaller ones spawn, they don't move at all. They just sit where they spawned. Sounds like the same problem but obviously it's not since adding that line didn't fix the small ones.
Got any tips for this?