How do I measure how many pixels are moved?

Get help using Construct 2

» Sat Mar 08, 2014 3:28 pm

I have seen that the Bullet Behaviour can do that, I think.
But I have a platform behaviour without bullet behaviour.

I would want: when player jumps, show on the screen how high the player is.
Is this possibily built in?
I have tried distance(x1,y1,x2,y2), but I think I do not understand how to use this command, or I can not use this command to get the result I want.
One of my recent games: Plants
B
31
S
7
G
8
Posts: 729
Reputation: 6,494

» Sat Mar 08, 2014 3:42 pm

Yes use distance.
x1,y1 are for the initial position of you object, x2,y2 are for the the final position.
So all you have to do is to store this values into some variables, for example at jump start for x1y1 and when your object start falling for x2y2 then use the distance function.
B
40
S
15
G
5
Posts: 295
Reputation: 6,129

» Sat Mar 08, 2014 5:00 pm

Thanks, I understand.

My problem is how to measure the Y-distance traveled at every tick. (you mentioned to use an event like jumping or falling, that is not what I have in mind)

I tried:
every tick: store Y into variable1.
every tick: store Y into variable2.
If variable1>variable2 (meaning: object is moving upwards): add (variable1-variable2) to VariableTraveled.

Result: variable1 and variable2 were always the same. VariableTraveled remained 0.

Examples:
As in the game doodle jumper: how far have you traveled upwards?
Or: During a level a balloon (platform behaviour, no bullet behaviour) gradually moves upwards and I want to display how many meters the balloon has traveled.
I expected: every change in Y-movement
One of my recent games: Plants
B
31
S
7
G
8
Posts: 729
Reputation: 6,494

» Sat Mar 08, 2014 5:46 pm

Well can you provide a simple capx, I'll try to have a look on it ?
B
40
S
15
G
5
Posts: 295
Reputation: 6,129

» Sat Mar 08, 2014 6:03 pm

The way you did you're making both variables the same value

Try making variable1 the Y value when the layout starts, and variable2 the Y value every tick.
Variable2-Variable1 will give you the distance traveled
B
87
S
22
G
15
Posts: 1,041
Reputation: 15,353

» Sat Mar 08, 2014 7:00 pm

@Joskin: I will as soon as I can. Thanks.

@7Soul: good suggestion, but I would want to add up Y-distance traveled with every jump the object makes. And the object can fall down. So after 3 jumps, the player stand on the same place as when the layout started, but I would want (as statistic) show how much Y-upwards it has traveled.
One of my recent games: Plants
B
31
S
7
G
8
Posts: 729
Reputation: 6,494

» Sat Mar 08, 2014 7:04 pm

While jumping add dt (delta time) * X to a variable ?
B
40
S
15
G
5
Posts: 295
Reputation: 6,129

» Sat Mar 08, 2014 7:22 pm

@Joskin I am guessing this will do: count how much time passes * X and you have a value that keeps increasing when you jump?
If so, that would be a solution to me. I will try this as soon as I can.
Thanks!
One of my recent games: Plants
B
31
S
7
G
8
Posts: 729
Reputation: 6,494

Return to How do I....?

Who is online

Users browsing this forum: Invidel, OddConfection and 11 guests