CompositeSprite Sprite handle question
by Eero Karvonen · in Torque 2D Beginner · 01/10/2014 (8:14 am) · 6 replies
Hi!
I'm planning a character whose bodyparts are supposed to be represented by different sprites of a CompositeSprite, and I need to give an external finite state machine the access to change the animations in the individual Sprites.
Is there a way to directly access the object handle of an individual Sprite in a CompositeSprite?
If there is no short-cut to do so, I guess I have to give the FSM the sprite index, so it can directly operate on the CompositeSprite changing animations.
I'm planning a character whose bodyparts are supposed to be represented by different sprites of a CompositeSprite, and I need to give an external finite state machine the access to change the animations in the individual Sprites.
Is there a way to directly access the object handle of an individual Sprite in a CompositeSprite?
If there is no short-cut to do so, I guess I have to give the FSM the sprite index, so it can directly operate on the CompositeSprite changing animations.
#2
<edit>
Alas, SpriteBatchItem was intended to be exceedingly lightweight and so does not inherit from SceneObject - so can't be used as a pointer in Con::executef(SimObject*, S32, ...).
So perhaps we can call it against the CompositeSprite and pass an ID with it to help us sort things out? Not very elegant....
01/10/2014 (1:16 pm)
Adding an onAnimationEnd() callback to SpriteBatchItem might just do the trick - SpriteProxyBase is the parent of SpriteBatchItem and SpriteBase and is the originator of the call to the onAnimationEnd() callback when the animation controller completes (in SpriteProxyBase::update()).<edit>
Alas, SpriteBatchItem was intended to be exceedingly lightweight and so does not inherit from SceneObject - so can't be used as a pointer in Con::executef(SimObject*, S32, ...).
So perhaps we can call it against the CompositeSprite and pass an ID with it to help us sort things out? Not very elegant....
#3
The documentation advises against "mounting" sprite objects with joints (since that way no "rigid connection" can be achieved). But what if I used a weld joint and set all the attached object's shapes as sensors? I don't see why it wouldn't work for this purpose as no physics would ever interfere with the attached object. Sounds "un-Box2d-ish", but I'm running out of options.
01/16/2014 (8:40 am)
Richard, does your suggestion imply modifying the engine?The documentation advises against "mounting" sprite objects with joints (since that way no "rigid connection" can be achieved). But what if I used a weld joint and set all the attached object's shapes as sensors? I don't see why it wouldn't work for this purpose as no physics would ever interfere with the attached object. Sounds "un-Box2d-ish", but I'm running out of options.
#4
I'm experimenting with this, but I haven't made much progress - pretty busy and haven't got the time to really dig in.
<edit>
To clarify, I'm experimenting with onAnimationEnd() callbacks for SpriteBatchItems.
01/16/2014 (10:03 am)
Yeah, an engine change is required. The "sprites" in a CompositeSprite object are not the same as the Sprite objects you use in your scene - they're a vastly stripped-down version that has no "scene-related" properties; they rely on the CompositeSprite object for all of their "substance" except their asset, really. The idea was to make them very lightweight and they are - at the expense that you can't really do much with them directly.I'm experimenting with this, but I haven't made much progress - pretty busy and haven't got the time to really dig in.
<edit>
To clarify, I'm experimenting with onAnimationEnd() callbacks for SpriteBatchItems.
#5
01/16/2014 (12:51 pm)
To answer the original question at least - you can use setSpriteName and selectSpriteName to refer to individual objects in a composite.
Torque Owner Eero Karvonen
I'm running out of ideas on how to circumvent this issue, since I read all over the place that the only solid way of attaching sprites together is using CompositeSprite.