I'm going to build a tower defense (like) game.

In a heavy tower defense, it takes time to processing.

So, if i set a time interval, it costs interval+processing time so it's not fair.

If i make a processing unit run every 100ms and process all things, it'll be fair but it costs more. And this is not good for flying weapon(like bombs).

Any another way or just use 100ms process unit?


1 Answer 1


This sounds more like a "how do I make a game loop question?" to me. The game loop should control the timing of all your units, and the frequency in which everything is redrawn. Yes, every pass of the loop takes certain amount of time to complete. Depending on how you want to set up your game loop, you can either try to control how much time each pass takes, or you can update each unit based on the amount of time that has passed.

There is a difference between draw rate and update rate. The draw rate would be the frames per second (fps) that you render the game at. You should use a fps that will give you smooth animation for what you are doing. For example, television uses 24 fps, this is enough to fool our brains into thinking that we are seeing fluid motion. On the other hand, some games have fast moving objects that do not look smooth at 24 fps, which is why they might run at 60 fps.

When it comes to updating the objects in your game, if you can get everything done within the amount of time allotted per frame redraw then you are doing good. For instance, if you have set your game up to run at 25 fps, then you have 40ms of processing time in which to update every unit and redraw the frame. That's 1000ms / 25 frames = 40 ms per frame. The amount of time you have to update would be 40ms less the time it takes to redraw the frame. If updating takes longer than this allotted time, you will start to run into trouble, because the extra time spent updating will delay the next frame redraw. This will effect how good your animations look.

If you have a lot of units that need updating and it takes too long to process them all in a single pass, it is possible to update half the units on one frame, and the other half on the next. This will reduce the update time per frame. Or maybe, updating usually gets done on time, unless you have to do a big operation, like pathfinding for 20 different units. Here you could do normal updating for the rest of the units, do the pathfinding for 10 units on one frame, and pathfind for the rest on the next. This small delay for a few units will go unnoticed.

Check out dewitters-gameloop for more details on this.

Regardless, 100ms is probably too long of an interval. Your animations will most likely look choppy at this rate.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .