Movement and animation
by Bret Patterson · in iTorque 2D · 05/01/2009 (6:51 am) · 5 replies
I'm trying to have a character walk around on a background and getting some weird visual effects:
1. When the user mouse clicks I call playAnimation()
2. I then call moveTo(targetpos)
about 75% of the time the character moves for a while before the animation starts causing him to slide for a while and then start the walking animation. How can I synchronize these two activities so that he doesn't start moving until the animation is really playing?
BTW. This is all in C++ behavior code.
1. When the user mouse clicks I call playAnimation()
2. I then call moveTo(targetpos)
about 75% of the time the character moves for a while before the animation starts causing him to slide for a while and then start the walking animation. How can I synchronize these two activities so that he doesn't start moving until the animation is really playing?
BTW. This is all in C++ behavior code.
About the author
#2
05/06/2009 (3:14 pm)
There's a mergeTime argument to PlayAnimation() which might be worth investigating. If the directional animations are synced to take the steps in the same order, merging should neatly transition you to the new direction. In theory :)
#3
05/07/2009 (8:04 pm)
I used merge time and it had no effect. It's just a boolean you turn on and as far as I can tell doesn't do anything.
#4
05/08/2009 (6:04 am)
I'm sure TGB handles this somehow. This is a really persistant problem because I can't seem to interrupt an animation mid frame and all my objects like to random "stick" in idle animation for a few seconds while moving. I've tried everything and even looked at the source code. As far as I can tell there isn't a solution for this, however I can't imagine anybody getting any platformers etc working with this kind of problem, but for some reason I can't for the life of me figure it out. Anyone have any ideas?
#5
Play a 4 frame idle animation (4 frames per second) when standing around.
Play a 4 frame walking animation.
When the user clicks on a tile location I use aStar to find the position and then set moveTo on the t2dAnimatedSprite and then call playAnimation("") with a unique animation based on direction.
When onPositionTarget is called I set the animation to idle and then in the next onUpdate() move them to the next location.
When they reach the final location I play the idle animation.
The problem is whenever the character changes direction, north to west for example, they are not quite done with their north animation and they walk north while moving west. Or if the animation is done and the idle animation is play they idle while moving west.
I've tried everything I can think of to "stop" an animation in the middle and start the new one immediately. However the ONLY fix I know of is to create a 1 frame 60FPS transition animations and set to that and then the desired animation and it works great. However this requires TONS of new animations to be created for every transition state of every movable object.
Someone has to have seen this in their game?
05/11/2009 (9:29 am)
Ok this one is becoming a serious pain. I have characters that do the following:Play a 4 frame idle animation (4 frames per second) when standing around.
Play a 4 frame walking animation.
When the user clicks on a tile location I use aStar to find the position and then set moveTo on the t2dAnimatedSprite and then call playAnimation("") with a unique animation based on direction.
When onPositionTarget is called I set the animation to idle and then in the next onUpdate() move them to the next location.
When they reach the final location I play the idle animation.
The problem is whenever the character changes direction, north to west for example, they are not quite done with their north animation and they walk north while moving west. Or if the animation is done and the idle animation is play they idle while moving west.
I've tried everything I can think of to "stop" an animation in the middle and start the new one immediately. However the ONLY fix I know of is to create a 1 frame 60FPS transition animations and set to that and then the desired animation and it works great. However this requires TONS of new animations to be created for every transition state of every movable object.
Someone has to have seen this in their game?
Torque Owner Bret Patterson
This means that you can only switch animation frames every 1 second. This is a problem when you have a character walking from 1 tile to the next and then it changes directions. Because it might be partway through a walking animation for the north direction and need to instantly switch to the west direction.
The only way I've found to fix this is to make the walk animation guaranteed to be slightly less than 1 second, then set it to a 1 frame animation with a 30 frame per second frame rate as a transitionary frame.
This feels very very weird. Can someone explain to me a better way to do this. Essentially I have a character who walks north,east,west,south and moves along a tiled isometric like viewpoint and I can't get smooth animation when he changes directions.