# How do I... Every X pixels..

Get help using Construct 2

### » Tue Dec 02, 2014 7:54 pm

Ok.Guys and Girls ..
I'm a little bit stupid ,right now

so...I Need help with this ...

Player is Moving...
Every X(32) pixels...do something....(as.... subtract 1 from Variable_1)

ok..save Player x,y...and then...

Thanks!

Edit: Player speed is Constant..so..maybe i can...
....but I want to hear your solutions..........
Last edited by korbaach on Tue Dec 02, 2014 8:05 pm, edited 1 time in total.
B
67
S
24
G
7
Posts: 1,519
Reputation: 11,104

### » Tue Dec 02, 2014 8:02 pm

You could try something like this by saving your object position in instance variables:

Code: Select all
`Start of layout    Sprite.OldX = Sprite.X    Sprite.OldY = Sprite.YCompare two values: distance(Sprite.X, Sprite.Y, Sprite.OldX, Sprite.OldY) >= X    Do something    Sprite.OldX = Sprite.X    Sprite.OldY = Sprite.Y`
Moderator
B
115
S
41
G
20
Posts: 1,586
Reputation: 19,196

### » Tue Dec 02, 2014 8:06 pm

Something like this pseudo code should work :

Code: Select all
`Start of frame     -> Set player.oldPos to player.currentPosEvery tick     -> Add to Player.movementDelta : distance(player.oldPos, player.currentPos)    -> Set player.oldPos to player.currentPosWhile player.movementDelta >= 32    -> Do what you want here    -> Substract 32 to player.movementDelta`

ninja'ed ! You should use definitely use a while if you plan of having tremendous speed, otherwise don't bother.
B
81
S
33
G
27
Posts: 1,029
Reputation: 21,143

### » Wed Dec 03, 2014 8:25 am

Thanks guys and girls!
...That's exactly what I thought..
but I just watched in code.. and my mind fried...
Thanks!
B
67
S
24
G
7
Posts: 1,519
Reputation: 11,104