Pan and Zoom with Touch.

0 favourites
  • 4 posts
From the Asset Store
Surena Touch
$2.50 USD
A wrap from official Touch plugin to export touch/mouse input to other plugins.
  • I know this is a common topic and C2 also has a tutorial built in for this.

    This one is a bit different.

    I used the C2 tutorial to get my touch zoom and pan to work correctly, and it does.

    I added a UI Button that when pressed will Zoom and Pan to a specific point.

    It uses an invisible object, ScrollTo behavior, and litetween.

    The tutorial and the UI Button have their own variables.

    The only thing they have in common is LayoutScale, ScrollX and ScrollY.

    The UI Button logic is below the Touch Pan/Zoom in the event sheet.

    If player touches screen while game is auto zooming/panning it gets ignored.

    This is because ScrollX, ScrollY and LayoutScale gets overwritten each tick when ran.

    During runtime, sometimes out of nowhere LayoutScale, ScrollX and ScrollY both get set to NAN and screen goes black.

    It doesn't happen often and I can't detect a pattern to it.

    I can't even reproduce it.

    I believe this is the issue.

    The Tutorial uses a Layer with Scale rate 0 and Parallax of 0,0.

    The Invisible object is on a layer that has Scale rate of 100 and Parallax of 100,100.

    I figure the math of the original tutorial is messing up because of this.

    I am very sure it has to do with ScrollX and ScrollY and not to do with LayoutScale.

    I did think maybe the litetween was interfering somehow...

    I am only hoping for the built in C2 Example Tutorial with a few added events, but if someone has something more simple I would appreciate it.

    I did study it to a point, but I only understand about 98% of the Example Tutorial.

    I mostly just copied it and pasted it into my own project and changed the variable names a small bit.

    I am curious if someone could share a capx with Touch Pan/Zoom with the ability to Pan/Zoom to a specific point when the game calls for it.

    Maybe use the

    "Example: Touch - zooming" capx

    and add a feature to zoom and Pan to any given spot on button touch.

    I would ask for an explanation on how to fix it, but I lack the ability to test zoom touch when developing...

    Thanks in advance.

  • It would really help if you share your capx file.

    "NaN" could happen if at some point you are dividing by 0 (which is not allowed)

    I have a zoom demo, but it's not quite what you want, as it zooms to screen center, but maybe you could modify it:

    (test in Chrome)

  • I don't have much of a capx.

    I took the built in Touch zoom/pan example and placed it in another capx..

    The few events I added made a logic bug.

    It would have been easier for all involved to just make a new with the C2 Touch Zoom example.

    I can promise it isn't dividing by or multiplying by 0, unless it is random from input feedback.

    The variables are all integer, unless litetween is affecting it some how.

    The Built in Touch zoom/pan example in C2 only zooms into the screen center.

    The fact that it has pan makes it seem like it doesn't.

    With combination of Pan and Zoom, it will look like it isn't zooming to middle of screen.

    Your capx. is mostly the answer, It is very simple.

    I actually understood it instantly.

    I was having trouble with understanding zoom in C2 Zoom tutorial.

    Because of your capx, I don't have to use 0 scale rate and parallax 0,0.

    I believe that it was what was causing my problem, and that it was only needed for zoom.

    I once had pan working great on 100 scale rate and parallax of 100,100.

    I just need to redo pan now, I will have to do that later today.

    I always try to mimic modular programming with the events.

    Thanks for the file.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I believe I fixed the original setup I had.

    I was calling a function to Zoom and Pan to a specific spot.

    It was interrupting TouchPanID and TouchZoomID getting set back to defaults when not in touch.

    I found if I manually set TouchPanID or TouchZoomID to 0 instead of default -1 it had the same results.

    Now thinking of it ScrollX and ScrollY wouldn't have mattered regardless of parallax and scale rate.

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