MonoGame for WP8 ready for testing (everything working)

Topics: Announcements, Windows Phone
Developer
Apr 8, 2013 at 1:50 AM
Edited Jun 22, 2013 at 7:27 PM
Hello Everyone!

Changes are merged to the main branch. Please use that instead of my fork.

We have finally come to the point where we can say that everything is working with MonoGame on WP8.
The main differences compared to the main repo (at the time of writing):
  • Autorotation (including landscape) with landscape support. Just use a DrawingSurface instead of a DrawingSurfaceBackgroundGrid (thanks to crnjan).
  • App resuming (again, thanks to crnjan), including custom content
  • Game Activated and Deactivated events
  • MediaPlayer resuming
I would like to invite everyone to try it, since it may take a while for the required pull requests to get merged.
What you need is:
My fork:
https://github.com/Nezz/MonoGame/tree/wp8_working
MonoGame.Framework.WindowsPhone added as project to the solution and referenced that way for easy ARM/x86 switching (not referenced by the DLL, but by a project in the solution).

Since everything related to graphics is lost on WP8 when the app resumes, you will need to re-render the contents of your RenderTargets.

Be aware that Fast App Resuming (the new resume type in WP8 which happens when you re-open an already opened app) is not acting nice with RenderTargets.

Update: SharpDX 2.5.0 dev build is now included. If it doesn't work, you will need this:
Lastest SharpDX dev build (copied into MonoGame/ThirdParty/Libs/SharpDX/Windows Phone/ARM and x86):
http://sharpdx-nightly-builds.googlecode.com/git/SharpDX-SDK-LatestDev.exe

Update 2: The SharpDX references do not work if you try to compile with AnyCPU configuration. You need to compile in x86 for the emulator and in ARM for the device.
We all want this limitation to go away, but we need Microsoft to make it possible to build in AnyCPU. You can help the matter by voting on the following feature request:
https://connect.microsoft.com/VisualStudio/feedback/details/777333/add-dllimport-support-for-net-in-windows-phone-8

Update 3: Changes are merged to the main branch. Please use that instead of my fork.
Developer
Apr 8, 2013 at 9:36 AM
Hi Nezz this is great news.
So are things like all soundfx, music, gestures & landscape fixed in your fork?

I think the team and the community are waiting for these fixes. We look forward to your PRs.


D.
Developer
Apr 8, 2013 at 10:20 AM
Everything is in place, but you have to take care of the orientation yourself. All the "hooks" are in place, so all you have to do is compare these:
Game.Window.CurrentOrientation
GraphicsDevice.PresentationParameters.DisplayOrientation (which should be always default aka portrait)
And apply a rotation matrix accordingly.
Apr 8, 2013 at 7:26 PM
That's excellent news -- and great timing too, I'll be revisiting all of the chapters of my book in the next couple of weeks to fill in all the sections I've had to skip for WP8 (which has been giving me some anxiety!) so this is exactly the news I've been waiting for.

It's a shame that the "full" support for landscape orientation isn't yet in place, it sounded like you guys were extremely close to it. A couple of questions regarding landscape with the current implementation:
  • When using matrices I can apply a 90 degree rotation matrix for landscape orientation, but what's the best way when rendering with sprites? Is it to render to a separate render target and then draw that rotated to the screen at the end? What is the performance penalty for this?
  • Are touch coordinates rotated when using landscape orientation or will these need manually switching around?
  • Is the plan still to implement "proper" landscape support in future (i.e., all the detail hidden away from the game author) and if so how much code is the game author likely to need to change to switch from doing all the work manually? I guess if we're comparing the window orientation to the graphics device orientation and only rotating when they are different, perhaps this will take care of itself (as with proper support they will then be the same).
Finally, does anyone have any idea when this is likely to be packaged up into another installable release? Then I'll finally be able to sleep peacefully at night. :-)

Many thanks for all your efforts, it's hugely appreciated.

Adam.
Developer
Apr 8, 2013 at 9:11 PM
If you use spritebatch, the best approach is to write a spritebatch extension that supports matrices. That's less than 10 lines of code: Decompose scale, rotation and translation from the matrix then call a the standard SpriteBatch.Draw with the decomposed values.
Nope, touch positions aren't rotated either.
For "proper" landscape support, this is what we have:
https://github.com/SickheadGames/MonoGame/tree/WP8Orientation
I haven't tested this code myself and it wasn't touched for a month now.

The whole landscape thing may look scary at fist, but it isn't hard to implement at all.
Apr 8, 2013 at 9:21 PM
Thanks for that Nezz, do you have any example code for such a spritebatch extension?
Developer
Apr 8, 2013 at 10:26 PM
Edited Apr 8, 2013 at 10:26 PM
There you go:
const double PI2 = Math.PI + Math.PI;

var scale = new Vector2(matrix.M11, matrix.M12).Length();
var rotation = matrix.M12 >= 0 ? (float)Math.Acos(matrix.M11 / scale) : (float)(PI2 - Math.Acos(matrix.M11 / scale));

spriteBatch.Draw(texture,
                    Vector2.Transform(position, matrix),
                    sourceRectangle,
                    color,
                    transformRotation + rotation,
                    origin,
                    transformScale * scale,
                    effects,
                    layerDepth);
Apr 8, 2013 at 10:38 PM
Fantastic, thank you -- I'll have a play with that tomorrow.
Apr 8, 2013 at 10:50 PM
Hi Nezz
That's a good news!
As soon , i'm ready on android, i will focus on Wp8
Peter
Apr 9, 2013 at 6:07 AM
One thought - you could use DrawingSurface instead of DrawingSurfaceBackgroundGrid which obeys page orientation:
<phone:PhoneApplicationPage
...
    SupportedOrientations="Landscape" Orientation="Landscape"
    mc:Ignorable="d"
    shell:SystemTray.IsVisible="False" >

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot">
        <MediaElement />
        <DrawingSurface x:Name="XnaSurface" />
    </Grid>

</phone:PhoneApplicationPage>
now rendering will be in landscape without any game code change required. Just my 2-cents ;)
Apr 9, 2013 at 9:03 AM
Hi crnjan,

Have you successfully used this technique? If I switch XnaSurface to be a DrawingSurface I get a compilation error (running against the MonoGame 3.0 release DLLs) as it unsuccessfully attempts to cast that to a DrawingSurfaceBackgroundGrid in the call to XamlGame.Create(). Does this require changes to the MonoGame code?

Adam.
Apr 9, 2013 at 10:01 AM
Yes I have, but you'll need my fork (https://github.com/crnjan/MonoGame) or Nezz's fork (https://github.com/Nezz/MonoGame/tree/wp8_working ), which has my changes incorporated. Please see first post in this thread.
Developer
Apr 9, 2013 at 11:11 AM
That's something I wasn't aware of crnjan. Thanks for opening my eyes :)
Developer
Apr 9, 2013 at 3:29 PM
Edited Apr 9, 2013 at 3:31 PM
I tested using a DrawingSurface and the rotation worked fine, but the backbuffer resolution and the device orientation needs to be set according to the DrawingSurface. Our game autoscales itself to the backbuffer and without those parameters, it looked wrong.
Apr 10, 2013 at 10:44 AM
Using Drawing Surface instead of DrawingSurfaceBackgroundGrid might cause a significant performance degradation, or?

