As you may have noticed, many of the other Neoforce tutorials tell you to drop in a Manager while the tutorial(s) on this site tell you to use the Application class. So, what exactly is the difference in the two approaches and how should you decide which approach is best for your needs? This article will attempt to answer those two questions.
The Manager class provides all the functionality you need for loading Neoforce skins, drawing controls, and handling input for the controls. If you need to add UI support to a project/game in later development stages, you'll probably find it's easier to throw a Manager into your code than it is to use the Application class. However, if you want the UI to work nicely with your world rendering code, I still suggest you go take a peek at the Application class to see when and where the call to DrawScene is taking place. Otherwise, you may run into issues where the Manager wipes out the game world when drawing the UI or you'll end up with the game and UI fighting over Z-order.
As the name suggests, the Application class is better suited for building applications. It's derived from the Microsoft.Xna.Framework.Game class so that should give a little indication on its intended use. If you're planning to build a tool for your game, or even a PC game with a lot of UI elements, it may be a better idea to start with the Application. It has all the features that the Manager has, because the Application contains a Manager object. The Application class also handles Manager initialization, handles mouse event hook ups for the manager, has a fully functional exit dialog, handles creating and initializing the main application window (if used), handles graphics device resets, and sets up the Manager's input offsets for you.
In terms of ease of use, the application already handles all the Manager drawing calls and provides a method called DrawScene that you add your world rendering code to (so the UI and the 'other' render code play nicely together.)
How Do I Choose?
In terms of which approach to use, it depends on a few factors. Here's my current breakdown of how I choose:
- Late stage project: It's easier to drop a Manager in where you need it. You'd probably have a hell of a time trying to convert to the Application class in later development.
- Multi-player game: It's probably easier to use multiple Managers for each player/viewport depending on how far into development you are. That's not to say you couldn't modify the Application to use multiple Managers and Viewports.
- Single player game: I'd go with the Application class on this one, but either approach works. Your preference really.
- Application/Editor/Tool: I'd start with the Application class. Either would work, but the Application already handles much of the stuff you'd need to do anyway.
What Have We Learned?
After set up, both approaches are functionally equivalent. Using the Manager class directly does require more initial work but it is far easier to add this to a project that is already under way. However, depending on your project, you may find yourself duplicating code that's already implemented by the Application class. If you're doing a more complex, form-based application, definitely choose the Application approach if you can.
I figure most of you Neoforce users are probably pretty comfortable with the Manager approach already. That's why I've chosen to show the alternate path, and, sometimes it's just easier to copy/paste and strip out what you don't need than it is to constantly write the same code for every project. :P
Any other more-experienced NF user out there want to weigh in on this topic? Hit up the comments. :)