Using technical best practices

Now that you know all about the usual kinds of best practices that can be applied to all Construct 2 projects, let's move on to the technical kind of best practices. This advice is really useful to improve the performance of your game, and, therefore, it is best suited to be applied to mobile games where the specifications of mobile phones are not as great as desktop computers. Tablets have generally better specs than mobile phones, but when developing your game, it's a good practice to assume that your players won't have a device with as good specs as your device.

Optimizing for mobile platforms

One thing to keep in mind while developing for mobiles is that smartphones aren't as powerful as desktop computers. So, making your game run fast enough should be one of your concerns when you're making a mobile game.

Test your game on mobile phones from the start. A very good way to ensure that your game runs on a decent framerate on a mobile platform is to test it on mobile phones from early on during the development. This can save you from unnecessary surprises later on when exporting your game to a phone. Also, try to get the widest array of smartphones possible, as you won't know what phone your players will end up using to play your games. If you can't get these devices yourself, you can spread an early (alpha) build to testers of your choice or borrow a friend's device.

Here are some ways for you to improve your game's performance on mobile devices:

  • Make sure that you enable WebGL in your project: On devices that support it, WebGL will greatly improve performance. Always set this to On in the project properties. If not supported, Construct 2 will fall back to canvas2D.
    Optimizing for mobile platforms
  • Avoid using too many objects: Showing too many objects on the screen at once can slow your game's speed, so always keep in mind a limit of the number of objects you use. If you want to use repeated sprites for backgrounds or other things, you can use the Tiled Background object, because it is counted as one object.
    Optimizing for mobile platforms

    Tip

    A good rule of thumb when using images is don't exceed 200 MB of memory usage; even going over 100 MB will probably rule out devices with less than 1 GB of RAM. For desktops, don't exceed 400 MB of memory use.

  • Place objects using the same effects on the same layer: If you're using a lot of objects with the same effect in your game, it would be better to just create them on a layer with that effect. This is because applying an effect to a lot of objects is heavier than just making an effect run on a layer. To add an effect to an object or layer, we just need to edit it in their Properties bar.
    Optimizing for mobile platforms
  • Try not to use objects with a lot of transparent area: Contrary to what most people think, transparent areas in your image still take up memory. This means that the game will still try to render them if they are on screen (yes, the idea of rendering a transparent area doesn't really make sense, but that's what happens). If you want to create a game border or something like that, it is better to draw four separate images and create four different objects for them.
  • Avoid large overlaps between two objects: Construct 2 draws objects from back to front, meaning if there are a lot of overlapping areas between two objects, then the overlapped objects would have pixels drawn on top of them again and again. This is a kind of waste of memory resources, because the overlapped areas are not visible to the player, so try to avoid this kind of a situation.

Knowing the cause of poor performance

Besides keeping in mind about maintaining good performance on mobile platforms, you also need to know what generally causes your game to run slowly. The things I'm going to list are common and might cause poor performance on any project. When your game runs slowly on all the tested platforms, check whether or not you did any of these:

  • Changing text objects at every tick: Changing text objects at every tick, whether it changes their size or text, costs quite a lot of performance hit. Usually, text rendering is very fast, but when changed, the object must redraw the text and change the cached texture, which can be expensive.
  • Using too many physics objects: Physics objects are really CPU-heavy operations; using too many of them can cause a big slowdown of your game. Try to keep a few big physics objects rather than many small ones in your games.
  • Creating too many objects: Even though creating an object isn't a heavy operation, creating a lot of objects at the same time will slow your game down. Always try to design your game to use few objects. Similarly, creating objects that scroll off the screen and then forgetting to delete them will slow things down.
  • Using too many effects: Just like developing a mobile game, using an effect on too many objects/instances is a heavy operation on most projects. It's better to have a layer specifically used for objects with the same effect; this will make it faster to implement the effect, because Construct 2 can do it in one operation instead of doing it repeatedly for different instances.
  • Using too many sprites: Just like creating too many objects, using too many sprites can cause a performance hit on your games. An example of how this might happen is when you use a lot of sprites to create a background; instead of using a lot of sprites, it is more efficient to use a Tiled Background object. If making a background is not the reason for using a lot of sprites, this means that you need to design your game more carefully to use fewer sprites.