Didn't try it myself. Did you take a look at the FPS counter?
Developer
Apr 10, 2013 at 1:42 PM
DrawingSurface ~ XNA-like performance
DrawingSurfaceBackgroundGrid ~ native DirectX

The difference is about 1 in fillrate. If your bottleneck isn't the fillrate, there will not be any significant performance degradation. The best way to test for fillrate bottleneck is by using a Lumia 920 (yep, the high-end phone is the slowest due to its screen).
Image
Apr 10, 2013 at 2:01 PM
I know. It's 2.56 times the resolution.
Actually I posted the link to this graphic and some actual measurements with MonoGame on Jan 15, and Jan 17, see here https://monogame.codeplex.com/discussions/402054 .

My app actually is fill rate limited. I could imagine that DrawingSurfaceBackgroundGrid is double as fast as DrawingSurface. But sometimes such guesses are wrong ;-)

What must I do exactly to switch from DrawingSurfaceBackgroundGrid to DrawingSurface?

I have to change the XAML by replacing DrawingSurfaceBackgroundGrid with DrawingSurface. That's easy.
But you wrote:
but the backbuffer resolution and the device orientation needs to be set according to the DrawingSurface.
There are settings in the XAML for this?

Or do you mean to make a change in Game1.cs? ... e.g. something like:
_graphics.PreferredBackBufferWidth = w;
_graphics.PreferredBackBufferHeight = h;
(I thought that settings are ignored in MonoGame).

Any hints welcome :-)
Developer
Apr 10, 2013 at 4:07 PM
On your side, you don't have to do anything else other than switch to DrawingSurface in the XAML. What I said was about MonoGame, as it gives wrong values.
Apr 10, 2013 at 8:47 PM
Hi Nezz and crnjan,

Are you planning to fix these wrong values inside MonoGame? It would be great if everything acted exactly the same as a landscape-orientated XNA game and it sounds like you're extremely close...
Developer
Apr 11, 2013 at 11:22 AM
I'm kinda busy these days to have a look at it. I think touch needs to be rotated too.
Apr 11, 2013 at 1:16 PM
@crnjan @nezz

Thank you. Tried it. Worked.

It's not as bad as I had suspected. The speed is in my case about 5 - 10 fps less when using DrawingSurface instead of DrawingSurfaceBackgroundGrid.

My game is at the limits, so I have to continue to work with rotated cameras / UIs. However DrawingSurface can in many cases be a simpler solution for games in landscape mode.
Apr 11, 2013 at 4:58 PM
DrawingSurface is part of XAML composition and therefore has performance penalty; however there are other more useful cases for DrawingSurface:
  • one can draw "behind" MonoGame surface, i.e. draw fullscreen camera preview or WP native maps and than draw 3D stuff over it, which is not possible using DrawingSurfaceBackgroundGrid,
  • using animation between XAML pages works out-of-the-box while it crashes when using DrawingSurfaceBackgroundGrid,
  • ...
Developer
Apr 14, 2013 at 11:17 AM
DrawingSurface is also preferred by SharpDX, which is the API MonoGame uses on Windows.
Apr 23, 2013 at 2:25 PM
Works fine! Thank you very much.
Apr 23, 2013 at 2:30 PM
I finished the last chapter of my book a day or two back, so now I'll be revisiting all the WP8 problems I had and retesting them against this update. I'll let you know how I get on.
Developer
Apr 23, 2013 at 4:58 PM
Rum Run is available for WP8 thanks to this brach. Check it out if you are interested:
http://www.windowsphone.com/s?appid=1363e786-cbe2-4558-9816-7889b22c9cd4
Apr 23, 2013 at 9:31 PM
I've worked through a lot of the things that were broken before and nearly everything is working perfectly -- this is a dramatic improvement.

I'll spend a little more time with the one or two things that don't seem quite right and will post more details tomorrow, it's possibly problems in my code rather than in MonoGame's.

Huge thanks for these updates!
Apr 24, 2013 at 2:47 AM
Edited Apr 24, 2013 at 2:49 AM
When I add this reference to my project, it will only allow me to build in the specified mode (x86 or ARM) and will not automatically switch for different build configs. So when I include the x86 reference, I would not be able to build the ARM version. Previously it had worked fine. Any ideas?
Developer
Apr 24, 2013 at 7:06 AM
shyong_oso wrote:
When I add this reference to my project, it will only allow me to build in the specified mode (x86 or ARM) and will not automatically switch for different build configs. So when I include the x86 reference, I would not be able to build the ARM version. Previously it had worked fine. Any ideas?
WP8 has some serious limitations that don't allow SharpDX (the DirectX API MonoGame uses) to build in AnyCPU, thus you need ARM for the device and x86 for the emulator. Just switch the build configuration and you will be fine.
Apr 24, 2013 at 7:26 AM
Related question: The Store Test Kit can only be used with AnyCPU?
Is there a workaround to use it?

Stephan
Apr 24, 2013 at 7:50 AM
Nezz wrote:
shyong_oso wrote:
When I add this reference to my project, it will only allow me to build in the specified mode (x86 or ARM) and will not automatically switch for different build configs. So when I include the x86 reference, I would not be able to build the ARM version. Previously it had worked fine. Any ideas?
WP8 has some serious limitations that don't allow SharpDX (the DirectX API MonoGame uses) to build in AnyCPU, thus you need ARM for the device and x86 for the emulator. Just switch the build configuration and you will be fine.
I tried that, but when I add in the x86 reference and try to build ARM, it won't build. Same vice-versa. I would have to manually remove the reference and add the other version each time I switch from emulator to device.
Apr 24, 2013 at 6:52 PM
Thank you to the folks who got this working! Was able to pass store cert using the build in this post.
Apr 24, 2013 at 9:39 PM
One of the problems I was experiencing yesterday seems to be happening consistently and I can't work out why. When I touch the screen running on a real device (a Lumia 820), the performance of the rendering dives significantly.

I've tested with various projects, but the easiest is with the empty WP8 project template from the MonoGame 3.0 installer. In order to get this working with the latest MonoGame source from the link above, I've modified the XAML content of GamePage to be as follows:
    <DrawingSurfaceBackgroundGrid x:Name="XnaSurface" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <MediaElement />
    </DrawingSurfaceBackgroundGrid>
...and modified the class constructor to be as follows:
        // Constructor
        public GamePage()
        {
            InitializeComponent();
            _game = XamlGame<Game1>.Create("", this);
        }
When I launch, the CornflowerBlue page appears as expected and the WP8 frame rate counter shows that it's running at 60fps, which is great.

Now if I simply swipe my finger up and down the screen a few times, the frame rate drops from 60 down to 1 or 2, and stays there for about 10-15 seconds (even after I stop touching the screen). After a while it jumps back to 60. The longer I swipe the screen for, the longer it takes to recover back to 60fps. I've tested with some simple sprite animation on the screen too and can confirm that the frame rate really is dropping dramatically.

