Sunday, August 4, 2013

Bunny Hunters Online: The Windows Store Project

The next step is to create a project for the first platform.  When writing a cross-platform piece of code you need to write to the common denominator.  The easiest way to do that is to start with the most restricted platforms.  For monogame, those are Windows 8 Store and Windows 8 Phone.

Right click on the Solution "Bunny Hunters Online" and chose "Add->New Project".   The new project dialog should be a familiar sight.  Choose MonoGame Windows Store Project.  Enter "BHO Windows Store" and click OK.


You many see another annoying warning pop up.  This too can be safely ignored.


This should result in the creation of a new project in the solution.  This will be the actual application so it should be set as the startup project.  This is done by right clicking on the project in the solution explorer and selecting "Set As Startup Project".


This project will use the xnb files created by the asset project.  Unfortunately I have found no easy way to get VisualStudio2012 to do this through a reference.  (If someone figures out how to add a content reference to a Monogame Windows Store project, please post it in comments.)  As an alternative, what I do instead is to add links to the xnb files as content.

To do this start by right clicking on the project and selecting Add->New Folder.  Name the folder Content.  Now, right click on the folder and chose Add->Existing Item...

In the dialog that pops up, navigate to  the BHO Solution Folder->BHO Assets->bin->Windows->Content.  Group select all the files with shift-click.  Then click on the arrow to the right of the ADD button at the bottom of the dialog and select Add Link.


This will add all the selected files as links in the Content folder you just created.  There is one more step, however.  As is, VS2012 doesn't know what to do with these files and will ignore them.  We need to tell that this is game content.  We do that by shift-click selecting the xnb files and then using the properties dialog beneath to set the Build Action field to Content.



Now build the entire project.  This should be successful, however for a Windows Store app this is only part of the process.  You need to deploy to finish it.  The easiest way is to run it using the green arrow next to the wordS "Local Machine"at the top of the screen.





If all goes well you should see a grey screen with an icon in the center for a few seconds, followed by an empty blue screen.

It is possible, depending on your configuration,  that deployment may fail and you may get a dialog like this instead.


For security reasons, you cannot run a Metro app from a network drive.  If you are doing your development on a volume shared with OSX (not a bad idea for eventual OSX project development) then Windows sees it as a network drive.

You can fix this by editing the BHO WIndows Store csproj file.  One little hitch, this file is loaded when you start the project and saved back out by the system when you quit the project.  So, any editing of the csproj file you do while the project is open has no effect.

To properly edit a csproj file you must first unload the associated project.  You do this by right-clicking on the project and selecting Unload Project from the context menu.


Next, you right click on the now unloaded project again and you will get a context menu with only a few options. Select Edit BHO Windows Store Project csproj.


This will open the csproj in the editor. Add the following lines just before the </Project> closing tag:

<PropertyGroup>
    <LayoutDir>C:\WorkingFolder\$(MSBuildProjectName)\$(Configuration)</LayoutDir>
</PropertyGroup>


The bottom of the edited file should look something like this:


Save the edited file and right click the project again. Select "reload project" to reopen it with the new csproj.  You will need to right click the project one more time and reset it as the startup project.  Once this is done, click run and you should get the results described above.

Next Blog:  Initializing the graphics system and bringing up the start screen.







No comments:

Post a Comment