How do I make animations in an iPad app? - iphone

I'm developing an application for iPad.
I want to make nice animations so that I can beautify my application.
For example, there are 4 main buttons/images in a view.
When tapping on one of them, a few more buttons/images will branch out.
It's like the 'parent button' will branch out to few 'child buttons'.
How are these kind of animations done?
Are there any good references or code snippets to refer to?
Thanks.

A good stating point would be the Core Animation demo's here:
https://github.com/neror/CA360
Run them in the iOS Simulator and checkout the code that creates the magic.
UIView animations would also be suitable for your example, and are a little easier to implement. There is a nice tutorial here:
http://www.raywenderlich.com/2454/how-to-use-uiview-animation-tutorial

Search on the term "Core Animation iOS" on your favorite search engine. You'll find information from Apple's Developer Central site, particularly the Core Animation Guide and Cookbook.

There are actually 2 main methods.
One is to use Core Animation, if it contains your desired path and animation.
The other is to use an animation game loop, where the app periodically calls a routine to redraw the view every frame time. An NSTimer or CADisplayLink can periodically (say at 24 or 30 or 60 Hz) call a routine doing a setNeedsDisplay, which then causes the view's drawRect to be called, etc. The some other periodic code can change some state (moving some X Y button positions, etc.) during or between each frame to provide the appearance of movement or other animation effect, when the view is redrawn. Or OpenGL can be used to redraw some animated 3D world as things move. You can even have each frame change in response to user input. This is the most flexible way to animate, and allows you to customize animations in ways that are impossible for Core Animation, but it uses more power and can be so CPU intensive as to be a lot slower than Core Animation as well.

Related

endless vertical scrolling background

