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

Get help using Construct 2

Post » Sat Nov 15, 2014 7:49 am

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!
Image
B
54
S
24
G
12
Posts: 96
Reputation: 10,316

Post » Sat Nov 15, 2014 8:18 am

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.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Sat Nov 15, 2014 10:35 am

Awesome!
I was on the right track.
Note I'll have to figure out how to decrease the other value. :-))

Thanks buddy!
Image
B
54
S
24
G
12
Posts: 96
Reputation: 10,316


Return to How do I....?

Who is online

Users browsing this forum: plinkie and 20 guests