Setting up the Environment
Important Note: I highly recommend using the RageStarter solution as a visual reference.
Folder structure
Referencing RAGE assemblies
Adding scene controls
Adding character controls
Folder structure
In some cases you'll need to tell RAGE where to find certain assets such as sounds and storyboards. When it comes to scene and character controls, however, you have some flexibility as RAGE discovers them automatically if they're decorated with the proper attributes (more on that below).
If you're wondering why the character controls are named generically (i.e. "human_down"), it's all about reusability. Many of your characters will be able to leverage the same control while merely swapping the underlying images.
Referencing the RAGE assemblies
Once you've mapped out a folder structure, the next step is to reference the RAGE assemblies. A quick summary of the distinction between RageBuilder and RageEngine:
RageBuilder: Injects a toolbar into your Silverlight page. The toolbar launches a series of windows which build your game's manifest. When your manifest is finished you output a file (rage.eng) as part of your project. There's no need to reference RageBuilder when you deploy your game.
RageEngine: Interprets and executes the manifest during all phases of development, including deployment.
One of the few snippets of code you'll be required to include appears in your MainPage's constructor. Depending on what stage your game is in the code will be either:
RageBuilder.Environment.Initialize(this); // design time
- OR -
RageEngine.Environment.Initialize(this); // for deployment
When it's time to deploy your project, remove the reference to RageBuilder and use the latter code snippet above — otherwise your users will see the RageBuilder toolbar!
Adding scene controls
Scene controls are nothing more than standard UserControls. Create a new UserControl and add it to your project wherever you like. Thanks to Managed Extensibility Framework (MEF), and by adding just a few attributes, plugging in scene/character controls is pretty straightforward. Here's an example with "Scene1":
[Export(typeof(IRageSceneControl))]
[ExportMetadata("ID", "Scene1")]
public partial class Scene1 : UserControl, IRageSceneControl
{
public Scene1()
{
...
RageEngine's SceneManager catalogues any controls which export IRageSceneControl. Note that your control must also implement the "IRageSceneControl" interface to be valid, though it's entirely up to you if you want to include any logic in the FreeResources method. The "ID" you provide in ExportMetadata must be unique per scene, and it's the ID you'll see when selecting scenes in RageBuilder.
Remember: if you added a scene and it's not showing up the next time you run RageBuilder, make sure you've included these attributes!
Adding character controls
Character controls are catalogued much the same way except the attribute/interface names are different:
[Export(typeof(IRageCharacterControl))]
[ExportMetadata("ID", "human_down")]
public partial class human_down : UserControl, IRageCharacterControl
{
public human_down()
{
...
Keep in mind the distinction between the character control and the character definition. The former is the visual representation of the character and is suited for reusability/re-skinning. The latter is all the properties that make up the logical character, such as his/her name, inventory, and so on.
The RageStarter project demonstrates the Export attributes on scene and character controls.
|