I want to make an endless vertical scrolling layer that gives the impression that the main character is moving upwards. I have been brainstorming on how to achieve this.
My issue is that I want objects to appear as if they are coming from above and below the screen at the same time. Secondly, I want to be able to move the main character to create and destroy box2d joints between it and some of the objects appearing on the screen. What is the best way to achieve this with consuming too much memory? I would appreciate any help on this.
Apple did a wonderful tutorial of this in a WWDC 2011 video session. It was "UITableView Changes, Tips & Tricks" and it's about 35m40sec into the video.
Since the use of the UITableView is really just a UIScrollView for the purposes of the background, you could just use a UIScrollView and you can either have it move on timer or events as needed.
Think of your player as moving within a stationary bounding box. The background can scroll using the aforementioned pooling method (as the background tile scrolls off the screen it is placed into a pool, and before a new tile is instantiated the pool is checked for available reusable tiles). Thirdly, your enemy objects will simply approach from either the bottom of the screen or the top.
Imagine your idea without the scrolling background (flying effect) and you should find that the problem is relatively straightforward.
I also needed and endless scrolling background layer. This can do exactly that, and it is super simple to set up and use. Just copy the four files in to the cocos2d folder in your project, then follow the quick tutorial seen on the github. Make sure the image you use is seamless (when you line them up vertically you can't tell where one ends.

Continuous drawing with Quartz? frame by frame possible?

I've been working on custom drawings using drawRect in UIView subclasses. That's cool, but you have to wait until the end of the run loop for drawRect to be called and I'm wondering how you can control frame by frame animations where you change the drawings over time, or if this is possible? Perhaps Quartz isn't really designed for this type of animated graphics? I gather that perhaps it is designed for static drawings that don't change so frequently.
Quartz by itself its not able to sustain a high frame rate, due to its need to redraw everything each time. But you can have Quartz work together with CoreAnimation to have Quartz based animations. The idea behind this is that you can cache previously drawn content inside CALayer objects and then use CoreAnimation to create the continuous drawing effect.
A good example of this technique can be see in the AccelerometerGraph sample code provided by Apple. Inside this sample the UIView subclass that uses this technique is the "GraphView" object. Basically this object draws as completely new only a portion of the graph (the newly generated segments), backs it in a dedicated layer and then animates the layers in order to provide the "scrolling graph" animation.
Clearly this technique works only when you have full control of the drawing elements and can manage this incremental way of adding objects in the screen. Of course things become much more complicated when you must redraw many different parts of the screen and you need to modify previously generated layers.
Anyway have a look at the mentioned code: it is quite interesting.
Your app should exit to the run loop before each frame. Do all your custom frame animation setup between each frame. So frame-by-frame drawing in drawRect should work just fine. This can work in iOS apps at a 60 Hz frame update rate, not just for static views, as long as all your methods between frame times, as well as your drawRects, are fast enough. Chop them up if needed.

iPhone Word Game like Scrabble / Wordfued / Rummi

I am in process of creating a multiplayer game similar to the Scrabble / Wordfued / Rummi. I am trying to see what would be best way go about implementing the UI and their interactions.
I would be having a framework which would keep track of all the pieces on the board and the AI for knowing if it is a valid move.
I am trying to figure out what could be best solution to handle the UI part. The game board would be larger than would the current iPhone screen could support. So the board would have an effect of a scroll view. The same goes for the game tiles using which user can play. These are not fixed amount of tiles/cards and the same could be more in numbers which would also need another scroll view kind of effect.
There would be many more effect's were the user can move a complete set of tiles/cards from the board and place it in another location of the board. Or even a tile in between the set of tiles on the board.
So I am trying so see if I should go with two scroll view provided by iOS and handle all the detaching the tile/card from one scroll view and placing the same in GameBoard scroll view
Or
Should I go with something like cocos-2d which provides more advance game UI handling capabilities.
Please do let me know your thoughts and feedback on what could be the best choice for the same. Thanks in advance for all your help.
Words With Friends uses native UIKit views. It is quite simple and uses a transition to move between the two degrees of magnification (close up and not close up).
You can do everything quickly in UIKit with a UIScrollview. You can use drag events to move tiles around the screen, even changing their perspective/look during dragging. Using UIAnimation would allow you to do simple frame based animation for things like dropping a tile.
Cocos2d will be quicker if you already know a similar gaming library. However if you choose it you you'll miss out on using Interface Builder and a lot of conveniences in UIKit.
If you're starting from a base of zero with either approach, then only use Cocos2d if you want particle effects (like stars and sparkles, UIKit has nothing for this).
Otherwise I'd say try UIKit, it's easier and there are more resources on the web.

Flame transition effect for iphone image

How would you impelement the following?
1. Image is loaded from a file
2. On Touch the picture burns in flame.
3. Next picture loads from another file.
How would you make the flame transition?
Hands down I'd use some OpenGL ES code I wrote for doing non-standard transitions (about 300 lines of code) as a base, and build a flame transition this way -- because I already have the code existing of course.
Basically how it works is like this:
Subclass UIView, set up a few properties including a EAGLContext, some GLuints representing textures of the views, etc.
Tell the view that its backing layer is an EAGLContext by overriding +layerClass
During initialization, pass another view in (your start view), and in this initialization phase, set up the GL context, take a texture of the view by capturing how it looks on the screen, save it for later.
Define a transition method which takes another view (the one to transition to), and does similar actions to #3 above, but also calls your custom transition code -- i.e., your flame effect.
That said, even if I didn't, OpenGL ES would still be the way I'd look at doing this first, since it will give me desirable effects in terms of realism, safe timing, and fast performance.
Alternatively you can look at CoreAnimation, which may be simple enough for your needs.

Elements/Wired Style 3D Animation

I am trying to implement the style of 3D rotational animation you see in the Elements and the Wired iPad applications. The animation has the UIScrollView style acceleration so it looks like they have connected a UIScrollView to a sequence of images.
I have tried implementing it in UIKit, using an "empty" UIScrollView to increment through an array of images and set the contents of a UIImageView, based on the content offset. This works but even with scaled down images on the simulator, it is very sluggish. I am not sure how I could optimise it to make it run faster.
Source Code on GitHub
I have also tried doing something similar in Cocos2D. Cocos could animate the sequence very smoothly but I couldn't control the animation. I tried using a scroll view and setDisplayFrame to step through an animation but it didn't work.
Any help or suggestions on either option would be greatly appreciated.
I'm not 100% sure I understand the effect you're trying to achieve, but if you're referring to the images in "The Elements" app which you can spin around, then yeah, you probably don't want to be doing that with an UIScrollView.
You can control the animation of content in Cocos2d. While you can set an animation to "just run", you can also manually set frames directly out of an animation, so if you can get smooth animation out of Cocos, you should be able to do it interactively. Look at the atlas sprite object - you can set the rect of an animation frame directly.
However, again, I'm not sure this is the best approach, either, since that's a lot of frames for a texture. If you're going to be doing a lot of 3D photographic objects, you might consider looking into the video codecs and scrubbing along a video instead of trying to pack all the frames of a rotation animation into a series of textures.
Just so you know, the guy who made "The Elements" wrote an article about the development of the app, and here's what he had to say about the 3D rotatable objects:
"Creating fluidly spinning objects with the level of crystal clear photographic quality I demanded is actually harder than it might seem. A number of the obvious things the more technical of you might think of turn out not to work for reasons too complicated to get into here. Suffice to say that John designed a brilliant solution that uses the iPad's excellent graphics subsystem to lend a hand in ways it's not normally intended to."
I don't know how exactly they achieved the 3D objects, but perhaps that "uses the iPad's excellent graphics subsystem" mention gives you a clue where to head from here...