How to alter image position as if it is a 30FPS animation?

Discussion in 'Programming' started by krugen, Sep 14, 2019.

  1. krugen

    krugen Member

    Joined:
    Jan 24, 2019
    Posts:
    156
    For example, you have a square that moves 1 pixel per frame and you set the fps to 30 when you imported the gif to GMS2. To run the gif would be "image_speed = 1;" and set it to zero when you hit the last frame, whatever that is.

    Now, I don't want to waste time animate the whole thing in a different software and exported it as a gif for GMS2. I want to animate it directly and programmatically in GMS2.

    To move, alter its (x,y), image_alpha, and so on.

    What about FPS? I can't use image_speed because it is just a single frame of a square. Just set room_speed to 30?
     
  2. spoonsinbunnies

    spoonsinbunnies Member

    Joined:
    Aug 24, 2018
    Posts:
    111
    if its a single frame there is no animation? if you mean move 1 frame per step as if it were animated you could just move the x or y per step. If you mean something else Im not sure, your wording here is a little wonky.
     
  3. krugen

    krugen Member

    Joined:
    Jan 24, 2019
    Posts:
    156
    Yea, but I wanna move it such that it is a 30 fps animation
     
  4. spoonsinbunnies

    spoonsinbunnies Member

    Joined:
    Aug 24, 2018
    Posts:
    111
    room speed is how many times per second all the events are called so yes room speed is what you are looking for.
     
  5. krugen

    krugen Member

    Joined:
    Jan 24, 2019
    Posts:
    156
    I have another problem then. If the game is 60fps, how? What if I have all this other animation which runs at different fps?
     
  6. spoonsinbunnies

    spoonsinbunnies Member

    Joined:
    Aug 24, 2018
    Posts:
    111
    that's just finding a ratio, and only updating at the ratio. If your room is at 60fps and you want a single object to run at 30 fps, you only update it every other step.
     
  7. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    2,180
    Your post is a little unclear. You talk about animation speed at 30 FPS, but also moving the position at 30 FPS, which are two different things.

    If you want the thing to move at 30 FPS when your room is running at 60 FPS, you need to multiply all the places where you change the things position by 0.5.

    If you want to generalise this for any room speed, you can calculate the number you need to multiply by, by taking the intended movement speed and dividing it by the room speed.

    Create Event
    Code:
    // Original movement speed values;
    // NOTE : This is just an example, you will probably have a different method
    // of applying speed to your character. These values will just make the
    // character move left and down continuously.
    x_speed = 10;
    y_speed = 10;
    
    // Calculate adjustment factor
    target_fps = 30;
    actual_fps = room_speed;
    scale_fps_amount = target_fps / actual_fps; // 30 / 60 in your case = 0.5
    
    Step Event
    Code:
    // By multiplying the movement amount by the scale factor, the thing will
    // move at the target speed as if it was running at the target fps.
    x += x_speed * scale_fps_amount;
    y += y_speed * scale_fps_amount;
    
    You can apply this "scale_fps_amount" (as I have called it) to anything else you want to slow down relative to the actual room_speed. For example, if the original image_speed was 5, then multiplying it by the scale factor give you an image_speed of 2.5.
     

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