OnAddToScene and onBehaviorAdd problem
by WesTT · in Torque Game Builder · 02/11/2008 (5:09 am) · 0 replies
Hi there, I have been using the two aforementioned callbacks for setting up a pickup/collection system in a game I am working on, and I think I may have found either a bug or something that is counter-intuitive at the very least, some insight would be greatly appreciated.
I have a pickup that has a 'weaponType' dynamic field and I use this dynamic field to set the correct animation to play when I "cloneWithBehaviors" the object from a spawn point. At this point, the t2dAnimatedSprite object drops down into the playfield. When the object is spawned, it's onAddToScene callback is called and its here I randomize the type of weapon I want the player to receive, I then take this randomized number and create the animation string for the correct animation to set on the object. Observe:
FYI, the pickups look like crates, thus the crate stuff. Later, when the crate hits its bottom world limit, it bounces a couple times then stops. Each time it bounces I set the generated animation string. This works just fine and it plays the correct animation for the weapon type. However, it does *not* play the correct animation for the weapon type selected when the crate iniitally starts falling into the scene. In fact, it seems like after the animation has been set in the behavior something is changing it after, but I have not been able to confirm this. I am thinking this because if I set a scheduled function like so:
to init the crate type after the onAddToScene/onBehaviorAdd callback has complete, the animation is set correctly. Currently, I am quite confused about this as I have wrote many other behaviors and not had this problem.
I have a pickup that has a 'weaponType' dynamic field and I use this dynamic field to set the correct animation to play when I "cloneWithBehaviors" the object from a spawn point. At this point, the t2dAnimatedSprite object drops down into the playfield. When the object is spawned, it's onAddToScene callback is called and its here I randomize the type of weapon I want the player to receive, I then take this randomized number and create the animation string for the correct animation to set on the object. Observe:
%this.owner.setConstantForce(0, 1000); %this.owner.setDamping(2.0); %this.owner.setRestitution(%this.restitution); // 1 to five, as zero is pistol %this.weaponType = getRandom(1, 5); %this.owner.weaponType = %this.weaponType; %this.setCrateAnimation(%this.weaponType);
FYI, the pickups look like crates, thus the crate stuff. Later, when the crate hits its bottom world limit, it bounces a couple times then stops. Each time it bounces I set the generated animation string. This works just fine and it plays the correct animation for the weapon type. However, it does *not* play the correct animation for the weapon type selected when the crate iniitally starts falling into the scene. In fact, it seems like after the animation has been set in the behavior something is changing it after, but I have not been able to confirm this. I am thinking this because if I set a scheduled function like so:
%this.schedule(33, "initCrateType");
to init the crate type after the onAddToScene/onBehaviorAdd callback has complete, the animation is set correctly. Currently, I am quite confused about this as I have wrote many other behaviors and not had this problem.