Possible to pinch-zoom canvas?

Get help using Construct 2

Post » Tue Feb 16, 2016 5:23 am

Is it possible to use two fingers to pinch and zoom within Construct 2? Or do I need an additional plugin?

Spreading apart two fingers: Zoom in
Spreading in two fingers: Zoom out
Check out my games on Google Play:
BEAST ATTACK (1,000,000+ downloads!)
ZOMBIE BASH (Android) (Launched Feb 17)
ZOMBIE BASH (iOS) (Launched March 17)
B
54
S
18
G
2
Posts: 436
Reputation: 5,582

Post » Tue Feb 16, 2016 6:20 am

https://www.scirra.com/manual/119/touch

You can use the Nth touch and TouchID expression to get the X and Y locations of your first and second touches. You can then store those positions in variables to use as comparison to see if your new touch position is bigger or smaller and by how much and scale accordingly with LayoutScale.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Tue Feb 16, 2016 11:51 am

There's a Pan/Zoom example shipped with C2..
Just type zoom in the searchbox when selecting new project..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sun Aug 21, 2016 7:42 pm

@LittleStain Is there a way to stop the zoom in and out at a certain point? Like the layout will have the zooming effect within a limited scope.

In the example provided, the layout is zooming out beyond the background image and zooming in unlimited. When I zoom out I can see the background image getting smaller making the white screen visible. I don't want that to happen. Zoom out should not happen beyond the layout (background image) and zoom in should not happen more than half of the layout.

Is there a way? Please help. Thanks.
B
24
S
7
Posts: 335
Reputation: 2,220

Post » Mon Aug 22, 2016 1:44 am

Use the min() and max() expressions to constrain your scale factor.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Mon Aug 22, 2016 8:24 pm

@oosyrag Hello buddy, could you please explain it in more detail?
B
24
S
7
Posts: 335
Reputation: 2,220

Post » Mon Aug 22, 2016 8:46 pm

Actually clamp() would be more suitable, to set a min and a max.

In the previously mentioned example capx, the zoom amount is set with the action

Set Layout Scale to InitialScale * (TouchCurrentDistance / TouchStartDistance)

You would instead set it to clamp(InitialScale * (TouchCurrentDistance / TouchStartDistance),minscalefactor,maxscalefactor)

Where min and max scalefactor would be the limits of how much you want to zoom.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Mon Aug 22, 2016 9:00 pm

@oosyrag
I have taken the values for min as 1 and max scalefactor to 2, zoom in is happening for a certain limit but after that zoom out is happening in reverse that is when I move both the fingers closer zoom in, instead of zoom out, is happening. What should I do now?
B
24
S
7
Posts: 335
Reputation: 2,220

Post » Mon Aug 22, 2016 10:33 pm

I'm not sure without looking at it, but you might have gotten your numbers reversed. Remember a scale factor less than 1 would be zooming "out" and a number greater than 1 would be zooming "in".
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Tue Aug 23, 2016 7:42 am

@oosyrag It is greatly working by reversing the numbers but I got a new problem. The zooming effect isn't going smooth. When I zoom out the layout going to the defined scale factor directly and same thing is happening with the zoom in.

I just replaced "InitialScale * (TouchCurrentDistance / TouchStartDistance)" to "clamp(InitialScale * (TouchCurrentDistance / TouchStartDistance),minscalefactor,maxscalefactor)" and nothing else.

Please help.
B
24
S
7
Posts: 335
Reputation: 2,220

Next

Return to How do I....?

Who is online

Users browsing this forum: namaewayukidesu, ultrafop, zenox98 and 13 guests