XNA on WP7

Monkey Targets Forums/XNA/XNA on WP7

dopeyrulz(Posted 2011) [#1]
Well, just spent the last 4-5 hours attempting to get something working on WP7. Hacked apart the existing XNA target to find what needed to be done, created a new WP7 project and made the changes.

There are a couple of things that will probably need to change:

In program.cs, the MonkeyGame : Game class will have to be removed as you can only have one Game class in the project:
//public class MonkeyGame : Game
//{

//    public const int WINDOW_WIDTH = 640;
//    public const int WINDOW_HEIGHT = 480;
//    public const bool WINDOW_RESIZABLE = false;
//    public const bool WINDOW_FULLSCREEN = false;

//};

In mojo\native\mojo.xna.cs file (created a new one for WP7), the gxtkGame : MonkeyGame will have to be changed for the above references.

Also, in Class gxtkApp, the following will have to be remmed (at this point):
	public static Stream OpenStateStream( FileMode mode ){
        return null;
        //IAsyncResult result;
		
        //result=StorageDevice.BeginShowSelector( null,null );
        //result.AsyncWaitHandle.WaitOne();
        //StorageDevice device=StorageDevice.EndShowSelector( result );
        //if( device==null ) return null;
		
        //result=device.BeginOpenContainer( "gxtkApp",null,null );
        //result.AsyncWaitHandle.WaitOne();
        //StorageContainer container=device.EndOpenContainer( result );
        //if( container==null ) return null;
		
        //Stream stream=container.OpenFile( "gxtkAppState",mode );
        //return stream;
	}

as WP7 does not (yet?) have access to the Microsoft.Xna.Framework.Storage classes.


In monkey\native\lang.cs file the ArrayList for the errStack will need to be changed to a generic list as WP7 doesn't have ArrayLists:
	public static List<String> errStack=new List<String>();
	//public static ArrayList errStack=new ArrayList();

I'd assume this is no problem for a full change??

Also the following will need to be changed:
	public static void Die( Exception ex ){
		bb_std_lang.Print( ex.Message+"\n"+bb_std_lang.StackTrace() );
		//Environment.Exit(-1);
	}

The Environment class does not have this method for WP7.


Now, couldn't do much more as I don't yet have access to my device and the Emulator won't run on my laptop (not WDDM 1.1 compatible arrr). F@#K...

Apart from that editing up the trans module for a new Target was pretty straight forward.


Tibit(Posted 2011) [#2]
Cool, thanks for sharing! This will be really useful, I'm aiming to release for winPhone7 soooon :)


marksibly(Posted 2011) [#3]
Hi,

> In program.cs, the MonkeyGame : Game class will have to be removed as you can only have one Game class in the project:

Hmm....there is still is only the one game class (I think!), as that one above is 'extended' by the one in mojo. Does it definitely not work with that?

> as WP7 does not (yet?) have access to the Microsoft.Xna.Framework.Storage classes.

Ok, any idea of an API to use for LoadState/SaveState then?

> The Environment class does not have this method for WP7.

Ok, any alternative?


marksibly(Posted 2011) [#4]
Hi,

Yay - got Reach/WP7 going!

Still need to find an API for LoadState/SaveState and to deal with user input, but it's a start...


dopeyrulz(Posted 2011) [#5]
Mark,

Great news! Thanks for taking a look.

Hmm....there is still is only the one game class (I think!), as that one above is 'extended' by the one in mojo. Does it definitely not work with that?

When I try and compile I get this error:

Error 2 Multiple Game startup types found derived from Microsoft.Xna.Framework.Game. Remove the additional types. Types found: gxtkGame MonkeyGame MonkeyGame



Ok, the answer lies here at the bottom of the page (Setting the Game Startup Type):
http://msdn.microsoft.com/en-us/library/ff634566.aspx
public class MonkeyGame : Game
{

    public const int WINDOW_WIDTH = 640;
    public const int WINDOW_HEIGHT = 480;
    public const bool WINDOW_RESIZABLE = false;
    public const bool WINDOW_FULLSCREEN = false;

    public MonkeyGame()
    {
    }
};

Once I add a public constructor you can then set the 'Game startup type' dropdown to MonkeyGame from the Properties (XNA Game Studio panel). Compiles up but I cannot test if it works unfortunately.

Ok, any idea of an API to use for LoadState/SaveState then?

The LoadState/SaveState stuff will possibly be part of the tombstone stuff - I vaguely remember this area when I was playing around. I'll take a look and get back to you.

I'm assuming it's loading and saving settings etc??

The Environment.Exit method - I'll see if there is some sort an alternative.


dopeyrulz(Posted 2011) [#6]
Ok, any idea of an API to use for LoadState/SaveState then?

http://msdn.microsoft.com/en-us/library/ff604992.aspx

On initial investigation is looks like we use the System.IO.IsolatedStorage namespace. I'll keep looking for more info.

Some more specific WP7 Isolated Storage stuff:
http://msdn.microsoft.com/en-us/library/ff626522.aspx

There is also some information about tombstoning an app here:
http://msdn.microsoft.com/en-us/wp7trainingcourse_2dgamedevelopmentwithxnapart2lab_topic4

We may need to add some extra events to handle this:

These handle fully Opening and Closing the game
GameLaunching
GameClosing

These handle pressing the Start button (pausing) and the Back button (to return to the app).
GameDeactivated
GameActivated

This may be interesting to handle as far as the type of information that needs to be saved. I'd assume an app would not be approved unless it handles these sort of events.

If you haven't seen this, the training kit might be of some use:
http://msdn.microsoft.com/en-us/wp7trainingcourse.aspx
There is a good section describing these events.

Finally - hope this doesn't put you off supporting XNA/WP7! I'm more than willing to help in any way I can.


dopeyrulz(Posted 2011) [#7]

> The Environment class does not have this method for WP7.

Ok, any alternative?



As part of the Game class, there is an Exit method ie. this.Exit() - but, this can't be called in Die() as its a Static method.

See here:
http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k(MICROSOFT.XNA.FRAMEWORK.GAME.EXIT);k(DevLang-CSHARP)&rd=true

Some further info about exiting apps:
http://blogs.msdn.com/b/ptorr/archive/2010/08/01/exiting-a-windows-phone-application.aspx


DruggedBunny(Posted 2011) [#8]
OK, just tried building for XNA (on Windows 7) and got massive fail on the Windows Phone 7 parts, which caused the rest to fail:



Do I need to update/reinstall XNA somehow?


dopeyrulz(Posted 2011) [#9]
James,

Not much around the net with your error. Did you install the WP7 stuff as the error appears to point to that.

Also Mark looks like he's removed the WP7 project in Build 31, so you could clear your build folder (if you haven't already) and recompile.