I'm working on a spawner class that spawns my game's enemy objects. The spawn time was based on a random number in Spawner.Update() method that would be constantly called throughout the game. As long as current enemies are not greater than int TotalEnemies.
However, the rusted wheel in my head started to crank, and I realized, wouldn't this be bad idea? Wouldn't my enemies spawn slow on a slow pc, and fast on a fast PC? I'm guessing I need to spawn them based on elapsed time rather than Update cycles.
Please let me know if I'm right or wrong, and feel free to share your silly mistakes.
Spawning enemies
If you are looking for a constant timing value then your spawning timer would need to be increased by elapsed.gametime.
If your spawn update method is not limited by the game loop (which it should), then that problem will occur. All your update/process functions should ideally be limited by time, so that they don't perform differently on different machines unlike render functions which are not limited and make use of better machines for better framerates.
Just use seconds or milliseconds to determine how often to release enemies. That's standard across all platforms...unless they are travelling near the speed of light ;)
I suggest you read Fix Your Timestep. While he talks about game physics, it's applicable to the game's entire update process. De-coupling the update process and the render process is a good idea.
Just use seconds or milliseconds to determine how often to release enemies. That's standard across all platforms...unless they are travelling near the speed of light ;)
In other words, limiting in the game loop. Limiting can be done in 2 ways - time-based and frame-based. Time based is obviously the better method as its not dependent on the machine speed.
De-coupling the update process and the render process is a good idea.
Truly!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement