Question re: Complex Animations
by Rich Marinaccio · in Torque X 2D · 07/11/2007 (9:32 am) · 11 replies
Ok, the tutorials are very clear on how to put an animated sprite in the game and give it some AI and whatever.
What I'd like to know is, how should changes in the animation sequence be handled?
For example, lets say I want a walking animation while my sprite is moving, and a standing animation while its not. Perhaps there could be some random animations thrown in, like picking his nose occasionally while he's standing still.
Do I create separate Animated sprite for each animation, destroying each one that is not in use at the moment? Or should I put all the possible animation frames into a single animation and create a component that decides which *part* of the animation should be played? Do I have that kind of control with an animated sprite?
When you're dealing with tanks or amoebas as in the two tutorials, static sprites or a single animated loop might suffice, but for any character that represents a multicellular lifeform is going to need switchable animations for walking, running, sitting etc. There are probably lots of ways to do it, but I don't want to start re-inventing the wheel, I'd like to get some advice on how this 'should' be done.
What I'd like to know is, how should changes in the animation sequence be handled?
For example, lets say I want a walking animation while my sprite is moving, and a standing animation while its not. Perhaps there could be some random animations thrown in, like picking his nose occasionally while he's standing still.
Do I create separate Animated sprite for each animation, destroying each one that is not in use at the moment? Or should I put all the possible animation frames into a single animation and create a component that decides which *part* of the animation should be played? Do I have that kind of control with an animated sprite?
When you're dealing with tanks or amoebas as in the two tutorials, static sprites or a single animated loop might suffice, but for any character that represents a multicellular lifeform is going to need switchable animations for walking, running, sitting etc. There are probably lots of ways to do it, but I don't want to start re-inventing the wheel, I'd like to get some advice on how this 'should' be done.
#2
07/11/2007 (10:43 am)
I want to know how to do it in code. I'm gonna buy the Platformer Starter kit and check it out. Thanks Stephen!
#3
I don't want to buy anything right now, I just want to see how difficult it will be to accomplish my goals with Torque X. Switching animation is pretty much a requirement in almost any game so I know the problem has been solved, I just want to save myself the trouble of trying to invent my own system only to find out that Torque X doesn't work how I thought it did and I can't do it 'that way'.
I searched a little regarding Thomas and animation but did not find the appropriate thread that deals with the problem area.
07/11/2007 (12:47 pm)
I hesitate to buy the starter kit in order to learn about Torque X. I'm already feeling some buyer's remorse from my TGEA purchase, not that TGEA is a bad product, it's just that the only way to find out what you need to know about it, you have to buy it, as the documentation is not available publicly. After I bought it and examined my options with TGEA, I decided that I should probably go 2D with my next project and probably won't be using TGEA.I don't want to buy anything right now, I just want to see how difficult it will be to accomplish my goals with Torque X. Switching animation is pretty much a requirement in almost any game so I know the problem has been solved, I just want to save myself the trouble of trying to invent my own system only to find out that Torque X doesn't work how I thought it did and I can't do it 'that way'.
I searched a little regarding Thomas and animation but did not find the appropriate thread that deals with the problem area.
#4
When you do the "create animation" step in TXB (i.e. not a T2DAnimatedSprite, but the thing that you would drag into the scene to create a T2DAnimatedSprite) it creates an object of type T2DAnimationData which mostly just holds the sequence of frames in your animation. You can assign objects of this type to the AnimationData property of a T2DAnimatedSprite. You can also update the Material property of a T2DAnimatedSprite if it needs a different set of frames for different animations (and T2DAnimationData object has a Material property that gives you the material it was created to work with).
So basically the workflow is that you create all your animations with the Create a new Animation button in the Create pane. You then drag one of them onto the scene to create your T2DAnimatedSprite. You write some code that controls your animation changes (probably a new component that you write and attach to your T2DAnimatedSprite). That code can assign new T2DAnimationData's to the sprites AnimationData property. You can get T2DAnimationData's by creating properties of that type on your component so you can set them in TXB, or you can do a TorqueObjectDatabase lookup based on their name that you set when you created the Animations.
You might have to do some experiments, and there might be subtleties like animations starting or stopping etc. when you change these properties.
Hopefully that made sense (let me know if it didn't), and will help you get started experimenting.
07/11/2007 (1:28 pm)
@Rich - I don't have time at the moment to go into too much depth, but hopefully I can give you some tips to get you started.When you do the "create animation" step in TXB (i.e. not a T2DAnimatedSprite, but the thing that you would drag into the scene to create a T2DAnimatedSprite) it creates an object of type T2DAnimationData which mostly just holds the sequence of frames in your animation. You can assign objects of this type to the AnimationData property of a T2DAnimatedSprite. You can also update the Material property of a T2DAnimatedSprite if it needs a different set of frames for different animations (and T2DAnimationData object has a Material property that gives you the material it was created to work with).
So basically the workflow is that you create all your animations with the Create a new Animation button in the Create pane. You then drag one of them onto the scene to create your T2DAnimatedSprite. You write some code that controls your animation changes (probably a new component that you write and attach to your T2DAnimatedSprite). That code can assign new T2DAnimationData's to the sprites AnimationData property. You can get T2DAnimationData's by creating properties of that type on your component so you can set them in TXB, or you can do a TorqueObjectDatabase lookup based on their name that you set when you created the Animations.
You might have to do some experiments, and there might be subtleties like animations starting or stopping etc. when you change these properties.
Hopefully that made sense (let me know if it didn't), and will help you get started experimenting.
#5
07/11/2007 (2:31 pm)
Thanks alot Dan, I think that's all I need to know.
#6
I'm fooling around with a few if/then statements in the MovementComponent, just to see if I could get anything to work. I can post that code if your interested; its got 4 directions with animations for each.
However I found quickly there is no simple if/then solution for mapping controller input to player animation.
You have to create a massive State Machine, if you want anything half decent.
I bought the PlatformerStarter. It's got a massive State Machine with audio sync.
Trying to learn C# and learn how their State Machine componentry works at the same time is disgusting.
But for the $ it's incredible really, it's like they are giving away high-end car parts for cheap.
Anyways, can anyone answer this:
If I drag and drop an animated sprite in TXB onto the scene, and do not add a component (so there's no "_sceneObject" to use as a reference), how would I get a refence to that specific Sprite?
It seems that using "TorqueObjectDatabase.Instance.FindObject" creates another instance.
07/16/2007 (8:57 pm)
I'm doing this now as a beginner with some success.I'm fooling around with a few if/then statements in the MovementComponent, just to see if I could get anything to work. I can post that code if your interested; its got 4 directions with animations for each.
However I found quickly there is no simple if/then solution for mapping controller input to player animation.
You have to create a massive State Machine, if you want anything half decent.
I bought the PlatformerStarter. It's got a massive State Machine with audio sync.
Trying to learn C# and learn how their State Machine componentry works at the same time is disgusting.
But for the $ it's incredible really, it's like they are giving away high-end car parts for cheap.
Anyways, can anyone answer this:
If I drag and drop an animated sprite in TXB onto the scene, and do not add a component (so there's no "_sceneObject" to use as a reference), how would I get a refence to that specific Sprite?
It seems that using "TorqueObjectDatabase.Instance.FindObject" creates another instance.
#7
07/16/2007 (10:33 pm)
@Dan - No, the FindObject method just returns a reference to the object you specify by name. If you want to create a new instance based on that reference you would have to Clone() it explicitly.
#8
if I do this
T2DAnimatedSprite mySceneSprite = (TorqueObjectDatabase.Instance.FindObject("myTXBSprite"));
this won't play it- (the database does find the objects though)
mySceneSprite.PlayAnimation(TorqueObjectDatabase.Instance.FindObject("idleSouthAnimation"));
For it to work I have to use the reference that is only available within the MovementComponent
T2DAnimatedSprite mySceneSprite = owner as T2DAnimatedSprite; //in the OnRegister method
Anyway- instead of putting you all through this I'll just do it the way suggested, ie template/clone/component
but this little thing has been bugging me...
07/17/2007 (7:57 am)
But that object that it's referencing will not be the current scene spriteif I do this
T2DAnimatedSprite mySceneSprite = (TorqueObjectDatabase.Instance.FindObject
this won't play it- (the database does find the objects though)
mySceneSprite.PlayAnimation(TorqueObjectDatabase.Instance.FindObject
For it to work I have to use the reference that is only available within the MovementComponent
T2DAnimatedSprite mySceneSprite = owner as T2DAnimatedSprite; //in the OnRegister method
Anyway- instead of putting you all through this I'll just do it the way suggested, ie template/clone/component
but this little thing has been bugging me...
#9
I can change material and see it updated but changing animation data does nothing.
Changing material is not enough for me, I need animations differ for example in number of frames and duration.
Can you provide any code for switching animation data?
08/13/2007 (1:38 pm)
I tried both methods (changing Material and changing AnimationData) and one of them doesn't work.I can change material and see it updated but changing animation data does nothing.
Changing material is not enough for me, I need animations differ for example in number of frames and duration.
Can you provide any code for switching animation data?
#10
if you create a new t2dComponent, or if you are using the exisiting MovementComponent, in the onRegister method use this
_sceneSprite = owner as T2DAnimatedSrite;
_sceneSprite.PlayAnimation(TorqueObjectDatabase.Instance.FindObject("idleSouthAnimation"));
and make sure you declare
T2DAnimatedSprite _sceneSprite;
in the "private fields" section at the bottom
that should do it, also you might want to wrap it in this so that the animation doesn't keep looping on the first frame
if (_sceneSprite.Animation.Name != "idleSouthAnimation")
{
_sceneSprite.PlayAnimation(TorqueObjectDatabase.Instance.FindObject ("idleSouthAnimation"));
}
08/13/2007 (6:56 pm)
Where are you writing your code? if you create a new t2dComponent, or if you are using the exisiting MovementComponent, in the onRegister method use this
_sceneSprite = owner as T2DAnimatedSrite;
_sceneSprite.PlayAnimation(TorqueObjectDatabase.Instance.FindObject
and make sure you declare
T2DAnimatedSprite _sceneSprite;
in the "private fields" section at the bottom
that should do it, also you might want to wrap it in this so that the animation doesn't keep looping on the first frame
if (_sceneSprite.Animation.Name != "idleSouthAnimation")
{
_sceneSprite.PlayAnimation(TorqueObjectDatabase.Instance.FindObject
}
#11
I tried to do something like T2DAnimatedSprite.AnimatedData = otherAnimatedData;
Using T2DAnimatedSprite.playAnimation(otherAnimatedData) works fine
08/14/2007 (1:18 am)
Thanks DanI tried to do something like T2DAnimatedSprite.AnimatedData = otherAnimatedData;
Using T2DAnimatedSprite.playAnimation(otherAnimatedData) works fine
Torque 3D Owner Stephen Zepp
I do remember a couple of threads from Thomas (possibly .plans as well) that also discuss this, you may want to try searching for some various keywords to see what shows up.