Re: Using an NSMatrix subclass for a board game view
Re: Using an NSMatrix subclass for a board game view
- Subject: Re: Using an NSMatrix subclass for a board game view
- From: Fritz Anderson <email@hidden>
- Date: Fri, 12 Oct 2007 13:12:18 -0500
On 12 Oct 2007, at 11:31 AM, Brautaset Stig wrote:
I'm writing a simple Reversi game, and I'm currently struggling a
bit trying to create a simple animation of the pieces being flipped
when a player (or the AI) makes a move. I'm using a subclass of
NSMatrix for my main view, and trying to make it call its own
display routine again.
My best guess is that you should define a subclass of NSCell (possibly
NSImageCell, possibly NSButtonCell), that keeps three states, one
empty, and one for each player. When it transitions, it should run an
animation showing it. This could be done:
In QuickTime with QTKit.
or
Using an NSTimer to mark the stages of the animation, and having the
timer make the cell setImage: for the next frame of the animation.
Invalidate the timer when the animation is done. The cell should send
setNeedsDisplay: or setNeedsDisplayInRect to the board view.
I see no reason why more than one animation can't be done at the same
time, though it might be less confusing to the user if you didn't
respond to clicks while animations are in progress.
The new cell will have to draw itself distinctively when the mouse is
down over it.
In the long run, you might want to consider your own board view. You
are already fighting NSMatrix by providing your own mouseDown: method
(why can't Desdemona receive an action from the NSMatrix and do the
transition itself?).
Also, you're keeping the state of the game in your NSMatrix subclass.
This is bad. Review the Model-View-Controller (MVC) design pattern at
developer.apple.com. You'll find it easier if you keep the state of
the game in its own class. That way, your AI (for instance) can work
directly on an object that isn't complicated by click-and-draw
mechanics. You can change the board-view or the game-state-model
without having to rework the other. Use the class Desdemona as a
controller object, to translate click actions into state changes, and
to propagate state changes to the display.
— F
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden