Zoom in error in a custom level editor

Get help using Construct 2

Post » Sun Nov 24, 2013 1:46 pm

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:
http://www.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..

CAPXchristina2013-11-24 13:51:22
B
28
S
12
G
4
Posts: 193
Reputation: 4,581

Post » Mon Nov 25, 2013 9:54 am

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?
B
28
S
12
G
4
Posts: 193
Reputation: 4,581

Post » Mon Nov 25, 2013 11:10 am

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. keepee2013-11-25 11:11:20
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Mon Nov 25, 2013 3:13 pm

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
B
28
S
12
G
4
Posts: 193
Reputation: 4,581


Return to How do I....?

Who is online

Users browsing this forum: dop2000, evillair, mongoose665, StillSarah and 64 guests