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.
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:
canvas2D
.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:
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:
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.
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.
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:
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.
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:
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.
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.
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.