[SOLVED] Slowing down 1 pixel at a time movement w/o fractions

Discussion in 'Programming' started by Bentley, Apr 19, 2019.

  1. Bentley

    Bentley Member

    Joined:
    Jun 18, 2017
    Posts:
    724
    I was working with Lemmings and trying to get the movement right. If you let the step event run with x++, they move too fast.

    I usually do something like this:
    Code:
    // o_control begin step event
    global.frame++;
    
    // o_lemming step event
    if (global.frame mod 3 == 0)
    {
        x++;     
    }
    I was wondering how others go about this. I didn't want to lower the FPS because that messes up other things that I want to run at 60 FPS. I didn't want to move at fractions, although I suppose I could. Anyway, just curious. Thanks for reading.
     
    Last edited: Apr 19, 2019
  2. YellowAfterlife

    YellowAfterlife ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    2,298
    Like so:
    Code:
    // Create
    acc = 0;
    
    // Step:
    acc += 1/3;
    var amt = floor(acc);
    if (amt > 0) {
        x += amt; // or more complex logic
        acc -= amt;
    }
     
    Bentley likes this.
  3. Bentley

    Bentley Member

    Joined:
    Jun 18, 2017
    Posts:
    724
    Haha, that's a nice way to go about. Very helpful, thanks for the reply.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice