sprite scale

0 favourites
  • 10 posts
From the Asset Store
Minimal Sprite Font with Stroke for Pixel Art games.
  • 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?

  • 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

  • thank you for your answer,

    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!

  • 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.

  • 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 destination

  • Guizmus

    fantastic!!! thats it!

    Thank you!!! <img src="smileys/smiley1.gif" border="0" align="middle" />

  • irina Maths are your friend ;)

  • 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?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Not sure, that's strange... Could we take a look at the capx to help ? ^^

  • 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!

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