Pinch to zoom

Get help using Construct 2

Post » Mon Dec 10, 2012 3:55 pm

ok so ive been looking around the forums but havent found an elegant solution to pinch to zoom without plugins.

sort of what i want to do:

create object at touchpoint 1
create object at touchpoint 2
measure distance between object 1 and 2
this distance is "X"
if distance becomes greater than X (objects moving away) then zoom in
if distance becomes less X (objects moving closer) then zoom out

zoom speed could be whatever, just not snapping.

would this work and could someone help please =)
B
7
Posts: 25
Reputation: 965

Post » Mon Dec 10, 2012 5:42 pm

Hello openfocus.

This is purely speculative, as I haven't messed with pinch-style controls yet, but I imagine you could save the point touched on the screen to a variable and measure the difference in a 'system tick' event.

It doesn't look like there's a way to measure two touch events at the same time, though. If only one can be tracked, it might be tricky; with X increasing right and Y increasing down, you might be able to measure just the X/Y position to determine if it's a pinch or spread motion.

I'll be curious if you get a demo of this working!
B
16
S
6
G
2
Posts: 152
Reputation: 3,764

Post » Mon Dec 10, 2012 6:07 pm

[QUOTE=Space Ape] Hello openfocus.

This is purely speculative, as I haven't messed with pinch-style controls yet, but I imagine you could save the point touched on the screen to a variable and measure the difference in a 'system tick' event.

It doesn't look like there's a way to measure two touch events at the same time, though. If only one can be tracked, it might be tricky; with X increasing right and Y increasing down, you might be able to measure just the X/Y position to determine if it's a pinch or spread motion.

I'll be curious if you get a demo of this working![/QUOTE]

yeah, thats exactly what im trying to do =) but i just cant figure out the variables and the events..
B
7
Posts: 25
Reputation: 965

Post » Mon Dec 10, 2012 6:10 pm

C2 does support multitouch...
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,674

Post » Mon Dec 10, 2012 7:26 pm

Touch(index)
distance(touch(0).x, touch(0).y, touch(1).x, touch(1).y)

I think this it... though you might want to use touch.XAt or touch.AbsoluteX

jayderyu2012-12-10 19:28:17
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,013

Post » Mon Dec 10, 2012 7:34 pm

Here is a working example with zooming and scrolling:
http://dl.dropbox.com/u/5426011/examples16/pinchzoom.capx

I used two layers and only scale layer 1. layer 0 I used to get the touch positions used for zooming. If I scaled the layout instead zooming became very unstable.
B
91
S
31
G
99
Posts: 5,199
Reputation: 65,684

Post » Mon Dec 10, 2012 7:59 pm

hound, that is impressive dude. I gotta keep that one on file! Thanks.
B
16
S
6
G
2
Posts: 152
Reputation: 3,764

Post » Thu Dec 13, 2012 8:42 pm

[QUOTE=R0J0hound] Here is a working example with zooming and scrolling:
http://dl.dropbox.com/u/5426011/examples16/pinchzoom.capx

I used two layers and only scale layer 1. layer 0 I used to get the touch positions used for zooming. If I scaled the layout instead zooming became very unstable.[/QUOTE]

thanks rojo, exactly what i was looking for! =D

btw, is there anyway to set max zoom, so that you cant zoom outside layout or super close?openfocus2012-12-13 21:15:35
B
7
Posts: 25
Reputation: 965

Post » Tue Apr 09, 2013 1:46 pm

hey @R0J0hound I have some strange results with your example and I'm not sure whats causing that.
Sometimes (very often usually) after zooming using two touch points it constantly keep track of one point - I've added simple text to show touch counts.
So if You then try to zoom again with two touch points it's messing up cause there are three touches now. Even if you stop touching it still shows one touch active and there is no way to reset it (only reloading page works)
I've been testing this on three different Android phones.

any ideas? or maybe it's a bug in touch plugin (using r124 currently)
ImageImageImageImage
B
156
S
64
G
41
Posts: 2,589
Reputation: 34,613

Post » Tue Apr 09, 2013 3:49 pm

Thanks @R0J0hound for that example !
But it doesn't really works for me neither.
I wanted to be able to scroll and zoom on a big map. Scroll should be constrained to the boundaries of the layout and zoom should have a min and a max intensity.
Any idea about how to do that ?
B
32
S
14
G
5
Posts: 232
Reputation: 5,502

Next

Return to How do I....?

Who is online

Users browsing this forum: Unconnected, Yahoo [Bot] and 10 guests