How do I add to cursor X based on viewport

  • I have searched around, and for a few days, tried implementing viewports, layer identifiers with mouse coordinates, etc but I noticed something interesting.

    My actions:

    I created a scrollable side scroller game layer

    I created a UI layer

    I set a custom cursor to my mouse specific to the UI layer (i.e. Mouse.X("UI"), etc)

    What I found:

    The cursor follows mouse flawlessly, even with game layer scrolls, and all parallax etc does the same (because its bound to UI layer)

    BUT..having bound to UI, if I leave the mouse/cursor at any position in the game viewport, and then move player, say to the right for example,

    The X and Y coordinates of the cursor do not change, even though the cursor moves with the UI layer.

    Makes sense, but not sure how to manipulate the X Y values based on game layer while bound to UI.

    This is to check if cursor.X is > or < a specific game layer object. I do not know, and have not found yet, how to take the cursor X and offset/add the difference of the left side of the game layer/viewportLeft X coordinate from layout coordinate of beginning at 0 with the viewport.

    Does that make sense?

    So moving the viewport will obviously side scroll, and of course layout X Y is not supposed to change, so how can I calculate the different between the viewport Left X and the layout 0 OR even UI X since its left is always 0 also?

    I could then take cursors Mouse.X("UI") and add the difference so cursor.X is always updated even if viewport moves, so its ALWAYS relative to the actual position in the view. The visuals work fine, but the numbers dont change.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If I understood correctly, the solution should be to compare Mouse.X to Object.X (instead of Mouse.AbsoluteX). If not, can you share a picture of your layout? My mental image of what you're trying to do is a bit fuzzy.

    And when you say "I set a custom cursor to my mouse specific to the UI layer (i.e. Mouse.X("UI"), etc)", are you referring to using Set cursor from sprite?

    EDIT: I should also clarify that if you do Mouse/Object.X(layer number or "layer name"), you'll get the coordinates at that layer.

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