Is there a way to access root element(DOM) with worker mode on?

0 favourites
  • 8 posts
From the Asset Store
Design for game, asset for game, game kit, UI design, completed design for game, mobile game, DEEPER ROOT
  • I am trying to set a css variable/custom property to root element(document.documentElement), but I guess it's not supported in worker mode.

    I need to a dynamic "--layout-scale" variable, and Construct already sets a similar purposed variable "--construct-scale", so I wondered if there any way for me to access this DOM element without getting errors in worker mode?

  • A fundamental limitation of the web platform is web workers can't access the DOM directly. In worker mode Construct runs in a web worker and so there is no direct access to the DOM - internally it works around that with lots of message passing.

    If you write JavaScript code in a project, worker mode "auto" defaults to DOM mode to avoid this problem. If you have set worker mode to "yes" to force running in a worker, but you need to access the DOM, set it back to "auto" or "no".

  • A fundamental limitation of the web platform is web workers can't access the DOM directly. In worker mode Construct runs in a web worker and so there is no direct access to the DOM - internally it works around that with lots of message passing.

    If you write JavaScript code in a project, worker mode "auto" defaults to DOM mode to avoid this problem. If you have set worker mode to "yes" to force running in a worker, but you need to access the DOM, set it back to "auto" or "no".

    So, no way to set this variable in worker mode.

    Have you guys maybe considered to adding this layout scale variable alongside construct scale yourself in some future updates?

  • Does the ILayer renderScale property do what you need?

  • Does the ILayer renderScale property do what you need?

    Not sure how, it's still a JS scope, right? But I need access to this values from CSS, so that some of my styles html elements could adapt to layout scale, the way they adapt to construct scale thanks to the global --construct-scale variable. This grid class from the screenshot, for example, needs both construct and layout scales to be sized properly.

    I could, of course, just assign new inline css styles through HTMLElement API everytime layout scale changes, but that would be much less convenient.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'm not sure what you're trying to achieve - in CSS you can use --construct-scale, and in JavaScript it seems you can use the ILayer property renderScale, which works in both DOM and Worker mode. Doesn't that cover all cases?

  • I'm not sure what you're trying to achieve - in CSS you can use --construct-scale, and in JavaScript it seems you can use the ILayer property renderScale, which works in both DOM and Worker mode. Doesn't that cover all cases?

    In my previous reply I showed in the screenshot that I need layout scale value in CSS, not in JS. I never had a problem accessing layout scale value in JS.

    Look at the 'background-size' property, where I use both --construct-scale and --layout-scale. First already exists, second currently does not(in CSS), unless you set it yourself by manipulating styles of root DOM element with some JS, which is not possible in worker mode.

  • I thought the render scale did already take in to account the layout scale? I'm still not sure what you're doing that requires the render scale and layout scale to be handled separately.

    If you really do need both modes though, I'd just say switch to DOM mode and add a CSS variable from JavaScript.

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