1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

Path and image angle and direction? How do I combine them?

Discussion in 'Programming' started by R3ZN4, Jan 15, 2020.

  1. R3ZN4

    R3ZN4 Member

    Joined:
    Dec 10, 2019
    Posts:
    12
    So I have a path set... and I have my object on the path... and I have the sprite set to go along with it...

    How do I make the image rotate to follow the path it is going on? It seems like there is just something easy I am missing but for the life of me I haven't been able to find the correct answer yet, I've been searching for the better part of a day.
     
  2. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,981
    An instance's position from the previous step is stored in the variables xprevious and yprevious.
    Its current position is x and y.
    The direction from the former to the latter is the direction it's moving in.
    You can calculate the direction from one point to another using point_direction.
     
  3. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,448
    More specifically, at the beginning of each frame/step, the current coordinates are backed-up to xprevious and yprevious. When positions are updated between the Step Event and End Step Event, x can be compared to xprevious and y can be compared to yprevious. So unless you are manually moving instances yourself, xprevious and yprevious are only really useful in the End Step and Draw events.
     
    TsukaYuriko likes this.
  4. R3ZN4

    R3ZN4 Member

    Joined:
    Dec 10, 2019
    Posts:
    12
    Great thanks I'll try to work it out. Is draw more efficient or is step end, like which 1 is going to take the least resources to keep checking. I am going to have a few battle ships on the screen at the same time all on "patrol".
     
  5. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,448
    Unless you are coding the entire program within one single event, use the end step
     
  6. R3ZN4

    R3ZN4 Member

    Joined:
    Dec 10, 2019
    Posts:
    12
    Thanks. :) Just for my learning, if I "was" going to program it all in 1 event why would I use draw instead?
     
  7. Sabnock

    Sabnock Member

    Joined:
    Jul 21, 2016
    Posts:
    364
    Image_angle = direction;
     
  8. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,981
    End Step executes at the end of every step (frame). If your game runs at 60 FPS, this happens 60 times per second, assuming your game is not lagging.
    Draw executes whenever the game draws the current frame to the screen. This is usually linked to the game's FPS, but can be less if manually configured to be less.

    If you use this for anything other than drawing, it needs to be outside of the Draw event, as it is not guaranteed to happen for every step (because you may override it).
    If it's not used for logic and only for drawing, you can safely put it in the Draw event.
    If you expect performance gains from doing either over the other, drop your expectations, as that's likely not going to have any significant impact on performance.
     

Share This Page