[Potential bug] WebView2 export don't run JS code regarding the window

0 favourites
From the Asset Store
Run Vovan Run
$1.60 USD
60% off
Full game Construct 2 and Construct 3 to post on Google Play
  • Potential bug, I use JS to scale the game window. It works fine in NWjs and the preview, but exporting to WebView2 (which is much leaner than NWjs) seems to nullify the code that changes the window. This is both resizeTo() and moveTo().

    Code in question here:

    I've tried window.resizeTo, replacing the variables to hardcoded and removing any flags etc values but nothing works.

    Also tried a blank project to see but no luck there either.

    It doesn't seem to be all JS, because a simple one like alert() works.

  • I think WebView2 doesn't currently support these window positioning methods out of the box. I filed an issue about it a while back.

    Can I ask why you need this though? It seems a weird thing to do. If you're trying to set a specific window size, it should default to the viewport size of your project.

  • I think WebView2 doesn't currently support these window positioning methods out of the box. I filed an issue about it a while back.

    Can I ask why you need this though? It seems a weird thing to do. If you're trying to set a specific window size, it should default to the viewport size of your project.

    Thanks for taking a look Ashley, appreciated.

    I dont think it's weird at all, window scale is a very normal option to have for desktop games (i dont do web games). Especially if you do pixelart, your game is made in a much lower resolution and then scaled up. Letting the player then select the window scale in options (or go fullscreen) is seen as hygiene factor for many. Celeste is a good example of this.

    I use this JS method because Construct does not provide a native way to scale the window. Would love if that would change moving forward but until then this is the best way to do it from what I've gathered.

  • To add on (can't see an edit button?), I realize now in the screenshot in the OP post I do not multiple the scale which is the idea. E.g. player would select scale factor 1, 2, 3, 4 etc and it would resize the window based on that. Alas, issue is the same :)

  • Worst case if Scirra or webview2 don’t get around to adding that then someone could use the c++ sdk to do it. It’s only a few winapi calls: one to get the window handle and one to set the size or position. I think someone already used that sdk on discord so maybe they could help.

  • Hmm, I wonder if there could be equivalent plugin to NWJS but for webview to do some fundamentals such as window positioning and sizing. But at least there's 2 chances of that happening with either Scirra or the community creating this!

  • E.g. player would select scale factor 1, 2, 3, 4 etc and it would resize the window based on that.

    Why not use letterbox integer scale? That essentially does that and supports any window size. So then you shouldn't have to be trying to change the window size.

  • > E.g. player would select scale factor 1, 2, 3, 4 etc and it would resize the window based on that.

    Why not use letterbox integer scale? That essentially does that and supports any window size. So then you shouldn't have to be trying to change the window size.

    The key aspect is that the player should be able to select this in an option screen instead of having to manually adjust the window size by dragging the corners, which doesn't give a professional impression. Especially for selling games on Steam where it's common to get negative reviews for missing these type of settings.

    Attached two screenshots from Celeste and my own previous game for reference (Velocity Noodle).

  • > > E.g. player would select scale factor 1, 2, 3, 4 etc and it would resize the window based on that.

    >

    > Why not use letterbox integer scale? That essentially does that and supports any window size. So then you shouldn't have to be trying to change the window size.

    The key aspect is that the player should be able to select this in an option screen instead of having to manually adjust the window size by dragging the corners, which doesn't give a professional impression. Especially for selling games on Steam where it's common to get negative reviews for missing these type of settings.

    Attached two screenshots from Celeste and my own previous game for reference (Velocity Noodle).

    Heh... To have Vsync in options for a C3 project... One can dream.

    But yes, I agree with this, better to have scaling option rather than manually adjusting the window size, particularly for pixel games. Could argue that "just set to fullscreen " but sometimes players might have a monitor resolution that shows black bars with integer scaling - so a cleaner windowed mode that's perfectly sized is more appealing.

  • I didn't know players wanted those settings - I'd have thought a fullscreen experience was more immersive than windowed 🤷

    I polyfilled window.moveTo() and window.resizeTo() for WebView2 as it didn't look too hard (although DPI settings can prove complicated, but I tried to get it right), so that's in for the next beta - hopefully it works OK.

  • I didn't know players wanted those settings - I'd have thought a fullscreen experience was more immersive than windowed 🤷

    I polyfilled window.moveTo() and window.resizeTo() for WebView2 as it didn't look too hard (although DPI settings can prove complicated, but I tried to get it right), so that's in for the next beta - hopefully it works OK.

    Big big thank you :)! I will try it when the beta comes out and feedback if needed.

    It might be more relevant for us small resolution devs but fantastic that we can use the lightweight webview2 while keeping these type of settings. Looking forward to seeing where c3 takes WebView in general.

    Have a great weekend!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Awesome, thanks Ashley!

  • I noticed this issue too when I exported my game in Webveiw2.

    Looking forward to the next beta!

  • I didn't know players wanted those settings - I'd have thought a fullscreen experience was more immersive than windowed 🤷

    I polyfilled window.moveTo() and window.resizeTo() for WebView2 as it didn't look too hard (although DPI settings can prove complicated, but I tried to get it right), so that's in for the next beta - hopefully it works OK.

    Thank you Ashley, resize seems to work correctly now.

    window.moveTo on the other hand is quirky. It's moving the window but not placing it correctly. I use this code to place it in the center of the screen

    	window.moveTo((runtime.globalVars.screenWidth-window.outerWidth/2), (runtime.globalVars.screenHeight-window.outerHeight/2));
    

    It's not centering the window, instead placing the top left corner of the window in the center instead (almost as if I wouldnt have the subtraction part). Perhaps this is the DPI issue you mentioned?

  • I tested it moving it to (100, 100) and it worked the same as the browser. Maybe it's an issue with your calculation. It's hard to help unless you file an issue following all the guidelines, as it's usually impossible to help without that information.

Jump to:
Active Users
There are 2 visitors browsing this topic (0 users and 2 guests)