Question about AttachPath Behavior
by Dave Rushton · in Torque Game Builder · 06/21/2009 (12:02 am) · 1 replies
Does anyone know if there is any reason why the AttachPath Behavior wouldn't work on 2dSprites that aren't created when the scene is loaded? All of my other behaviors are working correctly except that one. I am spawing several sprites as the level goes on and attaching behaviors to them. All sprites are spawning as expected just not following the spline. This is the code I am using. It is identical to the sprites I am creating when the scene is loading. Can anyone think of a reason it wouldn't work?
%red = new t2dStaticSprite() {
imageMap = "Red_PackageImageMap";
frame = "0";
canSaveDynamicFields = "1";
useMouseEvents = "1";
Position = %SpawnPosition;// "293.125 25.000";
size = "33.750 30.000";
Layer = "2";
CollisionActiveSend = "1";
CollisionActiveReceive = "1";
CollisionPolyList = "-0.913 -0.536 0.034 -1.000 0.918 -0.403 0.786 0.403 -0.074 1.000 -0.786 0.282";
mountID = "10";
_behavior0 = "TakesDamageBehavior lives 0 respawnEffect None";
_behavior1 = "AttachPathBehaviour path AiPath speed 35.000 direction -1 startnode 1";
_behavior2 = "CountOnDeathBehavior counter scoreObject";
_behavior3 = "MouseDraggableBehavior centerOnMouse 1";
_behavior4 = "ScorePointsBehavior pointValue 100 counter scoreObject";
//_behavior5 = "MoveTowardBehavior object KillZone speed 25.000";//
scenegraph = $whatLevelISThis;
class = Crates;
name = "red";
Layer=1;
%red = new t2dStaticSprite() {
imageMap = "Red_PackageImageMap";
frame = "0";
canSaveDynamicFields = "1";
useMouseEvents = "1";
Position = %SpawnPosition;// "293.125 25.000";
size = "33.750 30.000";
Layer = "2";
CollisionActiveSend = "1";
CollisionActiveReceive = "1";
CollisionPolyList = "-0.913 -0.536 0.034 -1.000 0.918 -0.403 0.786 0.403 -0.074 1.000 -0.786 0.282";
mountID = "10";
_behavior0 = "TakesDamageBehavior lives 0 respawnEffect None";
_behavior1 = "AttachPathBehaviour path AiPath speed 35.000 direction -1 startnode 1";
_behavior2 = "CountOnDeathBehavior counter scoreObject";
_behavior3 = "MouseDraggableBehavior centerOnMouse 1";
_behavior4 = "ScorePointsBehavior pointValue 100 counter scoreObject";
//_behavior5 = "MoveTowardBehavior object KillZone speed 25.000";//
scenegraph = $whatLevelISThis;
class = Crates;
name = "red";
Layer=1;
Vikram Venkatesan
change this portion of the behaviour as follows and it should work:
function AttachPathBehaviour::onAddToScene(%this, %scenegraph)
{
...