How do you control game speed?

I can think of 2 ways:

  1. by system time. But it is affected by lagging.

  2. by counting ticks. Now I set 1 tick to 10ms. But this is not intuitive, maybe other problems.

how do you think about this question?

You mean you want game to run at 1/4 speed for example? The only way I know is to have a global variable like speed and multiply every operation you do in your game by that variable.

So if you want to have 1/4 speed, have like static float speed = 0.25f;

When you want to move character, multiply the amount you add to players position by 0.25f. So

player.x += player.speed * Game.speed;

And yes, you need to do this for EVERY variable you modify that needs to change speed… I don’t know any other way.

Seems we are not talking entirely about the same thing. I think you have set the GAME_UPDATE_time to a fix time, and then using a speed variable to change mobile moving speed.

But for me game speed is not just about mobile moving. For example, mage chant spells, it gets delayed. So if game speed changed, the delay time should also change. Here, you will use system time * Game.speed to measure delay time?

What are you talking about? I told you, if you want to change game speed, use a global game_speed value, and you have to multiply everything that involves changing values with game game_speed value. That involves: the speed of spell casting, the speed of moving, the speed of rotating, the speed of everything. Every time you do something like integer++, you need to do integer+=1f*Game.speed;

If you design your game right then changing game speed is an extremely simple thing to do. However, to make this work you need to adjust your code so that any calculations that are time-based (movement, delays, special effects, etc…) use a “delta time”, which is the time between the current and previous frame. This is also how all physics engines (like Box2D) work.

Read this for more on how to make a good game loop: http://gafferongames.com/game-physics/fix-your-timestep/

You may want to take a look at my time package I wrote for my framework.

I created a little GameTime system, supporting fixed and delta time callbacks and setting a time scale.

This code might give you an idea how to resolve this problem, or just copy my code and be done :).