Search code examples
objective-ccocoacore-animationquicktime

CoreAnimation Game - Adding a video feed as the background?


Greetings Friends,

I am trying to overlay the simple 2D game I am developing on top of a quicktime (.mov) movie. I do not have experience with this (or much game programming xp) so I'm wondering if anyone has had to deal with this problem before and, if so, how did you go about solving it?

I've been looking into the QuickTime API (QTKit) and it looks promising, but if there's a better way - one that could be extended to support live video streams, that'd be AMAZING.

The game uses CoreAnimation layers for game objects and currently has an image as the window background. So basically, I need to change that image into a movie. Thanks all, I appreciate the help and suggestions.

// < Mr. Buffalo >

Solution

  • I figured this out at some point yesterday. Pretty straight forward actually. However, I haven't looked into streaming video yet..

    ApplicationController:

    - (void) setupQTMovieLayer
    {
        // Get the movie and make it loop (my test canned video is short so I loop it)
        QTMovie * movie = [QTMovie movieNamed:@"Sample.mov" error:nil];
        [movie setAttribute: [NSNumber numberWithBool:YES] forKey:QTMovieLoopsAttribute];
    
        // Create the movie on the (CALayer) backgroundLayer, make it sexy, and add it to our view atIndex:0
        // note: backgroundLayer is a property of this class
        backgroundLayer = [QTMovieLayer layerWithMovie:movie];
        backgroundLayer.masksToBounds = YES;
        [[contentView layer] insertSublayer:backgroundLayer atIndex:0];
    
        // Goto the beginning and play the movie
        [movie gotoBeginning];
        [movie play];
    }