Image:CocoaNav icon.png

PARMANOIR

Core Animation Starfield

Here's a little Core Animation sample with 3d layers.

Image:CoreAnimationStarfield.jpg
It looks better when moving ! :)

After learning that core animation doesn't like a root layer with a perspective transform, this sample sets up the perspective transform on a container layer, and stores the CATextLayer layers there. Works pretty well this time !

This uses preferredFrameSize to set the CATextLayer bounds, animates zPosition with CABasicAnimation and opacity with CAKeyframeAnimation to get a smooth transition from invisible, visible, invisible.

Coordinates

As we're going 3d, we don't work with (x,y) beetween ([0…frame width], [0 … frame height]) but with centered coordinates : [-width…width, -height…height]. This means our container layer needs to be centered in the view, or the 3d objects will appear to spring from the bottom left corner.

Issues

  • hit testing a layer doesn't work reliably.
  • the main layer is manually centered. Couldn't wrap my head around constraints.
  • how do you use Cocoa controls on a HUD window ? They don't look that good …

Image:iconZip.png CoreAnimationStarfield.zip

Core Animation

Jonathan Wight
2008 04 06

Nice code!

Runs like a dog on Macbook (1st gen) until you turn bloom filter off. Then runs really smoothly.

Subscribed!

Patrick Geiller
2008 04 06

Woops ! Maybe I should have Bloom disabled by default. But it's so much prettier ... :)

2008 07 25Where in build phases is that file ?
2008 07 192Imagine clickable error messages
2008 07 18Succulent Stormhoek
2008 07 173Loving the for
2008 07 12(Parmanoir) Feed now validates
2008 07 108Telling classes from instances
2008 07 08Comma Trick
2008 07 06Using libffi
2008 07 04BridgeSupport's type and type64
2008 07 042Clickable Disabled MenuItems
2008 07 026Less bugs through compiler optimizations
2008 06 251CocoaNav JS, a light CocoaNav for Safari
2008 06 232NSWindow goodies : bottomCornerRounded, usesLightBottomGradient
2008 06 222Inspecting NSUndoManager's undo stack
2008 06 16Cocoa Regular Expressions via JavascriptCore
2008 06 15Crossing the WebKit bridge
2008 06 08Double and Triple Click
2008 06 05Photoshop-like compositing with Core Animation
2008 06 052One way binding to NSSlider
2008 05 30Threaded Core Animation, Part Deux
Image:rss.png
Image:rss.png

Powered by MediaWiki

Hi ! I'm learning Cocoa to (hopefully !) become an indie developer.

I've written software all my professional life, in C++, PHP, Javascript. I've designed websites and web interfaces. My last venture went into flames as clients were happy but didn't like paying very much.

I've had little luck in the B2B world, I'm hoping for a better future writing Mac applications.

Planet Cocoa