Monet is a MVC library for writing hardware-accelerated 2D games.
Foundation is part of Cocoa, which comes with Mac OS X. There are several open-source implementations for Foundation:
- Cocotron (probably the most complete)
- libFoundation (likely outdated)
- nuFound (possibly incomplete)
MOApplication is the main class. It is responsible for creating a window (when using windowed mode) or managing the entire screen (when in fullscreen mode). It also contains the main game loop.
Each application has a single world, which is a object that responds to a
tick method. This method indicates that the game state should move a step forward.
Drawing is handled by
MOView, which is meant to be subclassed for every kind of view.
MOView also takes care of event handling. Views should base what they're drawing on the state of the world.
Starting the game
- Create a
- Configure the application (
- Set the world, if any (
- Open the screen (
- Push the initial game state (
- Enter runloop (
Drawing & views
Drawing is handled by views. Each view is a
MOView subclass that overrides
-drawRect: to perform the actual drawing.(The
rect argument is currently unused.)
Inside this method, all drawing operations will be performed inside the view. This is called the focus: before
-drawRect is called, the view automatically received focus. It is possible to give other views and images the focus by sending it
A view can have subviews. It is not necessary to explicitly draw the subviews in the
-drawRect: method; this will be done automatically. It is also not necessary to call
super in the
Event handling & controllers
Events are handled by controllers. Each controller is linked to a view. It is possible to have a view without a controller, but not the other way around. Controllers are automatically generated for views: implement
-controllerClass in the view and let it return the class of the controller.
Mouse events are sent immediately to the deepest subview.
When a view has successfully handled an event, the event should be discarded. When a view can't handle the specific event, the method handling the event should forward the event to the superview (which is what the default implementation does).
Key events are sent to the main view, unless there is a first responder, in which case the even will be sent immediately to the first responder.
When a view successfully handles an event, the event is discarded. When a view receiving a key event does not know how to handle it, it will sequentially forward the event to all of its subviews, until either it wasn't handled by any subviews, or it was handled by one subview, in which case the event will not be forwarded to the remaining subviews but will be discarded instead.
Relationships with Other Frameworks
Monet is loosely inspired by Cocoa. Being loosely inspired means that Monet's behaviour does not always match Cocoa's. For example, event handling is much simpler than in Cocoa (because a system as complex as Cocoa's is not necessary).
Monet uses SDL for window management and event handling. It also uses SDL_image for loading images in different formats. None of SDL's drawing functionality is used; this is where OpenGL comes in.
Monet uses OpenGL for all drawing operations.
Even though Monet is built on top of SDL and OpenGL, it should be relatively easy to replace SDL or OpenGL with a different implementation. For example, replacing SDL with GLUT should be possible without affecting any public Monet interfaces. Similarly, replacing OpenGL with SDL's built-in drawing functions should be possible in the same way, provided that the game itself does not directly use OpenGL.