2
\$\begingroup\$

Does every Windows Phone have one of the following 4 resolutions? 800x480, 1280x768, 1280x720, 1920x1080 pixels

Or is it possible that some devices only have a resolution of 1280x719 or 1279x720 pixel?

I use this code to determine the resolution of the device:

Resolution = new Vector2(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);

But if I use the 720p and 1080p emulators, then I have the following results:

Resolution = Width:1279 Height:720 

Why is the resolution width 1279 pixel and not 1280 pixel wide?

I get the same results with this code:

width = GraphicsDevice.PresentationParameters.BackBufferWidth;
height = GraphicsDevice.PresentationParameters.BackBufferHeight;

Is there a difference between GraphicsDevice.PresentationParameters.BackBufferWidth and GraphicsDevice.Viewport.Width? Which one should I use to determine the resolution of a Windows Phone device?

\$\endgroup\$
  • \$\begingroup\$ The viewport dimensions can be changed to suit your needs and are (almost) independent of the graphics device. \$\endgroup\$ – d3dave May 14 '14 at 5:04
  • \$\begingroup\$ Why does it matter? What are you using the resolution values for? \$\endgroup\$ – craftworkgames May 14 '14 at 6:21
  • \$\begingroup\$ I need to know the resolution values because I use different sprites for every resolution. \$\endgroup\$ – Homer_Simpson May 14 '14 at 16:04
  • \$\begingroup\$ You could then just define ranges. I think the 1 pixel error may be related to some internal scaling to fit the physical screen \$\endgroup\$ – floAr Jun 17 '14 at 13:52
1
\$\begingroup\$

A good place to go for these sorts of questions is the technical requirements specification of your platform, if it exists. Fortunately for Windows Phone 8, it does.

From the section on multi-resolution applications, you can see that 480x800, 768x1280, 720x1280 and 1080x1920 resolutions are the only ones supported (for WP8, update 3, as of this writing). That means you should support all of them, although an individual phone may only support a subset of them.

Thus, no Windows Phone 8 device should have a resolution of 1280x719 or 1279x720. Your code to detect the resolution is actually detecting the viewport width and height, which may in theory be different than the actual resolution for various reasons. The documented method to test the resolution is via App.Current.Host.Content.ScaleFactor, as in this code from the MSDN:

public enum Resolutions { WVGA, WXGA, HD };

public static class ResolutionHelper
{
   private static bool IsWvga
   {
      get
      {
         return App.Current.Host.Content.ScaleFactor == 100;
      }
   }

   private static bool IsWxga
   {
      get 
      { 
         return App.Current.Host.Content.ScaleFactor == 160; 
      }
   }

   private static bool IsHD
   {
      get 
      { 
         return App.Current.Host.Content.ScaleFactor == 150; 
      }
   }

   public static Resolutions CurrentResolution
   {
      get
      {
         if (IsWvga) return Resolutions.WVGA;
         else if (IsWxga) return Resolutions.WXGA;
         else if (IsHD) return Resolutions.HD;
         else throw new InvalidOperationException("Unknown resolution");
      }
   }
}

That said, you may want to continue detecting the viewport size instead of the actual resolution, depending on your actual subsequent usage; one reason the viewport can be smaller is if the OS reserves some portion of the screen for any reason, and you may want your code to react accordingly to that. Or you may not. Thus, it's important to be aware of the potential differences in either value and choose the one appropriate for the scenario.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.