Zoom in error in a custom level editor

  • Hi all: I'm making a simple level editor.

    While left mouse clicked = place tile

    Mouse wheel to zoom in/out

    The problem is, when I zoom in/out, the windows mouse cursor gets offset, and I don't understand how LayoutScale works.

    For example,

    at 100% layoutscale, I get ViewportRight =300 and layoutWidth = 300

    at 50% layoutscale I get viewportRight = 451 and (as expected) layoutWidth = 300

    Why 451px?

    @tulamide seems to have solved it once before here in madfactory

    's code:

    scirra.com/forum/zoom-problem-cap-added_topic42021_page2.html

    but the .cap isn't there so I can't check.

    Here's my CAPX, I'm sure I'm missing something simple..

    CAPX

  • It seems that with every layoutScale change, Construct assigns a different X,Y to what was formerly X=0 , Y = 0

    So there's an offset, but I can't connect the numbers.

    These are the experimental data I got from zooming out, and keeping the mouse cursor in the same X = 0

    layoutscale 1.0 viewport 320   offset =   0

    layoutscale 0.9 viewport 355.5 offset = -19.75

    layoutscale 0,8 viewport 400   offset = -50

    layoutscale 0.5 viewport 640   offset = -320

    layoutscale 0.4 viewport 800   offset = -600

    layoutscale 0.2 viewport 1600 offset = -3200

    And that's probably on top of scaling each tile.

    @tulamide any thoughts?

  • if you do mouse.x("layername"), it returns the right x on that layer, regardless of zoom.

    also the max() expression returns the highest number entered.. you can use it instead of the subevents regarding the edge boundary..

    max( mouse.x("layername"), 0) will return 0 if mouse.x is below zero

    There's also min() and clamp() which have similar uses.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • By the Gods, keepee

    You completely solved this for me <3

    And thank you for the math as well, this will make my code so much more readable.

    <3

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