What Is the Proper Way of Speeding up the Entire Game?

I’m creating an evolution simulator using cocos2d-x, which uses the physics engine extensively. As you can guess, I need to control the speed of the simulation.

In the scene where I want to control the speed, I’d set the Director’s Scheduler’s time scale along with PhysicsWorld’s speed, like this:

Director::getInstance()->getScheduler()->setTimeScale(SPEED);
this->getPhysicsWorld()->setSpeed(SPEED);

However, setting the SPEED too high (e.g. 10) would cause weird behaviors to happen - such as objects getting inside static objects. I only apply force and impulse to control the motion of objects. So for example, a jumping character would escape the platform and fall down if I speed it up beyond a certain point.

I have few questions:

  • Am I doing anything wrong here?
  • Is there a better way to control the speed of the entire scene?
  • Is there a limit to the speed I can set before the system breaks down?

I’d also like to know if I can make cocos2d-x calculate a specific amount of game steps before rendering. So, let’s say, the simulation will reach a specific state after a specific number of game steps - can I just make cocos2d-x calculate the steps and reach that state as fast as possible?

If anyone wants me to reproduce the problem, I can. However, I think most people can understand what I’m trying to say. Let me know.

You need to take consideration of tunnelling effect on usage of a physics engine, an over-high speed collision may take place between frames and hence unable to be detected.

Also you shouldn’t modify the time scale of the global scheduler of cocos2d::Director (I personally object to providing this API by cocos), since it would affect every schedulers. You should instead implement the time scale in your specific timer only, for instance:

void LayerGame::onEnter() {
	schedule(CC_SCHEDULE_SELECTOR(LayerGame::tick));
}

...

void LayerGame::tick(float dt) {
	// modify time scale here
	dt *= time_scale;

	// apply dt to your game objects below...
}
1 Like

Thanks for your feedback. The tunneling effect is what I didn’t know about. Maybe it’s time to switch to Box2D since it has support for continuous collision detection.

I have a question:

  • What’s wrong with changing the speed of every scheduler? If I want to control the speed of the entire game, shouldn’t I control all the schedulers out there?

Scheduler is not only used as in controlling game objects’ movements but are also employed to tackle non-UI stuffs like a function’s delay call, or for instance, you may have setup a scheduler to poll player’s network status every 10 seconds, since you have modified the global time scale, such polling period would also be affected.

But I want to speed up the entire game, which involves scheduled function calls, etc besides the physics.

Alright, so I think I got the answer by now. I can speed up all the schedulers if I want to. Just need to be careful, avoiding schedulers not related to the speed of the game, simple as that.

The solution is to resolve the tunneling effect, which is caused by discrete collision detection. I think it’s time to switch to Box2D from Chipmunk, as Chipmunk doesn’t have Continuous Collision Detection (CCD) support and isn’t planning to add it in the future, but Box2D already does. Marking your response as the solution to my problem. Really appreciated your help!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.