Once it has recovered, I seem to be able to touch the screen as much as I like without any further problems.

Other things I have tried:
  • I tried running with the VS IDE attached in both Debug and Release mode, and both exhibited the problem.
  • If I stop debugging and then run the same project by picking its icon from the programs list on the WP8 start screen, it runs without any problems at all, I can touch as much as I want with no slowdown.
  • Running in the emulator and swiping around with the mouse, I can't get the slowdown to occur.
Can anyone else reproduce this?
Apr 25, 2013 at 12:57 AM
^It was noted somewhere that having the device connected while debugging will cause significant slowdown with touch input.
Apr 25, 2013 at 6:23 AM
Ah yes you're right, I'd missed that. The thread is at http://monogame.codeplex.com/discussions/438011 -- I'm glad it's not just me anyway. :-)
Developer
Apr 25, 2013 at 9:50 AM
shyong_oso wrote:
I tried that, but when I add in the x86 reference and try to build ARM, it won't build. Same vice-versa. I would have to manually remove the reference and add the other version each time I switch from emulator to device.
Why would it build on ARM with x86 reference and vica-versa? It's called what it's called for a reason.
MonoGame has conditional references by default which do the work for you. Just leave them that way. Or instead, you can add SharpDX imports to the imports section of your project (have a look at SharpDX samples to see it), which will do the work for you, again.
Developer
Apr 25, 2013 at 9:51 AM
Message to everyone using trial mode: make sure to update as there is a WP8 bug where the Windows 8 style license information becomes invalid after resuming the app, thus a paid app will become trial.
Apr 25, 2013 at 8:39 PM
A question about orientation.

I can set up Portrait mode fine by setting Page.SupportedOrientations to Portrait and GraphicsDeviceManager.SupportedOrientations to Portrait. The window size is reported as 480x800.

I can set up Landscape mode fine too by setting Page.SupportedOrientations to Landscape and GraphicsDeviceManager.SupportedOrientations to LandscapeLeft|LandScapeRight. The window size is reported as 800x480.

But when I try to make an app that supports both landscape and portrait orientation, I can't get things to work properly. Once I set the Page.SupportedOrientations property to PortraitOrLandscape, the window dimensions are locked to 480x800 regardless of the orientation. When I hold the device in portrait orientation everything displays correctly, but when I rotate it into landscape mode the content does rotate too, but the window dimensions are still reported as being 480x800. As a result the content is stretched out horizontally and compressed vertically.

Is there something I can do to fix this? I'm happy to push the correct dimensions into MonoGame myself when the orientation changes if that's what's needed, but I've yet to find a way to do this that works.
Apr 26, 2013 at 3:41 AM
Thanks for your work here. I'm having trouble building. It looks like the latest SharpDX changed the signature of DrawingSurfaceBackgroundContentProviderNativeBase.PrepareResources. Is there a blessed SharpDX build that works? Or, are there changes planned to make it work with the latest builds?
Developer
Apr 26, 2013 at 8:40 PM
Edited Apr 26, 2013 at 8:40 PM
dancrevier wrote:
Thanks for your work here. I'm having trouble building. It looks like the latest SharpDX changed the signature of DrawingSurfaceBackgroundContentProviderNativeBase.PrepareResources. Is there a blessed SharpDX build that works? Or, are there changes planned to make it work with the latest builds?
It's already up to date.

This is the signature in XamlGame.cs:
public override void PrepareResources(DateTime presentTargetTime, ref Size2F desiredRenderTargetSize)

If SharpDX is looking for DrawingSizeF, then you need to update SharpDX to the latest dev build, here:
http://sharpdx-nightly-builds.googlecode.com/git/SharpDX-SDK-LatestDev.exe
Developer
Apr 26, 2013 at 8:41 PM
Edited Apr 26, 2013 at 8:41 PM
@AdamDawes575: Are you using DrawingSurface (not background grid)?
Apr 26, 2013 at 9:34 PM
Nezz, yes I am. My page XAML is as follows:
<phone:PhoneApplicationPage
[...]
    SupportedOrientations="PortraitOrLandscape" Orientation="Landscape"
    shell:SystemTray.IsVisible="False">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot">
        <MediaElement />
        <DrawingSurface x:Name="XnaSurface" />
    </Grid>

</phone:PhoneApplicationPage>
In my game class constructor I execute the following:
    // Set the supported orientations
    _graphics.SupportedOrientations = DisplayOrientation.Portrait | DisplayOrientation.LandscapeLeft |
                        DisplayOrientation.LandscapeRight;
In my Draw method I have this:
            _spriteBatch.Begin();
            _spriteBatch.DrawString(_miramonteFont, "Current orientation: " + Window.CurrentOrientation.ToString(), new Vector2(10, 100), Color.White);
            _spriteBatch.DrawString(_miramonteFont, "Window size: " + Window.ClientBounds.Width + ", " + Window.ClientBounds.Height, new Vector2(10, 130), Color.White);
            _spriteBatch.End();
(I know it's not efficient to build strings in the game loop, it's just test code.)

When I run and hold the device in portrait mode, everything appears correctly and it displays, "Current orientation: Portrait. Window size: 480, 800". When I switch to landscape orientation, the text appears horizontally stretched and vertically compressed and it says, "Current orientation: LandscapeLeft. Window size: 480, 800", so it's correctly identified the new orientation, but it hasn't reflected this in the window dimensions nor in the rendered graphics.

If I switch the XAML and class constructor to only support landscape, everything appears perfectly, undistorted and with the correct window dimensions (800, 480), but I can't get it to display properly in landscape at all if I indicate that both orientations are supported.

If you've any ideas I'd love to hear them as this is the only thing preventing me from wrapping up about three chapters. :-)
Apr 26, 2013 at 10:54 PM
I figured out my problem. When I'd done the git clone I'd ended up in the develop3d branch. I did a git checkout wp8_working and all is good now.
Apr 27, 2013 at 2:24 AM
What's the easiest way to manage x86 vs. ARM? It seems you need x86 for the emulator and ARM for the device. I can switch things in the Configuration Manager, but it seems like I have to manually swap the MonoGame framework reference.
Developer
Apr 27, 2013 at 7:33 AM
dancrevier wrote:
What's the easiest way to manage x86 vs. ARM? It seems you need x86 for the emulator and ARM for the device. I can switch things in the Configuration Manager, but it seems like I have to manually swap the MonoGame framework reference.
MonoGame does it automatically for you, just copy the new DLLs to the right directories. If you look inside MonoGame.Framework.WindowsPhone.csproj you will see this:
  <ItemGroup Condition=" '$(Platform)' == 'x86' ">
    <Reference Include="SharpDX">
      <HintPath>..\ThirdParty\Libs\SharpDX\Windows Phone\x86\SharpDX.dll</HintPath>
      <SpecificVersion>False</SpecificVersion>
    </Reference>
...etc...
  </ItemGroup>
  <ItemGroup Condition=" '$(Platform)' == 'ARM' ">
    <Reference Include="SharpDX">
      <HintPath>..\ThirdParty\Libs\SharpDX\Windows Phone\ARM\SharpDX.dll</HintPath>
      <SpecificVersion>False</SpecificVersion>
    </Reference>
...etc...
  </ItemGroup>
Apr 27, 2013 at 2:32 PM
Actually, I meant in the project for my app. How people referencing MonoGame.Framework.dll? Do you use conditionals like this in your game's project?
Apr 27, 2013 at 7:54 PM
Dan, if you create your app project from one of the supplied project templates, it'll automatically have the conditional references that Nezz mentioned in place. If you need to create your project via some other means, you'll need to edit the .csproj file manually (e.g., in Notepad) and copy in the <ItemGroup Condition...> blocks from the project template's .csproj file. Once you've done that it'll automatically switch between the referenced DLLs when you change build configuration.
Apr 27, 2013 at 9:34 PM
Thanks. I had removed the monogame reference from my project and then readded it pointed to my private build of the framework. I guess you can just leave the project alone if you go and replace the ones in the installed location, although I just modified my project by hand to include the conditionals.
Developer
Apr 28, 2013 at 11:29 PM
Ohh, I missed that one. You have to add MonoGame as a project, not a dll :) Updating the starter post...
May 2, 2013 at 2:35 AM
Thanks for pulling this together, Nezz. I found a couple of bugs in my code with my app. If you'd like I can send a push request. They happen if you mix plain XAML pages and a game page. To repro, modify the WP sample application's game page with the following in the constructor:
this.BackKeyPress += (s, e) => e.Cancel = false; // Take away XNA control over back navigation...
this.Unloaded += (s, e) => Dispatcher.BeginInvoke(() => game.Dispose());
Then, add a new .Xaml page that has a button that navigates to your game page and make it your entry point.

Bug 1:
  1. Launch the app
  2. Hit the Windows button
Result: crashes in the anonymous handler for PhoneApplicationService.Current.Deactivated in MediaPlayer's static constructor. The fix is to check _meidaElement for null in both the activated and deactivated handlers.

Bug 2: (reported https://monogame.codeplex.com/discussions/441747)
  1. Launch the app
  2. Navigate to the game page
  3. Hit back twice
Result: crash on quit in the PhoneAPplicationService.Current.Closing anonymous handler in the WindowsPhoneGameWindow. The fix is to check Game.Instance for null in all the handlers here.

I suspect there could also be some leaks going to and from the game page since some of the handlers like the WIndowsPhoneGameWindow ones are never removed, but I haven't verified.

Do you want me to push the changes (will require a bit of set up on my part), or do you want to just make the changes yourself?
Developer
May 2, 2013 at 11:19 AM
dancrevier wrote:
Do you want me to push the changes (will require a bit of set up on my part), or do you want to just make the changes yourself?
Bug 1 is related to this PR I submitted:
https://github.com/mono/MonoGame/pull/1633
The branch:
https://github.com/Nezz/MonoGame/tree/wp8_mediaplayerresume

Bug 2 is also one of my PRs:
https://github.com/mono/MonoGame/pull/1632
The branch:
https://github.com/Nezz/MonoGame/tree/wp8_activated

Please submit the fixes to the appropriate branches. I will merge them and cherry pick them into the wp8_working branch.
May 4, 2013 at 12:47 PM
If SharpDX is looking for DrawingSizeF, then you need to update SharpDX to the latest dev build, here:
http://sharpdx-nightly-builds.googlecode.com/git/SharpDX-SDK-LatestDev.exe
The above link doesn't fix this problem. Not sure if its been removed again?
Developer
May 5, 2013 at 7:50 PM
Gmotagi wrote:
If SharpDX is looking for DrawingSizeF, then you need to update SharpDX to the latest dev build, here:
http://sharpdx-nightly-builds.googlecode.com/git/SharpDX-SDK-LatestDev.exe
The above link doesn't fix this problem. Not sure if its been removed again?
It wasn't. I'm pretty sure you haven't replaced the referenced DLLs in the MonoGame directory :)
May 5, 2013 at 10:41 PM
Or, you might have forgotten to switch to the right branch after cloning Nezz's repository (that was my problem).
May 9, 2013 at 4:47 PM
I've managed to publish my first game using this on WP8. The game is called MonsterUp Memory and it's free. I seem to have a small issue with resuming, but I am not sure if it's MonoGame related or it's just my code (it happens only while playing). Thank you very much for your efforts!
The game is available here: http://www.monsterupgame.com/app/monsterup-memory/
Developer
May 9, 2013 at 11:43 PM
You are welcome :)

Make sure that fast app resume is not enabled (the new WP8 resume instead of re-launching the app). That thing causes some strange things to my surprise.
Developer
May 17, 2013 at 9:47 AM
Bumping this so it will be easier to find for newcomers.
May 19, 2013 at 10:56 PM
Just started testing this on my phone (920) to see if I could get my game working. Just trying the sample first and if I use the DrawingSurfaceBackgroundGrid in my xaml everything works fine and it deploys, but if I switch it to a DrawingSurface I get an excepting during initialization. Here is the XAML
    <Grid x:Name="LayoutRoot">
        <MediaElement />
        <DrawingSurface x:Name="XnaSurface" />
    </Grid>
And here is the constructor
        public GamePage()
        {
            InitializeComponent();
            _game = XamlGame<Game1>.Create("", this);
        }
When I run it I get this exception: An exception of type 'System.TypeLoadException' occurred in Unknown Module. but was not handled in user code

on Line 69 of DrawingSurfaceUpdateHandler.cs. It looks like it fails to initialize the Device correctly, but I'm not sure. Any idea what could be causing this issue?
May 20, 2013 at 4:26 PM
Edited May 20, 2013 at 4:26 PM
What is your root control? Looking at your code it seems to me that you have both. In order to have DrawingSurface instead of DrawingSurfaceBackgroundGrid you will actually have to replace the DrawingSurfaceBackgroundGrid with it and not adding it on top of DrawingSurfaceBackgroundGrid.
May 20, 2013 at 7:10 PM
Edited May 20, 2013 at 9:14 PM
pixelfury wrote:
What is your root control?
The grid is my root element. I don't have a DrawingSurfaceBackgroundGrid in my xaml.

I think I might have a solution, but I can't test it till later tonight (I'll edit this post when I do). I'm thinking it's an issue with the references on the project. I linked to the monogame project file that had the conditional references, but I only copied the .dll files from the SharpDX build, so I am missing the SharpDX.WP8.winmd file. I'm hoping if I supply that file that it will work.

Edit: Yep, attaching the correct SharpDX.WP8.winmd file fixed it. I no longer get that error and it loads fine.
May 21, 2013 at 10:33 PM
Edited May 22, 2013 at 5:26 AM
Hi everyone,

Thank you all for your time and effort, I was very happy the day I found out Monogame existed.

I have a little hobby game I've been trying to port over to Monogame from XNA 4.0(wp7). I've re-read this thread and few others so many times over last few weeks trying to get it working but I keep running into problems with the sound effects. I'm a UI developer by trade, so there's probably something really simple that I'm missing.

