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

R

R3ZN4

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

TsukaYuriko

☄️
Forum Staff
Moderator
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.
 

TheouAegis

Member
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.
 
R

R3ZN4

Guest
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".
 

TsukaYuriko

☄️
Forum Staff
Moderator
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".
Thanks. :) Just for my learning, if I "was" going to program it all in 1 event why would I use draw instead?
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.
 
Top