How do I increase a value while the other one decreases?

0 favourites
  • 3 posts
From the Asset Store
Footsteps SFX One contains 400 sounds of steps and jumps on different surfaces.
  • Hi there,

    I'm facing a little problem here...

    What I would like to accomplish is the following:

    I want some variable (let's name it 'A') to decrease while the x-position of a certain sprite increases.

    So say 'A' starts with a initial value of 100. As the sprite moves to the right, so as the x-position of the sprite gets higher, the value of 'A' is supposed to get lower until it reaches the value of 0 (zero) when the sprite 'hits' the right side of the screen.

    Any help would be appreciated.

    Thanks in advance!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • A = 100*(yourscreenswidth-yoursprite.x)/yourscreenwidth

    Since your hotspot probably isn't on the right side, you have to, for example, also add half of your sprite's width, if it is in the middle of it.

    A = 100*(yourscreenswidth-yoursprite.x-yoursprite.width*1/2)/yourscreenwidth

    Ofc the formula needs further tweaking, if you have a moving screen, that doesn't start with x = 0 to the left.

  • Awesome!

    I was on the right track.

    Note I'll have to figure out how to decrease the other value. )

    Thanks buddy!

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