[FIX] True Mouse.X/Mouse.Y for Layout Scale

0 favourites
  • 5 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • Hi,

    I had a problem with the way Construct 2 handles Mouse.X/Mouse.Y layout coordinates when scaling the layout. After some time I finally figured out a solution to this problem.

    To convert the correct mouse position from the incorrect mouse position on a layoutscale that is not 100% you have to..

    [System | Every Tick]

    True Mouse.X = (Mouse.AbsoluteX-WindowWidth/2)/LayoutScale+Scrollx

    True Mouse.Y = (Mouse.AbsoluteY-WindowHeight/2)/LayoutScale+Scrolly

    I also have a HTML5 link and a *.capx file showing this.

    HTML 5

    *.CAPX

    The Blue Circle is Construct 2's Mouse.X/Mouse.Y position..

    The Green Circle is the True Mouse.X/Mouse.Y position.

    I hope this helps :)

  • I think you're just missing the layer versions of the mouse X/Y expressions. From Mouse in the manual:

    b]X("layer")

    Y("layer")

    Return the position of the mouse cursor in game co-ordinates, with scrolling, scaling and rotation taken in to account for the given layer. The layer can be identified either by a string of its name or its zero-based index (e.g. Mouse.X(0)).

  • They don't work when scaling a layout not the layer. Try it out yourself. :)

    This is a solution for getting the correct Mouse.X/Mouse.Y positions when scaling the layout not the layers.

    Could you please include this in your next version as an expression such as..

    TrueMouse.X

    TrueMouse.Y

    or even just replace your current ones with this.

    BTW this should also solve your problems with layer scaling so you will have no need for a separate layer for the mouse.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • michelangelo, the mouse layer expressions do also take in to account the layout scale (which implicitly alters all layer scales). I tried modifying your example to use the mouse layer expressions and it worked OK, have you tried it?

  • thank you for this. it's beautiful!!!

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