Listing the common optimization misconceptions

You now know about things that can make your game run poorly, but other than this, there are things that most people think will affect the performance badly, but actually have little effect at all. Knowing these things is almost as important as knowing the real cause for bad performance, since you can save yourself from wasting time trying to optimize when there's no performance gain. Here are some optimization misconceptions:

  • Off-screen objects are still rendered: Construct 2 is smart enough not to draw objects that are not on screen; the only thing it does is take up space in memory. The GPU (Graphical Processing Unit) also doesn't render images that are out of the screen, even if they are part of a single sprite.
  • Image formats affect runtime performance: The only thing different image formats affect is the download size; they don't affect runtime performance. It is the same with audio formats.
  • Number of layers or layouts used also gives a performance hit: The number of layers used doesn't affect performance at all, unless a lot of layers suddenly change their opacity or apply an effect. There'll be no problem using a lot of layers with default settings. The number of layouts used also doesn't have any effect on performance.
  • Know what you're optimizing: One last thing I want to tell you about putting the best performance in Construct 2 is this: don't optimize what doesn't need to be optimized. Sounds obvious, but actually, it's not really that obvious. A lot of people do needless optimizations because they think it's worth it, when it's not; let me break it down for you.

Zeroing in on a frames per second rate

Perhaps the most important performance indicator in any game is how fast it can render every second; this is indicated by its frames per second (FPS). Modern computer monitors update at 60 Hz, which means that they will update 60 times a second. Speaking in a game sense, unless your game is highly framerate-dependent, such as racing games, 30 FPS is good enough for your games. If your game already runs at 60 FPS (or higher), there's no need to improve performance. If your game runs slower than 30 FPS, the speed drop will be noticeable to the human eye, so always try to have at least 30 FPS.

Understanding which part of the game to optimize

Generally, games process two things: the logic and the rendering. The logic is obviously where all your game logic is processed, such as running event logics, checking collisions, running physics, and so on. Rendering is simply the process of drawing images on the screen. It is not unusual for a game to spend 10 percent of the time processing the logic and 90 percent on the rendering part.

This means that whenever you want to speed up your game, always try to improve your graphics performance first. This can be done by reducing the number of sprites on the screen, trying to use the Tiled Background object when possible, not using too many effects, and so on.

Previewing over Wi-Fi

Construct 2 has a very useful feature for when you want to test your game on another device; this is called instant preview over Wi-Fi. For example, if you have a desktop computer and an iPad on the same Wi-Fi network, you can test your game on the iPad without exporting it first.

To use this feature, we must first enable it from Construct 2. Open the File menu and then the Preferences dialog. After the Preferences dialog opens, select the Preview tab and take a look at the Preview on LAN address column. By default, it shows localhost, which means that you're previewing on your PC. Click on the box right beside the column to show the list of local addresses:

Previewing over Wi-Fi

The list of local addresses is the address of your local network; it usually comes in the following format: 129.168.X.Y. Usually, there's only one of it apart from localhost; select it and press the OK button.

Previewing over Wi-Fi

After that, press the OK button in the Preferences dialog. The next step is to close Construct 2 and restart it with administrator permission. If you run your project now, you'll notice a slight change in the game's address shown in the address bar. This is different for each setting; it should look something like this:

Previewing over Wi-Fi

If you type the address that is shown here on your smartphone's or tablet's browser, you'll have the game previewing on your mobile device! This is very useful when you're making mobile games, as it saves a lot of time and effort.

Note

Preview over Wi-Fi is not available in the free version of Construct 2.

Without closing the Preview tab (on your browser), try to change something in the project and then run it again. You should see the browser on your PC and device simultaneously refresh, showing the new version of the game. This really eases the development of mobile games.

Tip

For more information on this feature, you can visit the tutorial at https://www.scirra.com/tutorials/247/how-to-preview-on-a-local-network/page-1.

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

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