Game Development Community

[SOLVED]Spawn of satan ?

by Bob Dobbs · in Torque X 2D · 09/14/2010 (5:49 pm) · 3 replies

I know everyone's probably more worried about the CEV & 4.0 issue at the moment but
anyone handy at spawner or clone issue's ? its 2:41am, I'm tired, I'm lonely, I'm STUCK ! ><

I'm trying to Clone 3 mounted sprites and then change their animations at certain points of gameplay.

When I spawn I do this
T2DAnimatedSprite spawnedEnemyHead = _headSpawnObject.Clone() as T2DAnimatedSprite;
T2DAnimatedSprite spawnedEnemyTorso = _torsoSpawnObject.Clone() as T2DAnimatedSprite;
T2DAnimatedSprite spawnedEnemyLegs = _legsSpawnObject.Clone() as T2DAnimatedSprite;
spawnedEnemyHead.Mount(spawnedEnemyTorso, "Head", true);
spawnedEnemyLegs.Mount(spawnedEnemyTorso, "Legs", true);

Now because they are clones of a template I have to remember to initialise all the animation data otherwise I get invalid animation data errors.

next I register in the torque DB
TorqueObjectDatabase.Instance.Register(spawnedEnemyHead);
TorqueObjectDatabase.Instance.Register(spawnedEnemyTorso);
TorqueObjectDatabase.Instance.Register(spawnedEnemyLegs);

then so they are moving when they get cloned set em up for animation
spawnedEnemyHead.PlayAnimation(_enemyHeadAnim);
spawnedEnemyTorso.PlayAnimation(_enemyTorsoAnim);
spawnedEnemyLegs.PlayAnimation(_enemyLegsAnim);

now the weird thing is in other components when I call any PlayAnimation's only the torso part responds to animations I appear to have all the correct and relevant parts in my CopyTo ( obj2._sceneObjectHead = _sceneObjectHead; etc)

...though I'm not too sure about my _OnRegister

if (!base._OnRegister(owner) || !(Owner is T2DSceneObject))
return false;
_sceneObject = (T2DAnimatedSprite)owner;

how would I register my mounted T2DAnimatedSprites in the On register ?????
(if that's what's required,I've a hunch it is...tell the truth onRegister confuses me mightly someone tell me what it does exactly!?)

Inserting various breakpoints throughout the code while debugging only the "torso" object seems to be accessible in other components, the "leg" and head parts just seem be null.

So either onRegister or perhaps something I'm missing when Spawning ?

Please be kind and help an insomniac.

#1
09/14/2010 (5:56 pm)
OnRegister really doesn't do much of anything, its just a place where you can put lines of code that you only want to execute when your object is registered. Its sort of a chance to do one shot initialization. Where process tick is an every tick thing. (maybe 32 times a second, if you are rendering at maximum.

I'm curious about your animations, have you set them up to cycle, loop, or simply end? That might be the issue, is your animation completes the cycle, and you don't see it because you wanted it to loop?

#2
09/14/2010 (6:06 pm)
Thanks for the fast reply!

Some of them are looped, some of them are not, I set them accordingly when I spawn the object ie the top 3 are "walking" the bottom 3 are dying.
_enemyHeadAnim.Init();
_enemyHeadAnim.AnimationCycle = true;

_enemyTorsoAnim.Init();
_enemyTorsoAnim.AnimationCycle = true;

_enemyLegsAnim.Init();
_enemyLegsAnim.AnimationCycle = true;

_enemyHeadAnimDeath.Init();
_enemyHeadAnim.AnimationCycle = false;

_enemyTorsoAnimDeath.Init();
_enemyTorsoAnim.AnimationCycle = false;

_enemyLegsAnimDeath.Init();
_enemyLegsAnim.AnimationCycle = false;

otherwise I get an assert fatal error with invalid data.

in my Ai component I can change the torso animation no problems
but in my damage component because I am wanting to make changes in animation to all parts when an enemy dies, only the darned torso death animation plays because the Head and Legs Scene Objects appear to be null....

hmmm

It took me half a day to figure out just when the animation data was invalid, now wonder why the hell the sceneobjects are null even though they appear to be spawning ok

if you want mosey look to
www.13hours.net/src/