GM:S 1.4 Trying to move a sprite...

Discussion in 'Programming' started by NeonBits, Mar 2, 2019.

  1. NeonBits

    NeonBits Member

    Sep 22, 2017
    I don't know if I have everything to make it perfect. If you like puzzles, here's one:

    create_event :
    var_A = 660;
    var_B = 50;
    var_C = 0;
    "var_B" will decrease depending of the number inside "var_C".
    "var_C" will increase (0, 0.1, 0.2, etc) until it reaches 1. It can also decrease until it reaches 0.

    draw_sprite_ext ( spr_sprite,  0  , var_A  , .........);
    when "var_C" is greater than "0", I would like the sprite to move to the left until "var_A" reaches "415", during the small sequence held in "var_B".

    At "var_B = 50", "var_A" = "660".
    At "var_B = 0", "var_A" should be at "415" (660 - 415 = 245).

    the answer is "var_A -= someting" but I'm just making things too fast or too slow. Best I get is:
    var_A -= (245 / 100) * var_C;
    because of codes somewhere else, once the situation has changed, where "var_A" is still substracted until "415".

    edit: Maybe I should add that the sprite is 162w, 79h, origine: center, and is xscaled/yscaled at 0.1 for depth simulation.
    Last edited: Mar 2, 2019
  2. RefresherTowel

    RefresherTowel Member

    Jul 13, 2016
    Can you name your variables according to what you actually want them to do? Are var_A and var_B the start point and end points of a line and var_C the percentage of the path the sprite should be on?
  3. NightFrost

    NightFrost Member

    Jun 24, 2016
    Your intent is a little unclear, but if you want to create linear movement between two points based on a time / counter variable, you should define start and end points with startx, starty, endx, endy. Then you can calculate current position for both coordinates doing current = start + (end - start) * time.
  4. NeonBits

    NeonBits Member

    Sep 22, 2017
    You can close this.
    I've managed to cheat logic with another logic... after an hundred attempts... It's not perfect but it's ok ( I hope..).
    I was trying to emulate background movement; I could not include the structure as part of it so I made it a sprite; I wanted it to get in the picture according to "distance" and "current speed", while the object was turning. Then had to fix the x/yscale...
    Thanks for the suggestion, but I could not make it work; I was trying upside down or I'm not good enough, probably both, but it moved too fast in the scene. So I adjusted movement compared to the different "speed situations" until it's "good".
    Last edited: Mar 3, 2019

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