advertisement

Article:
  Animating Graphics in Cocoa, Part 1
Subject:   Animating several balls
Date:   2002-01-15 06:50:16
From:   destanley
Wow! Great. This is exactly the kind of stuff I'm interested in. Now if Mike can only attack video and sound (hint hint).


Anyway, I tweaked the exercises in order to better understand Cocoa animation, had a lot of fun, and hit a wall when trying to animate several balls. I think the question is: how should I attack things in Cocoa from an object-oriented viewpoint. I'm a procedural kind of guy and I'm having problems figuring out exactly when to subclass, what to subclass and where (in a view, in an NSObject, etc), when to make my own classes, and when to use Apple's. I really get all the Model-Controller-View stuff theoretically, but I don't see it really in action here.


It seemed to me the most logical thing would be to make several "ball" objects, each one containing 'dx', 'dy', their NSBezierPath and their own NSAffineTransform. Then an array (mutable just for fun) would hold all those objects and some controller object would allow you to affect their dx and dy values while they looped, drawing themselves so to speak.


Well, the problem is of course that there is only one NSView while there are several objects, and... well you see... I still haven't fully *gotten* Cocoa...



1 to 1 of 1
  1. Michael Beam photo Animating several balls
    2002-01-20 11:12:41  Michael Beam | O'Reilly Author [View]

1 to 1 of 1