Chapter 9. Mastering the Best Practices

Congratulations! By now, you already have more than enough skill to create games in Construct 2. Not only that, but you also know how to look for bugs in your game and eliminate them. However, there's one more important thing you need to know: best practices. You should know this because rather than trying to kill bugs later, it'd be much better if you can prevent them from appearing in your games in the first place.

In this chapter, we will cover the following topics:

  • The recommended file formats to use for assets
  • Common things that are recommended for any projects
  • Optimizing memory usage in your games

Applying common best practices

As per my experience, I've divided best practices into two big groups:

  • Common best practices: These are the ones you apply on all your projects, no matter how big or small. Not applying them usually won't give a performance hit to your game but can still slow down your project's development.
  • Technical best practices: These are the ones that give a performance boost to your games. These are usually used on big games that require heavy resources or mobile games where there might be technical constraints. Though these kinds of best practices can also be applied to smaller projects, there's little point in optimizing a game that doesn't need to be optimized. Nevertheless, it's still a good practice.

Backing up data regularly

One really important thing to keep in mind is this: your computers might crash when you're working on your project, thus resulting in lost projects. Other things such as flood, fire, or someone stealing your computer can also cause you to lose your data. You must always have a backup file stored somewhere other than on your PC, just in case something unexpected happens.

Construct 2 has two features to do this automatically, and it can save data to either your computer or to Dropbox. These features are called auto-backup and scheduled backup, and both of them can be set in the Preferences dialog. Setting up these back-up features in Construct 2 is easy, as shown in the following two steps:

  1. To go to the Preferences dialog, click on the File menu and then select the Preferences button:
    Backing up data regularly
  2. A new window will appear. Select the Backup tab to see the setting for the backup features:
    Backing up data regularly

By default, Construct 2 makes one file for backup when saving; this backup is saved in the same folder as your main .capx file and can become useful if the main file is unable to be opened (for whatever reason). The filename for this backup is filename.capx.backup1, or if you keep more than one backup, it becomes filename.capx.backup2, filename.capx.backup3, and so on.

Auto-backup is useful, but it still saves file to your computer. As I explained, it is highly recommended that you save your file somewhere other than on your computer in case of theft or natural disasters. To do this, Construct 2 has the scheduled backup option, which is the second half of the Backup tab. Scheduled backup saves the backup to a specified location at a specified frequency.

It is recommended that you have a Dropbox account, where you'll be guided to install a Dropbox folder on your computer. You can then set the scheduled backup to save your project to this folder, which is then uploaded to Dropbox automatically. The scheduled backup is stored in the folder when you press the Save button after the frequency has passed. For example, if you set a daily backup, the scheduled backup would save your game to the folder after a day or more has passed. Alternatively, if you have a portable hard drive or USB flash disk, you can plug this into your computer and set a backup folder there, which is a good alternative if you're not in a place with a reliable Internet connection.

Tip

It is advised that you make a daily backup to your Dropbox folder, just in case something unexpected happens. This setup process only takes a few minutes, and you don't need to do anything; everything is done automatically.

Testing your game on multiple browsers

While HTML5 is already a standard, the implementation might vary between modern web browsers. It is a good practice to install a few browsers and test your game on all of them. Additionally, if you're making a mobile game, make sure that you test on as many devices as possible.

Supporting devices with touchscreen

There are more and more people using mobile devices these days, and if you're developing a web-based game, it's best to assume that there are people who are going to play your game on a mobile device. To make a game compatible for both desktop and mobile devices, you need to apply some simple tricks that depend on the complexity of your game.

If you're making a one-button game, the kind of game that can be played by the touch of a button, such as Canabalt (you can find this game at https://play.google.com/store/apps/details?id=fishnoodle.canabalt), you can use the Touch object and then set the use mouse input property to Yes; it is No by default. This will make your game recognize the player's left mouse click as a touch, while click-and-drag represents the swipe input.

If you're creating a more complex game, you can start by placing the Start game button at the start of the game before showing the main menu; don't write something like click or tap because this can confuse players who don't play in the platform you assumed. Then, using both the Touch and Mouse objects, you can check whether the fired trigger is On touched object or On object clicked to determine whether the player is on a desktop or a mobile device.

After you know that the players are playing on a mobile device, you can show the onscreen controls. To do this, perform the following steps:

  1. First, create a layer on your project that contains all the onscreen controls' HUD. Let's call it the On-screen controls layer and set its initial visibility to Invisible in the Properties bar.
    Supporting devices with touchscreen
  2. Then, you can create a global text variable called platform; the value of this variable is set when the player touches or clicks on the game the first time. If it's from the On touched object trigger, the value is mobile; if the On object clicked trigger is fired, it is desktop. Using this information, we can add a piece of code when the game plays to show the On-screen controls layer if the player is playing on a mobile device:
Supporting devices with touchscreen

The players can play your game on both desktop and mobile without them having to do anything.

Using the right file format

When working with Construct 2, you might want to prepare your asset files to be in the best format for Construct 2. There are two formats that you need to keep in mind: the image format and the audio format. They are described here:

  • Image format: For this format, use the 32-bit PNG file from your graphic-editor software when possible. The 32-bit PNG is lossless, which means it saves the file in a smaller size without reducing quality, and it supports alpha transparency.
  • Audio files: For this format, use the 16-bit PCM WAV files. Importing an audio file with this file to Construct 2 will make Construct 2 automatically convert it to AAC and Ogg Vorbis. These are the two audio file formats needed to support all modern browsers.

Security

If your game ever needs to save the players' usernames and passwords, don't ever write it into events! It will be plainly visible in the JavaScript code when exported. If you need to use usernames and passwords, store them in a database and write some backend code to access this database, usually in PHP, and then, call this code from the Construct 2 code.

This topic is outside the scope of this book. If you're interested in online security, there are plenty of tutorials on it. Some of them are available on Scirra's website, for example, https://www.scirra.com/tutorials/525/simple-login-using-a-mysql-database.

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

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