How do I increase a number with 1 formula?

0 favourites
  • 3 posts
From the Asset Store
Make a displayed number gradually increase or decrease, making an impression of a real-time counting.
  • For example: a sprite moves from left to right.

    every tick:
    sprite: set x to: self.x+50[/code:17eomtem]
    
    But i want the movement slightly going faster.
    So I added global var [i]num[/i]
    
    [code:17eomtem]Every 1 second: 
    system: add 1 to num[/code:17eomtem]
    
    And changed the code from above to: (added "*num")
    [code:17eomtem]every tick:
    sprite: set x to: self.x+50*num[/code:17eomtem]
    
    How do I do this without adding an extra global variable?
  • There are two main ways:

    A) If the movement coordinates (Start and End) are always the same:

    Set X to: Self.X + 50 + 100*[(Self.X-Start.X) / (Target.X-Start.X)][/code:34ho81xw]
    (replace 100 by the number that should be added extra when the Sprite almost reached the target)
    
    [i][(Self.X-Start.X) / (Target.X-Start.X)][/i] calculates the movement progress of the Sprite (0 at the beginning, 1 at the end) and multiplies it with [i]100[/i].
    That way, the extra value gets higher, the more the Sprite has moved.
    
    Again, this only works [i]if the Start and End values are known and set each time[/i].
    
    B) Use a plugin, for example [url=https://www.scirra.com/forum/behavior-litetween_t70700]LiteTween[/url].
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you!

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