SDK2 How to access mouse/pointer position from a behavior when Worker mode is enabled?

Not favoritedFavorited Favorited 0 favourites
  • 5 posts
From the Asset Store
Vector illustration of a UFO with an alien in three different positions.
  • I'm developing a custom SDK2 behavior that needs to read mouse/pointer position at runtime. This works fine with document/window listeners when 'Use worker' is disabled, but obviously fails when Worker mode is enabled since Workers have no DOM access. Is there an officially supported SDK2 mechanism to run a small script on the main/DOM thread and pass data (like pointer coordinates) to the worker-side runtime script? I know native plugins like Mouse/Touch somehow get this data even in Worker mode — is that mechanism exposed to third-party addons?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Most input events like keyboard, mouse and pointer input are fired on IRuntime so you don't need to forward them yourself. For example you can write runtime.addEventListener("pointerdown", e => OnPointerDown(e)), just like you would with document or window in the DOM.

  • Most input events like keyboard, mouse and pointer input are fired on IRuntime so you don't need to forward them yourself. For example you can write runtime.addEventListener("pointerdown", e => OnPointerDown(e)), just like you would with document or window in the DOM.

    Thanks, that worked for detecting events! One follow-up: is there also an official way to convert the event's client coordinates into game viewport/canvas-space pixels while in Worker mode (without DOM access to the canvas element)? I need this for accurate pointer-to-world raycasting. Native plugins like Mouse expose LayerX/LayerY correctly even in Worker mode — is that conversion exposed on IRuntime or ILayer for third-party addons?

    Specifically, I'm seeing correct behavior only in fullscreen mode; in windowed mode with letterboxing, there seems to be an offset I can't account for without the canvas element's bounding rect.

  • Yes - have a browse through the reference in the documentation and you'll find the ILayer method cssPxToLayer() as well as lots of other useful things.

  • Yes - have a browse through the reference in the documentation and you'll find the ILayer method cssPxToLayer() as well as lots of other useful things.

    Its well explained documents, thank you

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