3

I'm building a little game using NodeJS and EaselJS that runs great in-browser, locally hosted. I downloaded Visual Studio and started the process of creating a UWP from it so that I can play on my Xbox One. Visual Studio is basically just the middle man, as I am using the "Start Page" and pointing it to my locally hosted web server to create the app, rather than try to re-invent the wheel.

I'd like to take advantage of some of the Windows.UI functions ONLY WHEN it's run as a Window/Xbox app, specifically the Overscan ability for display on a TV. So far I've been unable to get the JS to detect the execution type. I've added

if (Windows)
{
    Windows.UI.ViewManagement.ApplicationView.getForCurrentView() ...
}

but when I run it in a regular ol browser I get a Reference error of Windows being undefined. I also tried

if(typeof Windows !== 'undefined'){....

which makes the browser version work fine, but deployment tests in Visual Studio don't see it either (I put a debug console output to make sure).

Is it possible to have a best of both worlds execution, or do I need to go full bore and develop a specific version of the game in VS to get what I want?

2 Answers2

1

Figured it out. The if(typeof) solution is partially correct, so points there Shawn. What I was failing to do is include WinRT Access to the URI in the appxmanifest inside of Visual Studio. Once I told it to actually look for Windows on the app side, I'm getting my debug output and the screen is scaling appropriately. Thanks for having a look see anyway!

0

I can think of two possible options. First check the type of the object:

if(typeof Windows != 'undefined')
{
}

Second, declare a variable Windows before your check(s). It's ok to redeclare a variable in javascript. It won't override the original.

var Windows;
if(Windows)
{
}
Shawn Kendrot
  • 12,425
  • 1
  • 25
  • 41
  • As I mentioned, I can do the typeof check and the browser continues on its merry way, but the UWP deployment ALSO passes over it instead of executing the code inside the statement. If I declare the var early on to placate the browser version, won't it still throw errors on the UI declarations inside the if statement? Cuz none of that is gonna exist, even if the Windows var does. – Christopher K May 18 '17 at 23:20
  • A variable that is declared but not assigned value is `undefined` but works fine for the if statement – Shawn Kendrot May 19 '17 at 03:23