small medium large xlarge

03 Jun 2009, 17:21
Bryan Hughes (8 posts)

Hey Everyone,

Thought I would see if anyone here can help me. I am relatively new to core animation and have just about every book on iPhone development including Core Animation by Bill Dudney which I have read. Although I must admit that reading multiple books simultaneously does create a bit of confusion when trying to reference back to the source something you remember reading.

My question is: I would like to take the top level UIView after all the subview and layers have finished rendering and make a copy of it before it displays on screen. I looked around for some call backs but like I said, I am relatively new and am not up to speed on the API. I am looking to create a double vision effect. Traditionally, I would simply copy the buffer twice, apply an opacity to each copy and shift a random degree and then render that composite while throwing away the original buffer. This should be really cheap (other than the memory needed for three buffers).

With the views and layering, I should be able to achieve the same effect as long as I can do some sort of call back when the superview is ready to be rendered to the screen.

I am pretty certain this should be trivial based on the Quartz architecture.

Thanks! Bryan

05 Jun 2009, 17:01
Bryan Hughes (8 posts)

Thought I would update this post with some information that I have found. First, you are not supposed to mix Core Animation, Quartz with OpenGL ES. This is supposedly a no-no.

I did google this little bit of code that would work nicely:

				NSDate *begin = [[NSDate alloc] init];
				[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
				UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
				NSTimeInterval since = -([begin timeIntervalSinceNow]);
				NSLog( @"since=%f\n", since );
				[begin release];

EXCEPT that it takes on average .30 seconds to convert the current image context of the superview into an image which I can then apply as another layer on top. Obviously this fails miserably…

My game has a very good frame rate, at this point I am going to experiment with what the cost will be in simply rendering all the game objects twice. If anything, it will be an interesting exercise.

Still would love to hear of any ideas, suggestions or wisdom on how to do top level effects with Quartz.

You must be logged in to comment