|
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...
|
If you're interested in learning more about how to build objects, when to build them, what they should be, what should be subclassed, etc. you should look into Design Patterns (the book), and more generally design patterns the concept.
You should approve of the next column :-)