[UPDATE] Also noticed that on the next lecture there’s a fix to bullet proof the code from having this issue
Hi all, just an observation that I noticed with the whole enemies shaking issue.
At first I had the same issue, where the enemies would shake once they reach the end of the screen. And as mentioned on another thread it looks like it’s due to the EnemyFormation box going out of the Game Area and therefore breaking the loop.
I noticed that I was playing back on a really tiny Game Screen - as I had several windows and tabs open at the same time.
When I changed the Game window to something closer to a real playback situation the bug dissapeared.
Hello,
It might seem like increasing the game window size solves the issue but it’s a temporary fix. If you wait long enough the problem will most likely return.
The issue is not that the enemy formation goes out of the game area. It is supposed to happen anyways as it allows us to change the direction of the formation when it happens. The actual problem is that the deltatime is not constant since the framerate is variable as mentioned in the post you linked. This result is that the formation does not travel equal distances between frames.
This code combined with variable frame rate can lead to the issue in question as shown in the image below: if ( out of bounds ) { flip direction }
The solution then is the code as discussed in the video: if ( out of left bounds ) { change direction to right } else if ( out of right bounds ) { change direction to left }