How to properly setup a Cocos2D Animation Sequence with repeating animations - animation

what is the recommended approach to playing animation sequences that include as the end-stone a repeating animation. For example, here are a few scenarios:
Sprite appears on screen, play intro animation, then repeat forever an "idle" animation
Sprite with "idle" animation performs some action thus I need to play some other specific animation at the end of which the sprite should start idling again.
CCSequence does not let me do this, as the "idle" animation is wrapped into a CCRepeatForever.
If I simply chose to run whatever animation I like above the idling animation I get frame flickering (looks like both animations are played at the same time) — sucks.
All animations are inside CCAnimationCache ... any advice will be highly appreciated.

I don't know if there is a recommended approach. What I would do is running the second animation (the repeating one) with a delay or by chaining it to the first through the animation completion handler.
An easy way to do the chaining is adding at the end of your first animation a CCCallFunc action, like here, that will call trigger the second animation:
CCActionInterval* action = [CCSequence actions:
[CCProgressFromTo actionWithDuration:duration_ from:100.f to:0.f],
[CCCallFunc actionWithTarget:self selector:#selector(startSecondAction)],
nil ];

Related

How do you get animations in roblox not to overlap

So I am working on a game at the moment and I made an animation that I would like the player to use while walking, I'm having an issue where when the animation plays my character stops moving it's legs and arms. Here is the code that I am using to run the animation, I did not include any variables in it.
AnimTrack = plr.Character.Humanoid:LoadAnimation(Anim)
AnimTrack:Play()
You can't if both animations use the same body parts (even if they do not move them).
The only way to combine animations is to use animations that don't use the same bodyparts (have those disabled which are used by the other animation).
Ideally create your own animations to avoid any unwanted effects.

Unity3d Updating position with animation simultaneously

I have an animation for humanoid models to simulate climbing. I have been looking for a way to stimulate this animation when the model comes next to the window. I used the triggers to determine where the model is and it worked. However, when I execute the animation, the position of the model is not being updated according to the animation. I am using offmesh links and nav mesh agent and I disable nav mesh agent when the model triggers. How can I use the animation and provide the update simultaneously?
Animation Properties
Thanks in advance.
I don't think the animation should take care of the movement. You should control that somewhere else. You could make the animation climb from y = 0 to 5 but then it won't work if your ladder is at y = 3.
You'd better have a method that is called from the animation using AnimationEvent so that when you trigger the animation, it also triggers a movement of the object upwards/downwards regardless of the current position of the object. It would simply use Translate and disabled input until the animation ends.

Unity 3d show specific frame of animation

I'm trying new unity 3d options for 2d games. I'm trying to create background that changes depending on actions i made. So if i press button one i get sprite one as background and if two i get sprite two. Since I have 32 options, I figure out the best way would be to have an Animator, that changes frame depending on button click. So i created animator and animation. But the problem is I can't set time to where to stop animation to show selected frame.
I'm trying like that:
Animator ani=background.GetComponent<Animator>();
ani.animation["field_back_anim"].time=0.5f;
ani.speed=0;
But it fails at second line with that error:
MissingComponentException: There is no 'Animation' attached to the "background" game object, but a script is trying to access it.
You probably need to add a Animation to the game object "background". Or your script needs to check if the component is attached before using it.
However if I do no code the animation just plays trough all 16 frames. So i gues there is animation after all.
On the background GameObject I have 2 components first is sprite renderer and second is animator. When I open animator in Animator view i see there green rectangle saying Any state and yellow one with "field_back_anim". I don't get what i'm doing wrong.
I will also except any other solution that does the following.
Thanks!
The animator component is used to control transition between many animation clips. If you're going to playing an animation clip on a gameobject, an animation component is proper, not the animator. Remove the animator and add an animation component to your background gameobject in the inspector. If you set animation property to field_back_anim, your gameobject will animate well. Manipulation codes should be changed like below.
Animation ani = background.GetComponent<Animation>();
ani["field_back_anim"].time = 0.5f;
ani["field_back_anim"].speed = 0;

Cocos2d How to make/run animation more realistic

Simple Animation - first thought that came up, when 2 objects collided.
For example: Player collides with object Bouncer. What would happen?
Player class start bouncing animation
Bouncer class start self animation to inform user that bouncing started
this is simple animation that looks pretty good but, I have an idea how to add more realism to this and i want to, ask is it really possible to do this?
Let's say same situation player collided with bouncer
Make player invisible
In Bouncer class start animation (animation frames painted with Player and Bouncer motion (e.g preparing for jumping))
in step 2 Players position changed, putting players into position where bouncing animation ended
Make player visible
start Jump
If it is really possible, then i think this will look more realistic. Is there any sample code for this?
Animating anything in Cocos2D can be very time consuming. If you are doing vector/pixel work, you must create a frame for every single change in the animation, which can be very challenging if you don't have much in the way of an artistic background. Might I recommend something like Adobe Flash which will semi-automate the animation process. It has a function to export the animation to frames (individual PNGs), which could be turn into an animation using CCAnimation and some helper classes.
You can create your animation using After Effects, for instance, that generates a set o frames. Then you can use a software like Sprite Helper to embed that animation in cocos2d.
On your project you just have to load it and play it when you need.
http://www.raywenderlich.com/1271/how-to-use-animations-and-sprite-sheets-in-cocos2d

how to draw many CCSprite without slow performance?

I'm making such a arrow shooting game. Everything is good. but I realized if I draw line tracking my arrow, It will be great. so I put some code on my game in my Scheduler that is supposed to draw circle where arrow is going. But I had to draw so many circle, so game frame is not good when I shoot multi arrow.
Is there other better way? I use CCSpriteBatchNode, plist, CCSpriteFrameCache already. I did all I can do. I need help Thanks so much
this is my code
...............
[self schedule:#selector(CollisionDetection:)];
}
- (void)CollisionDetection:(ccTime)dt
{
for (CCSprite *arrow in arrows->arrowsArray)
{
CCSprite *track = [CCSprite spriteWithSpriteFrameName:#"WhiteCircle.png"];
[track setPosition:arrow.position];
[arrows->rootLayer->arrowsSheet addChild:track];
id delete = [CCFadeOut actionWithDuration:1.0];
id deleteAction= [CCSequence actions:delete ,[CCCallFuncN actionWithTarget:self selector:#selector(spriteActionFinished:)], nil];
[track runAction:deleteAction];
.......
The allocation of objects is a large overhead. If your game runs to slow you should consider creating a pool of arrows at the beginning of the game and only trigger the action on it as soon as you need it. If it is not visible anymore just set it to inactive and reuse it the next time you need an arrow.
Sounds like your problem isn't the arrows, but the circles, which I imagine are Cocos objects too. You'd be better off learning how to draw the circle texture directly to the screen using opengl commands instead of objects. That'll help a lot.
When have a time critical animation, i stay clear from CCCallFunc(N), as it can stall the scheduler for a noticeable amount of time. As I read your code, you have a CallFunc at every scheduled interval ... hmmmm. Have you tried running this without the scheduler, ie package and start all your animations at once, with a single CallFunc at the end ? Instead of changing the position as part of the scheduled interval, use a CCMoveTo that you will run at the same time as your tracking animation.

Resources