# sprite scale

Get help using Construct 2

### » Wed Jul 03, 2013 3:03 pm

Some help needed on my formula for scaling the sprite.
What im looking for is to set formula that will linear scale down my sprite from full size to null size while he travels from spawn to target.

So far iw managed to set scale correct but when i apply global timescale change my scaling breaks down... :(

any tips?
B
34
S
15
G
3
Posts: 820
Reputation: 6,491

### » Wed Jul 03, 2013 3:13 pm

scale = initial scale * distance(sprite,target)/distance(spawn,target) ?
If you are going for a linear scale based on the position, you should do it base only on distances, so completely independent from the timeline. Or maybe I misunderstood you ^^
Put this in an event triggered every tick if the sprite "is moving", and you should be good
B
17
S
9
G
4
Posts: 473
Reputation: 6,311

### » Thu Jul 04, 2013 10:03 am

it works but the end result is not as good as i expected it to be... :(

Is there a way to make scaling less at the begining and more towards the end?
..so that calculation is not strictly linear but rather kinda curvy, archy if you know what i mean.

thanks!irina2013-07-04 10:17:50
B
34
S
15
G
3
Posts: 820
Reputation: 6,491

### » Thu Jul 04, 2013 10:19 am

@irina

That is possible using lerp. In the frequently asked questions thread's opening post there are links to some topics with explenation about lerp.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Thu Jul 04, 2013 10:23 am

Of course, just tweak the function ^^
distance(sprite,target)/distance(spawn,target) (let's call this P) is going from 1 to 0, representing the proportion of the distance still to travel. If you do pow(P,X) (where X is between 0 and 1, strictly) you will get a curvy function, not linear anymore, still going from 1 to 0 (0 power X = 0 and 1 power X = 1, when X>0 so we are ok).

Examples :
For X=0.5
scale at origin is 100%
scale at 30% of the travel is 84%
scale at 50% is 71%
scale at 70% is 54%
Scale at 90% is 30%
scale at destination is 0%

For X=0.8
scale at origin is 100%
scale at 30% of the travel is 75%
scale at 50% is 57%
scale at 70% is 38%
Scale at 90% is 16%
scale at destination is 0%

When X approaches 1, you will get a more linear function.
When X approaches 0, you will get a more curvy function.

You just have to try now :)

EDIT : lerp would help also, it's true, but it won't work if the sprite can go both ways, or if you want to have always the same scale at the same position, because lerp will be time-dependent, "smoothing" the changes in the scale. Because of this, the scale would adjust depending on the sprite movement/speed over time, not just its position between origin and destinationGuizmus2013-07-04 10:27:17
B
17
S
9
G
4
Posts: 473
Reputation: 6,311

### » Thu Jul 04, 2013 12:34 pm

@Guizmus

fantastic!!! thats it!

Thank you!!!
B
34
S
15
G
3
Posts: 820
Reputation: 6,491

### » Thu Jul 04, 2013 12:38 pm

@irina Maths are your friend ;)
B
17
S
9
G
4
Posts: 473
Reputation: 6,311

### » Thu Jul 04, 2013 8:49 pm

I think im encountering a strange issue here.
I mean everything is working ok except animations (explosions, to be precise).

What i mean, they are scaled ok but since animations last some time... They dont continue to scale during playing of particular animation it self...
They are only scaled based on point of creation and that's it.
Even thou they continue their moving, they dont scale but playout entire animation on the same size or scale of it.

Is this qualifies as a bug or am i doing something wrong?
B
34
S
15
G
3
Posts: 820
Reputation: 6,491

### » Thu Jul 04, 2013 10:51 pm

Not sure, that's strange... Could we take a look at the capx to help ? ^^
B
17
S
9
G
4
Posts: 473
Reputation: 6,311

### » Fri Jul 05, 2013 9:02 am

I dont want to bother you too much.
Fact that you said it's strange was enough to make me to dig deeper and i'w managed to set it right.

Thank you!
B
34
S
15
G
3
Posts: 820
Reputation: 6,491

Next