I've grabbed Nezz's Git (Clone in windows with the branch set to wp8_allworking (I've also checked out crnjan's build as well). I also got both the SharpDX-SDK-LatestDev.exe and their git build.

Copied the appropriate (x86/ARM) Sharp DX DLLs into the following Monogame git directory. (I've tried both the sharp git build and the .exe)
git\MonoGame\ThirdParty\Libs\SharpDX\Windows Phone\ARM (& x86)

Copied the project template
from --> git\MonoGame\ProjectTemplates\VisualStudio2012\WindowsPhone
to a new folder --> Documents\Visual Studio 2012\Templates\ProjectTemplates\Visual C#\Nezz

Create a project with this template. File > Add > Existing Project. Select the monogame .csproj (tried .sln as well). It adds. (At this point I've noticed that Nezz's project has issues, the folder WindowsPhone is removed from the 'Windows' directory and fails to build). crnjan's build has this fixed it looks. I have gotten Nezz's build to work by directly referencing the x86 DLLs and only running in emulator. This is probably an easy fix, havn't looked into it.

I then include an existing content project from an old XNA solution. I've also tried the new monogame 3.0.1 content project and also just including a pre-compiled content directory. If I include the content project, I set a 'BeforeBuild' option in the csproj to get it to build before the project.

Depending on which combination i've done. The GamePage.xaml.cs needs either
_game = XamlGame<Game1>.Create("", XnaSurface); or
_game = XamlGame<Game1>.Create("", this);

I may also have to add a <MediaElement id="mediaElement" /> to the GamePage.xaml

After all of this is done, and i've moved my game classes etc into place. I can get it to build ok. The emulator fires up but the game will only run if i remove all my sound effect resoures from loading --> MySound = content.Load<SoundEffect>("Sounds\MySound")

The rest of the content loads fine. I have checked that the compression quality of the sound is set to 'Best'.

exception of type 'System.TypeInitializationException' occurred in MonoGame.Framework.DLL
Typename or Namespace was not found in metadata file. (Exception from HRESULT: 0x8000000F)
at SharpDX.XAudio2.XAudio2Functions.get_XAudio2Create_()

I've noticed nobody here is talking anymore about the sound effects, suggesting that this branch has it fixed. Does anybody have any insight as to where I'm going wrong.

Thanks in advance.

tl;dr - my WP8 app refuses to load sounds and I'm out of ideas :(
May 22, 2013 at 6:32 PM
I'm very new to MonoGame but I think it is awesome to create C# games in a great framework to WP8. Looking forward to use the cross platform though. :-)

But I have three comments/questions I hope someone can help with. I have tried lated source and SharpDX and build locally, and still same issues.

1) Same problem as invective and others. Not able to load content of soundeffect. I saw somewhere that it might be caused by SharpDX, but do they solve it?
2) When I in my game page click home and afterwards click back, I come to my NavigateTo but nothing is rendered. I assume this what Nezz last comments is about in initial post, but what should I do?
3) Not able to compile for any cpu. This prevent me to use Visual Studio Store Test Kit which could save me some test time. Is this just a fact?

Thanks in advance
Coordinator
May 23, 2013 at 1:08 AM
3) We cannot use AnyCPU due to the omission of DllImport in Windows Phone. See this Connect issue for more information (and vote for it).

Developer
May 23, 2013 at 11:31 AM
@invective and @JerryAndersen:
Sound effects are working fine here. I believe the error is related to the SharpDX.WP8.winmd file. My best bet is to redownload the latest SharpDX dev build (2.5.0) and copy ALL the files into MonoGame's proper library folders. Don't miss out anything, like exes or the winmd file.
Coordinator
May 23, 2013 at 11:47 AM
I've just ported my Windows 8 game to Windows Phone 8 using Nezz's branch and the latest SharpDX libraries and sound effects work fine.​ I just copied the files into the ThirdParty/Libs/SharpDX/Windows Phone folder (all the dll, xml files and one winmd file).
Developer
May 24, 2013 at 11:43 AM
SharpDX 2.5.0 is now included to make this easier to use. Make sure to update the subprojects.
May 26, 2013 at 11:50 PM
I got the sound working, it's still a little flakey. I think my original problem was that I had somehow referenced some XNA libraries still. Thanks for trying to help out Nezz, but I wasn't sure how to update the sub-projects in git :) So my Libs folder was still empty on checkout.

Now to sort out the orientation and resolution concerns :)

Cheers.
May 27, 2013 at 7:44 PM
Seems like sound is working with new SharpDX files.
Furthermore my problem regarding that I couldn't step back to my game page after clicking home is also working, so that is perfect.

Thanks a lot
Jun 2, 2013 at 2:18 PM
Hi, sorry if this is a stupid question, but what exactly should I do to get my 3d game to resume correctly using the fork mentioned in the first post which supposedly contains a fix for this problem? At the moment I am just getting a blank window after resuming.

Thanks
Jun 2, 2013 at 2:46 PM
Perhaps forgotten to fill Vertex- and IndexBuffers after a DeviceReset?

Something along the line of:
GraphicsDevice.DeviceReset += (o, e) =>
{
   vertexBuffer.SetData<VertexPositionNormalTexture>(vertices);
   indexBuffer.SetData<int>(indices);
};
Does it work then?

Stephan
--
http://www.software7.com
Jun 2, 2013 at 2:48 PM
@Gerhman
I expect you have latest Monogame and SharpDx, and you are able to build it.

If so you should add the MonoGame.Framework.WindowsPhone.csproj to your 3d game solution. When that also can build you should remove your existing Monogame reference and instead add a project reference to your newly added project.

After that I assume you have an build error in:
_game = XamlGame<GameEngine>.Create("", XnaSurface);
which should be changed to
_game = XamlGame<GameEngine>.Create("", this); if it is located in your page.

That should be all, hope it will help you.
Jun 3, 2013 at 5:00 AM
@stephan7 Thanks that completely solves my problem!
Jun 4, 2013 at 2:01 PM
Hi.

Can't play sound effect with this version.

I'm using this code snippet for playing:
SoundEffect sound = Content.Load<SoundEffect>("select");
SoundEffectInstance soundInstance = sound.CreateInstance();
soundInstance.Play();
There is no exception, I just don't hear sound. Also I've found that even if I set Volume property for SoundEffectInstance explicitly it always reseted to 0.

My sounds are xnb files built from wav files using XNA 4 content pipeline. When I use same xnb files and code in XNA 4 project everything is fine.
Jun 5, 2013 at 2:12 AM
adogg wrote:
Hi.

Can't play sound effect with this version.

I'm using this code snippet for playing:
...
I tried many different things to get my sound to work, and once combination caused this same issue (Sounds load, but do not play, no exception). I'm sorry I cannot provide more info about what the exact issue was. But I eventually got it working with the latest build. I have a feeling that I was still referencing the XNA DLLs from the original project or something (Not the sharp DX).

Good luck.
Jun 5, 2013 at 8:52 AM
stephan7 wrote:
Perhaps forgotten to fill Vertex- and IndexBuffers after a DeviceReset?

Something along the line of:
GraphicsDevice.DeviceReset += (o, e) =>
{
   vertexBuffer.SetData<VertexPositionNormalTexture>(vertices);
   indexBuffer.SetData<int>(indices);
};
Does it work then?
This is presumably a bug in the WP8 MonoGame code, I'm sure that this should happen automatically when the app resumes? Any chance of someone implementing a fix for this?
Jun 5, 2013 at 9:05 AM
That would be one possible solution.

