Latest Thunkable for Android releases (Pinch to scale on Canvas)

gesture
canvas

#1

Hey Thunkers,

Hope you are having a happy Friday. To get you started for the weekend, we have added the ability to scale up or down objects on a Canvas by pinching, one of the most intuitive gestures on a smartphone. We think this should enable even more interesting and powerful gaming and drawing apps.

https://docs.thunkable.com/assets/pinch-to-scale-fig-1.png

Release notes are below and make sure to download the latest Thunkable companion app
Thunkable Release Notes

Next up for us on Android are Push Notifications and a native Floating Action Button -

Happy Thunking!
Albert on behalf of the team


Thunkable live 3.20 crashing
#2

Great work! Thank you very much!


#3

:+1:


#4

great work @albert


#5

I am sure, this is added by @TingC


#6

Is this based on Hal Abelson’s ScaleDetector extension?


#7

I think so.


#8

Yes correct.


#9

When using scale_factor to adjust the width and height of a non-square sprite, I’m finding that the sprite’s aspect ratio is getting slightly distorted each time it’s scaled down smaller than a certain size, until the smaller dimension approaches zero and the sprite disappears. I’m assuming this is a quirk of the whole-number nature of both pixel dimensions, meaning that when each dimension is multiplied by the five-decimal-place scale factor and then rounded to a whole pixel, the two dimensions gradually become out of sync with one another.

It might be helpful if we could set a locked aspect ratio for a sprite. But in the meantime, I have found that I can more or less work around this by allowing a sprite to scale down only if both dimensions are greater than a minimum pixel count (and again, I haven’t worked out the ideal minimum, but 100+ seems to be working for me right now).

Posting here because I would’ve been happy to find this info an hour ago. :rofl: Please advise if this is not an appropriate use of this forum topic—I’m new to Thunkable.


#10

When resizing proportionally, you can use this formula:

Only use the pinch to resize the width and calculate the height like this

sprite.height = ( original height / original width ) x new width


#11

Indeed I did, but the issue persists.

ETA: I’m finding that even when I do set a bottom limit for the dimensions, the sprite will still distort if I pinch it big-medium-big-medium, so this is not at all a foolproof workaround. It does seem to slow the distortion process down a bit, though.


#12

You are doing something wrong, because using that formula I have perfect proportional resizing. Can you post the blocks where you resize your sprite?


#13

This is the separate app where I have been searching for a workaround (so as to rule out any other part of my app interfering). It only does this, and over the course of many resizings, the image gradually and consistently distorts. The nearer it is to square, the more times it takes.


#14

@notkristina: You need to calculate the aspect ratio for the sprite in the beginning of your app, to make sure that value is not changed later in the app, like you are doing inside your Canvas.Scaled event.
Did you notice the red circle with a cross in your global oldWidth definition? That’s an error. It means you can’t assign that value in a definition. So that variable is empty at start.
Also I added the blocks you need to keep the sprite between 100 and 300 pixels wide, you change it to whatever you need there.


#15

I am such a fool. I misread your equation the first time and went on thinking I knew what I was doing. Of course this will work. Thank you so much for your time and patience. Your solution will help lots of people, but first, me! :laughing:

I did not notice that red X, thank you for bringing it up. It didn’t especially matter what that variable was initialized to in this instance, but I wonder why that’s not an acceptable value.


#17

@Italo
i used these blocks but whenever i pinch to zoom the sprite becomes invisible


#18

Show your blocks.


#19

This is NOT a support or discussion topic… Please create a new topic in the right category(e.g. Android Discussions) if you have problems :wink:


#20

@Italo


#21

It looks like it should work. How big the image assigned to your sprite is?