Set Object to Mouse Position - when layer is scaled

0 favourites
  • 3 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • Got an interesting one today folks.

    So to set an objects location to the mouse position, obviously you do it using "setPosition - Mouse.X, Mouse.Y".

    This works fine.

    Now, when the layer that the object is on is scaled, this doesn't work. it offsets the object from the mouse position, thus ruining the movement.

    In the image - The actual Mouse Position is shown as the Red Dot.

    s22.postimg.cc/fztoo2yox/Mouse_pos.jpg

    Any solutions or clever math to fix this?

    Cheers,

    Matt

  • Assuming that layer 0 is not scaled, and layer 1 is scaled, Sprite is on layer 1:

    On every tick -> Sprite set position to

    X: CanvasToLayerX(1, LayerToCanvasX(0, Mouse.X, Mouse.Y), LayerToCanvasY(0, Mouse.X, Mouse.Y))

    Y: CanvasToLayerY(1, LayerToCanvasX(0, Mouse.X, Mouse.Y), LayerToCanvasY(0, Mouse.X, Mouse.Y))

    .

    EDIT 12 days later:

    AM_Games , scrap that! I just remembered that you can easily get mouse coordinates for any layer.

    Simply set position to Mouse.X("layername"), Mouse.Y("layername")

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • dop2000

    That's absolutely genuis! Much appreciated pal, never even occurred to me to do it this way.

    Tested and working fine so you've gone and saved me a huge headache.

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