I personally think that it shouldn't be handled by the framework, because then it would need to cache the data.
And the GraphicsDevice.DeviceReset can be applied very easily by a game dev.
I think I can also remember that Android also does not handle it automatically (for the same reason I guess).

Stephan
--
http://www.software7.com
Jun 5, 2013 at 9:42 AM
It was automatically handled by XNA, and isn't a problem in Win8 apps. For consistency and backward compatibility, I think it should be fixed...
Developer
Jun 5, 2013 at 11:33 AM
Edited Jun 5, 2013 at 11:33 AM
AdamDawes575 wrote:
It was automatically handled by XNA, and isn't a problem in Win8 apps. For consistency and backward compatibility, I think it should be fixed...
Feel free to make a pull request into my branch with the fix :)
Jun 6, 2013 at 12:00 PM
Edited Jun 6, 2013 at 12:01 PM
Hello nez, I want to ask something about using this source code (since I'm new to monogame). At the first, I am using the installed version, but after I post my problem here : https://monogame.codeplex.com/discussions/445666 . I then follow it while not uninstalling the current monogame installed.

These are my step by step in using your source, please correct mine if there is any incorrect step :
  1. I cloned your wp8_working branch into my computer.
  2. I copied your project into my project folder.
  3. I extracted the SharpDX downloaded from your opening post link into my Third Apps folder in cloned project that has been copied into my project folder.
  4. I opened my project, then Add Existing Project the Monogame.Framework.WindowsPhone CSPROJ file from the solution explorer.
  5. I remove all the warning SharpDX reference in your Monogame project solution, and change it into the set downloaded from above link (the Windows Phone x86 one, because I am using Emulator)
  6. The reference I add are : SharpDX.dll, SharpDX.Direct3D11.dll, SharpDX.DXGI.dll, SharpDX.MediaFoundation, SharpDX.WP8.winmd
  7. I then remove the Monogame.Framework from my Project reference (the one which path is to the installed Monogame)
  8. I then add the Project Dependencies targeting your added project.
Compiled it, and find no error, but the problem is not solved at all. The purpled area below is still usually unclickable (There is a moment when I can click it, but it's not consistently able to be clicked. Usually, it is not able to be clicked). I also never add any textbox, nor coded any textbox ever in this project mine.

The screenshot will be found here : http://gamedev.stackexchange.com/questions/56576/how-to-fix-monogame-wp8-touch-position-bug . The main problematic columns is column number 1,2,3 from right.

Any idea what caused this? Thanks.
Developer
Jun 6, 2013 at 9:30 PM
Edited Jun 6, 2013 at 9:32 PM
moztheblessed wrote:
Any idea what caused this? Thanks.
Sorry, I didn't see your reply in the other thread. As I said, it's probably your GamePage.xaml. This is what it should look like:
<phone:PhoneApplicationPage
    x:Class="your namespace here"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Landscape"
    shell:SystemTray.IsVisible="False">

    <DrawingSurfaceBackgroundGrid x:Name="XnaSurface" Background="Transparent">
        <MediaElement x:Name="XnaMediaElement" HorizontalAlignment="Left" VerticalAlignment="Top"/>
    </DrawingSurfaceBackgroundGrid>

</phone:PhoneApplicationPage>
Jun 7, 2013 at 12:38 PM
Thanks Nezz and MonoGameTeam. I got my game AudioFox ported over from a Windows Phone 7 -> Windows Store Game to Windows Phone 8. Setup was a little bumpy but once things started rolling it went great.

For others it might be good to know that if you have other projects in your game solution you want to port and reference Nezz's branch of Monogame... you have to update your project files. Otherwise you get a load of conflicts from the XNA that comes with windows phone 8 games out of the box.This link shows you how to update your project files to ignore the default XNA libs. Nezz's Monogame Windows Phone template already has these changes so you wont need to do it for the main game only other libs you may need to create(ie: Windows Phone 8 class library)

http://www.codeproject.com/Articles/585824/MonoGame-3aplusUsingpluslibrariespluswithplusWindo
Jun 7, 2013 at 2:17 PM
Thank you nezz. Idk why there are stackpanels in my GamePage.xaml. Since I never code in it before. Thanks once again.
Jun 7, 2013 at 2:52 PM
Edited Jun 7, 2013 at 2:53 PM
@moztheblessed You most likely made a change in the graphical version of GamePage.xaml which results in changes in the code or GamePage.xaml.cs. Once it is set up you shouldn't need to change anything in there.
Developer
Jun 7, 2013 at 11:23 PM
Edited Jun 7, 2013 at 11:24 PM
kbo4sho wrote:
@moztheblessed You most likely made a change in the graphical version of GamePage.xaml which results in changes in the code or GamePage.xaml.cs. Once it is set up you shouldn't need to change anything in there.
The project template at the time of the first news of WP8 support were not user friendly. It had wrong namespaces which needed to be corrected manually, and it also had the default text on the page which ate up the touch.
Jun 10, 2013 at 1:50 PM
Hi there.

I'm trying to update my WP7 game to WP8 using this fork & branch. I'm getting a build error when I come to deploy to the emulator, though
(in GamePage.xaml.cs):
The name 'InitializeComponent' does not exist in the current context
The name 'XnaSurface' does not exist in the current context
The name 'XnaMediaElement' does not exist in the current context
Everything else seems to build fine. I've also diffed the files against the template files in the fork and everything seems to be fine. I have also tried downloading the SharpDX files, extracting them and copying the contents of .\Bin\Standard-wp8-x86 over the files in ThirdParty\Libs\SharpDX\Windows Phone\x86 and the same for ARM.

Any ideas what I'm missing? I saw a reference above to switching _game = XamlGame<Game1>.Create("", XnaSurface); to _game = XamlGame<Game1>.Create("", this); but no reference to InitializeComponent().
Developer
Jun 12, 2013 at 11:57 AM
Since it can't find InitializeComponent, I'm pretty sure you changed some namespaces and those changes were not made in the XAML.
Jun 19, 2013 at 9:56 PM
Edited Jun 19, 2013 at 10:01 PM
Has this been merged back to MonoGame/develop yet?

Edit (< 1 minute later..):
of course it has.. I've made changes to the WP8-project myself as well. Anyhow.. I'm having issues with TouchPanel.GetState() returning Infinity for position. Known issue?

Edit #2
I think I need some sleep...
GetState() works fine in the develop-branch. But not so much in the latest stable release. So.. My bad. Ignore me. :)
Developer
Jun 20, 2013 at 4:44 PM
Partially merged. We are currently working on updating the rest of the changes to be able to merge.
Jun 21, 2013 at 5:50 PM
Edited Jun 21, 2013 at 5:57 PM
Hi everyone, having a play with this on my Nokia Lumia 920. Using the steps shown in the top post I've got it working and it's flippin' excellent :)

However, I've noticed some strange behaviour with TouchPanel.GetState(). If I quickly place my fingers on the screen and then take them off again I seem to end up in a situation where I don't get a set of matching TouchLocationState.Released entries for every TouchLocationState.Pressed event.

For example, just now in the debugger, when I call TouchPanel.GetState in the Update loop, I'm constantly getting a number of entries returned even though I'm no longer touching the screen. All the entries are flagged as having a state 'Moved'.

Inside this function
   public static TouchCollection GetState()
    {
        // Process the touch state.
        var consumeState = true;
        while (RefreshState(consumeState, _touchState, _touchEvents))
            consumeState = false;

        return new TouchCollection(_touchState.ToArray());
    }
_touchEvents is empty and _touchState contains the invalid (?) TouchLocation entries. These never get cleared.

As I said, it only seems to happen with this rapid tapping of the screen using as many fingers as I can fit.

Hope this is the right place to post this sort of thing. Any ideas what could be causing this?

cheers
Developer
Jun 22, 2013 at 1:07 PM
If the debugger is attached, the touch starts acting strange and the game slows down. Are you experiencing this when not debugging?
Jun 22, 2013 at 1:43 PM
Hi Nezz, yes, happens when i try it out on my phone outside of the debugger. Only seems an issue with lots of fingers placed on the screen at the same time and taken off quickly and repeated.

cheers
Developer
Jun 23, 2013 at 12:27 PM
ishy44 wrote:
Hi Nezz, yes, happens when i try it out on my phone outside of the debugger. Only seems an issue with lots of fingers placed on the screen at the same time and taken off quickly and repeated.

cheers
Since the changes of this branch were merged into the main branch, please check out this issue with that and if it persists, open an issue with it.
Jun 24, 2013 at 9:42 PM
Edited Jun 25, 2013 at 7:30 PM
Nezz wrote:
ishy44 wrote:
Hi Nezz, yes, happens when i try it out on my phone outside of the debugger. Only seems an issue with lots of fingers placed on the screen at the same time and taken off quickly and repeated.

cheers
Since the changes of this branch were merged into the main branch, please check out this issue with that and if it persists, open an issue with it.
Hi Nezz, tried the latest source and it still happens. I've put some debugging code in AddEvent (TouchPanel.cs) to record the events I get during testing. I think what seems to be happening is I'm getting sent a 'Pressed' event but no corresponding 'Released' event. The 'Released' even never arrives hence the problem. I'll open an issue.

Update : I'm not sure the problem is with Monogame. I've managed to reproduce the problem in a tiny 'Windows Phone and Direct3D' App. In C++ I just store a vector inside the default IDE generated Direct3DInterop class that records pressed events and released events
   void Direct3DInterop::OnPointerPressed(DrawingSurfaceManipulationHost^ sender, PointerEventArgs^ args)
   {
    uint32 pointerID = args->CurrentPoint->PointerId;

    auto i = std::find (_pressed.begin(), _pressed.end(), pointerID);
    if (i == _pressed.end())
        _pressed.push_back(pointerID);
  }
void Direct3DInterop::OnPointerReleased(DrawingSurfaceManipulationHost^ sender, PointerEventArgs^ args)
{
    uint32 pointerID = args->CurrentPoint->PointerId;

    _pressed.erase(std::remove(_pressed.begin(), _pressed.end(), pointerID), _pressed.end());
}
In my XAML, I just have a textblock and a dispatch timer that periodically checks the count of elements in _pressed (it should always return to 0).
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent" 
      Margin="0,115,0,0">
    <DrawingSurface x:Name="DrawingSurface" Margin="0,-113,0,0" Loaded="DrawingSurface_Loaded"/>
    <TextBlock x:Name="LostReleasedCount" Text="Lost released count = 0" HorizontalAlignment="Left" Margin="0,-113,0,0" VerticalAlignment="Top" Height="113" Width="480"/>

</Grid>
and in the code behind file
    private Direct3DInterop m_d3dInterop = null;
    private DispatcherTimer _timer;
    private int _seconds;

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);

        // Creates a new instance of a timer.
        _timer = new DispatcherTimer();

        // Tells the _timer to tick every  second.
        _timer.Interval = TimeSpan.FromSeconds(1);


       _timer.Tick += TimerOnTick;
        _timer.Start();
        _seconds = 0;

    }

    private void TimerOnTick(object sender, EventArgs eventArgs)
    {

        Dispatcher.BeginInvoke(() =>
        {
            _seconds++;
            LostReleasedCount.Text = "Lost released count = " + m_d3dInterop.GetPressedCount().ToString();
        });
    }
