Animation Corresponding to UITimer - ios

I am coding a game in Swift where the player has to make a move within a second, or else time runs out and he/she loses. How can I make an animation that runs every second, resembling the one in the top of Snapchat stories, where it is a filled in circle that slowly "wipes" away in a circular motion like a windshield wiper? Is it just a second-long GIF that I loop every second? Is there a way to do this with native UIKit graphics?

I think what you are looking for is a "clock wipe" animation. You can do that by adding a mask layer to your image and animating it using Core Animation.
I wrote a SO post on this very subject:
How do you achieve a "clock wipe"/ radial wipe effect in iOS?

Related

How to dissolve nodes in SpriteKit?

I have 2 SKSpriteNode objects, and I want to crossfade them.
One of the easiest way is to create a fadeOut SKAction and a fadeIn SKAction, and apply them to the SKSpriteNode objects. But the problem of this approach is that during the action both of them have the alpha under 1.0, which looks not so good.
For example, I'd like to dissolve the red square SKNode to a green round SKNode
If just fade out the red square and fade in the green round during the action it'll look like this
So you can see background through these 2 objects. I hope to dissolve these 2 objects like this:
In UIKit I can use UIView.transitionWithView but in SpriteKit I only found a similar method for presenting scenes (SKViewObject.presentScene: transition:). So is there anyway to make a dissolve transition for SKNodes?
There's little you can about the background coming through when adjusting the alpha settings on both nodes. A possible hack could be to temporarily insert a solid node in front of your background but behind both other nodes until the action is done. At which point you remove it.
The node should be in the shape of both nodes cross-section (pardon the sloppy artwork on my part):
I searched a lot for this question and I nearly decided to use a shader to do this kind of dissolve (since you can directly edit the pixel in a shader), but then I found that there's an unusual way to solve this problem. It may not be useful for every situation, but if your background doesn't do things like scroll or zoom, this approach may be the easiest. In simple words, just create a screenshot for the current screen and display it at the top, then change your node to the sprite you need, and at last fade out the screenshot you took.
So at first you have to make sure all the nodes are in the correct node tree. Then use SKViewObject.textureFromNode(rootNode) to create the screenshot, make a sprite node from this texture, and add it to your screen. Then, you can create the fade out SKAction to fade out this screenshot sprite. You may also remove it when the action ends.
Using this approach, during the fade out the screen will just look like this:

Watchkit animation implementations: clock face, animated charts, circular progress bar

I've seen some very basic demos of potential watchkit apps, and some appear to implement animations. Examples might be:
A clock face with a moving second hand or even minute hand.
A bar chart with bars that animate in, or who shape changes with new real-time data.
A circular progress bar who's bar animates from zero to the current value.
The only way I've seen so far to do animations is by a sequence of images over a duration:
[imageView startAnimatingWithImagesInRange:NSMakeRange(0, 60) duration:1.0 repeatCount:0];
How would these previous animation examples generally be implemented? I can't imagine they are all done with image sequences. I don't think one can even layer images, and coordinating placement would be a nightmare.
They are all done with sequences of images. Here is some code for how I animate movement on a map. Is it possible to position views on top of each other
Edit
You may also find these frameworks helpful.
https://github.com/frosty/Flipbook
https://github.com/radianttap/WatchRingGenerator
2nd Edit
Here is another great article on adding animation into your Watch App. http://david-smith.org/blog/2015/03/04/ailw-adding-bits-of-liveliness/

How to implement alternating colours animation on iOS

I've designed a custom indicator View for my application which consists of a row of 10 circles. The indicator indicates the progress of a task and the closer the task is to finishing, the more circles are filled. I would like to add two very basic animations to this indicator and, because this is my first iOS application, I'm not sure what the best way to implement them is.
Animation 1: While the task progress information is being fetched from the server, I want each dot to change color (from black to blue) in succession.
Animation 2: Let's say I get that a task is 80% complete from the server, I want to change the color of the first 8 dots from black to green with a decreasing delay.
My question is, is it okay to implement these animations in drawRect: or is there a more standard way of implementing something like this.
Thanks!
I wouldn't use drawRect: at all for this UI. I would create the circles using a UIShapeLayer with a circle for its path, and do the animations with
animateKeyframesWithDuration:delay:options:animations:completion; this method allows you to add animations for the individual circles (using addKeyframeWithRelativeStartTime:relativeDuration:animations:) with whatever delay and relative duration you need between the keyframes.

On iOS, how can smooth animation be achieved?

Is it true that for Angry Birds or Cut the Rope, they draw the whole frame of the whole screen first (the whole view), and then paint the whole frame onto the screen, making the animation smooth?
That's because if we animate a metal ball, of size 20 x 20 pixel, and if we erase the ball first, and then draw the ball at a new location, then there might be some flickering very subtle but noticeable.
The same might be if it is animated by drawRect, which will erase the whole screen, and then draw everything in their new locations, which might have even more flicker than above?
Going back to the drawing whole frame method: if a ball was at coordinate (100,100), and now the ball is painted on top of the whole screenshot (with the new background exposed), at coordinate (103, 100), then it is very unnoticeable for the changes. (no disappearing and then reappearing happening at all).
How can smooth animation be achieved that looks like Angry Birds or Cut the Rope game?
They make use of OpenGL, which is a lot faster than any of the Quartz methods (ie. drawRect) since it makes use of the GPU instead of the CPU for rendering. Using Quartz can be hundreds or thousands of times slower depending on what you are doing exactly.
If you do not want to resort to OpenGL. You can put the object inside a UIView and then animate it. As long as the contents of the view is static, this is plenty fast for most applications. For example, making the background a view, and the metal ball a view, you can move that view around and achieve very smooth animations without problems.
Use CALayers. They are more lightweight than views.
If an app uses OpenGL, the answer is yes, it does its rendering before the frame buffer is presented to the screen. I think the other ways to draw to the screen use the same technique of drawing to an off-screen buffer before transferring the completed image to the screen, but I'm not so sure about that.

How Can I Animate The Significant Blurring of a Sprite

I am using Cocos2d on the iPad to create a small game. I would like to, purposely, significantly blur a sprite, and then fade it out.
Particularly, I was hoping to make a sprite containing text get blurry (like the ink was fading or soaking into the paper) and then ultimately disappear, as if by magic.
I know how to animate the fade process using Cocos2D actions.
How can I animate the process of a sprite becoming super blurry?
I do not think it is possible to do a blur effect with the default cocos2d actions/functions.
you might want to try this custom gaussian blur class out instead
http://www.cocos2d-iphone.org/forum/topic/6315
the code is in the middle of the thread
or a more troublesome alternative is to create the blur effect using frame by frame animation

Resources