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.
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. Please advise if this is not an appropriate use of this forum topic—I’m new to Thunkable.
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.
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.
@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.
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!
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.