Am I missing something obvious here?
Jun 26, 2013 at 9:57 PM
Well, I've got a solution, albeit a slightly hacky one. I can still get FrameReported events from the owning PhoneApplicationPage. So, I've added some code that just records a list of ids, adding when I get a TouchAction.Down and removing when I get a TouchAction.Up. Then I just scan the TouchCollection returned by TouchPanel.GetState and if it's > 0 and the ids list == 0, force all touch states to be released from TouchPanel (by making ReleaseAllTouches public). Seems to work fine, but is really a workaround for released events going missing somewhere in the murky depths of DirectX (presumably).
Jun 28, 2013 at 9:24 AM
I had problems with the TouchPanel.GetState(); infinity bug.
Now it's working fine with the 2 changes.
            _game = XamlGame<Game1>.Create("", this);
and adding
        <MediaElement />
above
</DrawingSurfaceBackgroundGrid>
Got those changes from posts above maybe someone can explain those changes?
Jul 1, 2013 at 1:33 PM
Fantastic having these issues addressed: this has dropped my #ifdef count measurably (only lifecycle and external wrapper code to worry about now!)

Question: what do I need to do to ensure that my VS templates pick up this version? I'm having problems with the x86 version where there seems to be a clash between this and v3.0.0 (despite my changing the references), which limits my testing ability?

Ideally, it would be really good if these changes could be rolled into an update for the VS templates...

Otherwise - excellent!
Ben
Jul 2, 2013 at 5:41 PM
Edited Jul 2, 2013 at 6:13 PM
Nezz, I hope you read this.

http://gamedev.stackexchange.com/questions/58317/ambiguation-between-multitouch-geistures-tap-and-free-drag-in-windows-phone-8-em\

Craftworkgames says it is a bug, but I don't know exactly what the problem is.

