Edit AllPages

Here is some code i wrote to play around with and experiment with animation using NSTimer. I don’t know much about efficient animation, so what you see here is probably nothing ideal. But what the hell…

The Interface File:

@interface PulsingDotView : NSView { NSTimer *timer; NSColor *color; NSBezierPath *path;

NSPoint center;
double vy0, vx0, vx, vy, ax, ay, dt, tx, ty, x0, y0, radius; }


I orignally wrote this code to make a circle pulse in the view, but then after a substantial bit of playing around it got changed into something else…

And the Implementation File

#import “PulsingDotView.h” #import “math.h”

@implementation PulsingDotView


This view is just hooked up to a view in interface builder. Have fun!

Would be better to only update the dirty area instead of the whole view. :/

Here’s what I’ve tossed together…

The Interface Files:

@protocol Animation


@interface AnimatingView : NSView { NSTimer *animTimer; }


Implementation File:

@implementation AnimatingView

I set my window’s contentView to be an instance of AnimatingView and load on some custom views/controls that conform to the Animation protocol.

Here’s an example of a view that conforms to the Animation protocol (Compiled here);

#import “Animation.h”

@interface BouncingView : NSView { float verticalSpeed; }

// BouncingView.m…

@implementation BouncingView

frame.origin.y += verticalSpeed; [self setFrameOrigin:frame.origin];
     // erase where we were..
    [superview setNeedsDisplayInRect:oldFrame];
     // draw where we are..
    [superview setNeedsDisplayInRect:frame]; } @end