How do I use touch input for scaling

0 favourites
From the Asset Store
Surena Touch
$2.50 USD
A wrap from official Touch plugin to export touch/mouse input to other plugins.
  • I'm experiencing an issue with the zooming behavior of a sprite called "SpaceShip." I've implemented a resize button that enables the player to zoom in and out the "SpaceShip" based on touch input.

    The code does exactly this, but the problem is that the initial touch on the SpaceShip always triggers the object to scale to 2 times its size before allowing further resizing. If we move it/scale in around a bit, a weird effect also coming. This behavior is undesirable, and I want the object to start resizing immediately without the initial jump to double scale.

    Please help me fix the code. I'm a developer myself and still in the process of learning Construct 3 by reading other questions and answers. I've come this far, but this time I'm stuck trying to figure out how to use touch input for scaling. So, I asked for help before and received an amazing piece of code (Thanks to that user for providing the code).

    drive.google.com/drive/folders/1GMGL7lDOz2LVptZfa0Mh20ekYWLpWvVB

    Tagged:

  • Check out this demo:

    howtoconstructdemos.com/zoom-a-sprite-or-entire-screen-with-pinch-touch-gesture

    There is also an official example:

    editor.construct.net

  • Thanks dop2000. We first went through the example you shared unfortunately that didnt helped in achieiving requirement. It would be really helpful if you please guide us or giving some hints how we can fix it

  • Your spaceship sprites are scaled down by default on the layout. So when you set their scale to 1, they naturally grow to their original size.

    Change the formula to something like this:

    Spaceship set scale to clamp(0.5+(Touch.X-ScaleX)*0.0090, 0.3, 1.5)

    I also suggest using hierarchies instead of Pin behavior.

  • Thanks dop2000 for the solution. However we tried the clamp expression, the scale option is getting reset, ealier the initial touch on the SpaceShip always triggers the object to scale to 2 times its size before allowing further resizing, but now one time.

    Please find the attached c3p.

    drive.google.com/file/d/1mC0rnjHZjmcjlfdVgqVZLSeWolmRe4Mp/view

  • but now one time.

    I don't understand what you mean.

  • I have attached a small video. Basically, the issue arises when we click the resize button while the sprite is in a zoomed state.

    Also, please guide us on the clamp logic: how precisely we can restrict the maximum and minimum zoom levels.

  • You probably need to store current scale value in an instance variable on the sprite. And use that variable instead of the fixed "0.5" number.

    Ship set scale to clamp(Ship.curScale+(Touch.X-ScaleX)*0.0090, 0.3, 1.5)

    When resizing is finished, save the new scale value to curScale variable.

    0.3 and 1.5 are the minimum and maximum values for the clamp() expression. See the official manual:

    construct.net/en/make-games/manuals/construct-3/system-reference/system-expressions

  • We tried the suggestion shared by you.

    The same issue arises when we click the resize button, now the zoomed state is max clamp limit. Please find the new attached video and c3p.

    (I hope the response will be published right away unlike last time which took 3 days)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'm so sorry for the delay! lol

    dropbox.com/scl/fi/us9zxk9sim0bpg1x8wi0j/Q1-R3_dop2000.c3p

  • Thanks a lot Dop2000. Really appreciate your help !!

  • Hi, dop2000

    I'm struggling to make that logic work with the text object, could you please help. How to make that resize logic works same with text?

    Here the attached c3p.

  • I suggest creating a hierarchy with a sprite being parent object, and the text being child object. Then when the parent sprite is resized, the text will be resized as well.

  • Then when the parent sprite is resized, the text will be resized as well.

    Thanks Dop for your suggestion. I created it based on your advice

    However, my question is, the above method you proposed works, but it would be simpler if it could be achieved directly using the text without the need for an additional sprite.

    So for that I believe I'm almost there; just a few expert modifications are needed to make it work.

    Please check this c3p.

  • Now I have updated the c3p. I'm almost there, please check.

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