(I'm using Monogame 3.0, not currently using this branch)

Thanks.

EDIT : Sorry, it seems that I pressed on a area not quick enough to freedrag. It's done well now if there is no delay between "tap" and drag to freedrag
Jul 8, 2013 at 10:57 AM
Edited Jul 8, 2013 at 11:27 AM
I have 2 questions but first I want to thank everyone for there hard work in this. I'm about 90 % done in porting my Windows 8 game over to WP8 my game is all in landscape mode so following your instructions worked out perfect.

I'm only stuck in saving and loading data. It seems the method I was using in my WP7 projects no longer works. Wanted to know how are you guys handling saving and loading game data.

Also how do i lock the screen orientation so that it's on Landscape Left. I edit my xaml file but still using my 920 i'm able to shift the orientation either Landscape left or right. I just want to lock it down to Landscape left.

I think once i get over this hurdle i'm pretty much done! If you can direct me to some instructions or a sample that would be awesome!.

Thank you for your time.
Jul 8, 2013 at 2:10 PM
There should be an example(template?) of using MonoGame for WP8 in Landscape mode.

This worked for me:
Remove the DrawingSurfaceBackgroundGrid, inside GamePage.xaml and replace it with this:
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <DrawingSurface x:Name="XnaSurface"/>
        <MediaElement></MediaElement>
    </Grid>
Now just change the Orientation and SupportedOrientations to Landscape, on the PhoneApplicationPage xaml properties:
SupportedOrientations="Landscape" Orientation="Landscape"
This worked for me.

Anything else needs to be done?
Jul 8, 2013 at 3:03 PM
Thanks for your response. That's exactly what I have. And landscape does work. Problem is if I turn the hone landscape mode will shift to landscape right. I want it to stay on Landscape Left. Orientation is set on Landscape Left but it still shifts anyway. Any Ideas?

To clarify it does not go to Potrait mode which is what I want! But landscape mode does shit between left and right depending on how you hold the phone.
Just want it to stay on Landscape left.
Jul 14, 2013 at 9:05 PM
Hello all just when I thought I was done. I can toombstone my app once.. If I launch the game tombstone it then resume again I get a white screen with nothing on it. I'm reading on here and it says I can add this bit of code to fix my problem

GraphicsDevice.DeviceReset += (o, e) =>
{
vertexBuffer.SetData<VertexPositionNormalTexture>(vertices);
indexBuffer.SetData<int>(indices);
};

Just don't know where to add it. Any Ideas?

I have the latest develop branch and I'm using drawingsurface for my landscape fix. Thank you very much for reading.
Jul 26, 2013 at 7:40 AM
Edited Jul 26, 2013 at 9:42 AM
Hello. I found an error while trying to use landscape only orientation on my apps.

These are the errors :

Error 1 The best overloaded method match for 'MonoGame.Framework.WindowsPhone.XamlGame<Micro_Ace.Game1>.Create(string, System.Windows.Controls.DrawingSurfaceBackgroundGrid)' has some invalid arguments D:\KP\Backup\2013-07-26\1\Micro_Ace\Micro_Ace\GamePage.xaml.cs 25 21 Micro_Ace

Error 2 Argument 2: cannot convert from 'Microsoft.Phone.Controls.PhoneApplicationPage' to 'System.Windows.Controls.DrawingSurfaceBackgroundGrid' D:\KP\Backup\2013-07-26\1\Micro_Ace\Micro_Ace\GamePage.xaml.cs 25 48 Micro_Ace

This is my GamePage.xaml :
<phone:PhoneApplicationPage
    x:Class="Micro_Ace.GamePage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Landscape" Orientation="Landscape"
    shell:SystemTray.IsVisible="False">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot">
        <MediaElement />
        <DrawingSurface x:Name="XnaSurface" />
    </Grid>

</phone:PhoneApplicationPage>
and this is my GamePage constructor :
public GamePage()
        {
            InitializeComponent();

            _game = XamlGame<Game1>.Create("", this);

            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();
            
        }
(I also have seen the XamlGame in Nezz project and I am sure that the Create method has PhoneApplicationPage instead of DrawingSurfaceBackgroundGrid)

Any idea what caused this? My guess is that Nezz's wp8_working is not included correctly in my project, but how? Thanks.

One more, if it's successfully converted into landscape only, the emulator will shows up landscape too yes?
Aug 11, 2013 at 2:32 PM
Edited Aug 11, 2013 at 2:33 PM
Well done Nezz and other contributed to the WP8 port.
Though I don't know the magic behind it, my game runs even much smoother on MonoGame WP8 than my native XNA version.
Aug 11, 2013 at 10:31 PM
moztheblessed,
By looking at the error you got, your XamlGame.Create function is the old day one.
Make sure you clone the latest one from main branch : https://github.com/mono/MonoGame
Aug 12, 2013 at 5:13 PM
Hello, I have difficulty to use the project mono/MonoGame as my project template. This is what i've done :
  1. Install MonoGame 3.0.1
  2. Download SharpDX 2.5.0 from the OP link
  3. Clone mono/MonoGame
  4. Locate installed sharpDX and replace the entire folder with the newly downloaded SharpDX
  5. Create a new project using Monogame Windows Phone 8 template
  6. Replace the files in that new project with files copied from \MonoGame\ProjectTemplates\VisualStudio2012\WindowsPhone (from cloned project)
  7. Replace $safeprojectname$ in the project with MyProjectName
There also an unsolved problem under this error message :
The name "LocalizedStrings" does not exist in the namespace "clr-namespace:MyProjectName".

Any step I've missed or wrongly executed? Can you show me the right way to set this project up to the new developed MonoGame?

Sorry for this noobish question :) Hope you can help me.
Developer
Aug 12, 2013 at 5:18 PM
Open the LocalizedStrings.cs class and make sure it is in the proper namespace for your project.

Make sure that the assembly UID and the project UID also match up. You may find that it all builds, and deploys, but when you run it on the simulator, it starts and stops immediately and never launches in your Game class.

Make sure that your namespaces, UIDs, and names are correct in the XML files contained in the Properties directory.
Aug 13, 2013 at 7:06 PM
Edited Aug 13, 2013 at 7:08 PM
Thanks for your answer

But when MyProject cleaned, these are what I got :
  1. Error 1 The name "LocalizedStrings" does not exist in the namespace "clr-namespace:MyProject". D:\KP\Backup\2013-08-14\MyProject\MyProject\App.xaml 10 9 MyProject
  2. Error 1 The name "LocalizedStrings" does not exist in the namespace "clr-namespace:MyProject". D:\KP\Backup\2013-08-14\MyProject\MyProject\App.xaml 1 1 MyProject
And when I build it (with both x86), these messages shows up (in addition to the two above) :
  1. Error 17 An assembly with the same simple name 'MonoGame.Framework, Version=3.0.1.0, Culture=neutral, PublicKeyToken=null has already been imported. Try removing one of the references or sign them to enable side-by-side. c:\Program Files (x86)\MonoGame\v3.0\Assemblies\WindowsPhone\x86\MonoGame.Framework.dll MyProject
  2. Warning 16 No way to resolve conflict between "MonoGame.Framework, Version=3.0.1.0, Culture=neutral, PublicKeyToken=null" and "MonoGame.Framework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null". Choosing "MonoGame.Framework, Version=3.0.1.0, Culture=neutral, PublicKeyToken=null" arbitrarily. MyProject
Any idea why these happened? And how to fix this? Because I've checked the namespaces and there seems no problem.

Do I need to uninstall the MonoGame 3.0 first? Since I have both the 3.0 and 3.0.1 installed (but I personally think this is not the problem)

This is my LocalizedStrings.cs (Although I didn't find any weirdness) :
using MyProject.Resources;

namespace MyProject
{
    /// <summary>
    /// Provides access to string resources.
    /// </summary>
    public class LocalizedStrings
    {
        private static AppResources _localizedResources = new AppResources();

        public AppResources LocalizedResources { get { return _localizedResources; } }
    }
}
Thanks.