How do I... Every X pixels..

  • 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..........

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

    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[/code:2t5n08eg]
  • Something like this pseudo code should work :

    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[/code:3160nrp1]
    
    ninja'ed ! You should use definitely use a while if you plan of having tremendous speed, otherwise don't bother.
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks guys and girls!

    ...That's exactly what I thought..

    but I just watched in code.. and my mind fried...

    Thanks!

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