How do I... Every X pixels..

Get help using Construct 2

Post » Tue Dec 02, 2014 7:54 pm

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

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.
Image
B
65
S
23
G
7
Posts: 1,505
Reputation: 10,896

Post » 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.Y

Compare two values: distance(Sprite.X, Sprite.Y, Sprite.OldX, Sprite.OldY) >= X
    Do something
    Sprite.OldX = Sprite.X
    Sprite.OldY = Sprite.Y
Moderator
B
113
S
41
G
20
Posts: 1,586
Reputation: 19,116

Post » 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.currentPos

Every tick
    -> Add to Player.movementDelta : distance(player.oldPos, player.currentPos)
    -> Set player.oldPos to player.currentPos

While 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
69
S
28
G
24
Posts: 977
Reputation: 18,739

Post » Wed Dec 03, 2014 8:25 am

Thanks guys and girls! :D
...That's exactly what I thought..
but I just watched in code.. and my mind fried... :?
Thanks!
Image
B
65
S
23
G
7
Posts: 1,505
Reputation: 10,896


Return to How do I....?

Who is online

Users browsing this forum: ChesVCF, LaDestitute, OBLIVION, Solomon and 25 guests