A Three-Pack of Core Animation Samples
Lucas Newman has posted a collection of three Core Animation sample projects. These examples stand out not only because they actually do interesting things, but the code is well-written and well commented.The three samples are:
1. Wallball — a 3D pong-like game where you bounce the the ball against a backboard which stretches and distorts as the ball makes contact. Tons of great examples here. NSTrackingArea, Core Image filters, CATransactions, basic Core Animation geometry. Also fun to play.
2. Scatter — Insects "scatter" as you hold down the mouse button to turn on a flashlight. They actively move around to avoid the light. Delegate-based CALayer drawing and animation, NSTimer, and Key-Value Observing.
3. Jumpy — Grabs a snapshot of your desktop and "bounces" it off into the background. Examples of custom windows, the new Leopard-based CGWindow API, and implementing reflections.
Download Samples (1.4MB)
A Three-Pack of Core Animation Samples
Posted Dec 16, 2007 — 13 comments below
Posted Dec 16, 2007 — 13 comments below
Chuck — Dec 16, 07 5208
(I don't intend this as a knock against Lucas � it's some great sample code, and I'm sure lots of people will get good use out of it. I don't think anybody would expect him to test sample code on every hardware config Apple's shipped in the last five years, and a workaround would be less clear anyway.)
Wes — Dec 16, 07 5210
How would you do that?
Alexander Rauchfuss — Dec 17, 07 5211
The easiest way would be to use CATiledLayer and the drawLayer:inContext: delegate method.
ssp — Dec 17, 07 5214
Jumpy didn't work for me at first. Just a white rectangle was bounced around pretty much as in what Chuck commented on. Disconnecting the second screen resolved that problem, but if we run into this problem so easily it may really be worth further discussion to see how to deal with it gracefully in an application.
George Dick — Dec 17, 07 5215
CGImageRef image = CGAutorelease(CGWindowListCreateImage( *(CGRect *)&displayBounds, kCGWindowListOptionOnScreenOnly, kCGNullWindowID, kCGWindowImageDefault));
George Dick — Dec 17, 07 5216
Lucas Newman — Dec 17, 07 5218
You are totally right about the flashlight layer size being too large � the layer size limitation is very inconvenient.
Switching to a CATiledLayer for the flashlight layer would definitely fix it, though.
jimi — Dec 17, 07 5221
Its superfly.
Alexander Rauchfuss — Dec 18, 07 5222
Altered Scatter
Blain — Dec 19, 07 5232
Mark Stultz — Dec 24, 07 5286
http://developer.apple.com/samplecode/GeekGameBoard/index.html
Looks fun.
Merry Christmas.
julian — Mar 09, 09 6620
Micmoo — Apr 17, 09 6688