How do I scale the image with out messing up the ratio?

0 favourites
  • 9 posts
  • Hi Everyone,

    I have some graphics that are pretty high detail and thus large. I have used the scale layout option set to .25 so that more of the map and graphics show in the game window.

    However, I have an icon that follows the mouse using this:



    But instead of following the mouse correctly, the objects moves in a much smaller ratio (i assume it is also scaling the mouse movements).

    So how can I either do the smaller graphics to show more game without using scale or fix the smaller ratio when following the mouse?

  • You can use Mouse.X(layer) and Mouse.Y(layer), where layer is the name or index of a layer with zero scale rate (like "HUD"). The icon should also be on that layer, or you can convert coordinates with LayerToCanvas and CanvasToLayer expressions, see this post.

  • So I tried both of those with different results...

    Doing the Mouse.X(layer) kept the object following the cursor BUT, I have the cursor snapping to a grid. And when my camera moved, it would still snap but not to the same grid anymore (like it was snapping to a grid on the GUI layer and not on the GAME layer). Is there a way to fix that?

    I also tried the CanvasToLayer (and a bit disappointed at how little the manual has on it), but this didn't net anything of use. The object did not move around much, similar to how much movement I was getting originally.

    Other thoughts or corrections to what I'm doing?


    Ok I played with it a bit more and got a lot closer:

    Set X: round(Mouse.X("Game")/Global_GridX)*Global_GridX

    Set Y: round(Mouse.Y("Game")/Global_GridY)*Global_GridY

    This mostly works, except it seems to not allow much distance from the original point in the object before moving to the next tile over.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It will be easier to help you if you could share your project file.

  • Ok here you go:

  • I don't really understand the problem. It looks fine to me.

    There is one thing I would fix - change event 20 from "DragDrop is enabled" to "DragDrop is dragging". Also, you have two instances of highlight sprite, one on Game layer and one on Background.

  • If you look at event 19, there are some disabled lines where i have been testing different things.

    The click and drag was just another try, but since it only works while dragging and not always following, it isn't ideal.

    So disable event 20 and enable 1 of the event 19s and you will see the issue.

    Also, I know I have extra instances but can't figure how to get rid of them.

  • You can do this:

    On every tick, set position to
    X: round((Mouse.X("Game")-128)/Global_GridX)*Global_GridX
    Y: round((Mouse.Y("Game")-128)/Global_GridY)*Global_GridY

    Simply unlock the Background layer and delete the extra instance of highlight sprite from it.

    Also, create an unused layout "Assets" and move there all instances of objects which you spawn in runtime. Keeping them off-screen on your main game layout may cause different issues in the future.

  • Ok that worked, I had the right idea just didn't put the -128 in the right place.

    Thanks again for your help.

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