Types of physics engines in Construct 2

Construct 2 has three kinds of physics engines it uses to run physics operations:

  • box2dweb: By default, Construct 2 uses the box2dweb version of the physics engine. The box2dweb version is based on the box2d physics engine; a physics engine is commonly used for native games. The box2dweb version is the JavaScript version of it that's intended to be used for web games.
  • box2dweb asm.js: This is the faster version of box2dweb. It uses emscripten (a technology from Mozilla) that takes C and C++ code and produces JavaScript, creating high-performance JavaScript code as a result. This is what's called asm.js, and the browsers that are optimized for asm.js can translate this code to enable fast performance that you'd get from native C and C++ codes. However, all this happens in your browser.
  • CocoonJS native: This is the physics engine optimized for CocoonJS wrapping. If you don't know about it, CocoonJS is a service that helps you wrap or package HTML5 games, like the ones made in Construct 2, to Android and iPhone games. If you're making a mobile game and intend to use CocoonJS to export it, it is advised that you use the CocoonJS native physics engine.

By now, maybe, some of you have a good question in mind: if the asm.js version of box2dweb is faster than normal box2dweb physics engine, then why not make box2dweb asm.js the default physics engine? It turns out that there are two drawbacks of this asm.js physics engine. They are as follows:

  • It doesn't support the disable collisions action. Some old games that are created before the physics engine feature is added might use an action to disable collisions, and setting the asm.js as the new physics engine will break these games. To enable backward compatibility as much as possible, asm.js is not the default physics engine.
  • In iOS native apps, it can be slower. The reason for this is a bit technical. The Safari browser on iOS has a JIT compiler that interprets JavaScript code and runs it. When you run native iOS apps, for example, when you wrap your game using CocoonJS or PhoneGap, JIT (Just In Time) is not supported. Note that this is still fast performance for many games. However, it's still slower than the non asm.js version of the same code, so if you want to deploy games for iOS, it is advised that you do not to use the box2dweb asm.js physics engine.

Okay, so now you know the three types of physics engine Construct 2 uses. Which one should you use? If you're deploying to mobile using CocoonJS, use the CocoonJS physics engine; if you're targeting iOS platforms, use box2dweb; and if you use the disable collisions' action in your game, use box2dweb. If you encounter anything other than these, use the box2dweb asm.js physics engine.

If you want to learn more about the Physics behavior, there's an online manual on Scirra's website (https://www.scirra.com/manual/98/physics).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset