Animating Graphics in Cocoa, Part 1
Subject:   Animating several balls
Date:   2002-01-20 11:12:41
From:   mikebeam
Response to: Animating several balls

Yeah, animating several balls is a problem that i've not yet tackled. Your proposed solution is often the one pops into my head when i think about it. Instead of having a controller object alter their values of dx and dy you caould have the custom view take care of that. At each animation step the view could tell each ball in the array (via an enumerator) to move forward a step, and then in the drawRect method you could again enumerate your array of balls and send -draw messages to each ball which would tell them to draw themselves. Something along those lines.

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 :-)