Many prominent online platforms have ramped up production of HTML5 games over years, which has drawn considerable attention from gamers and the game industry across the globe.
Thanks to their adaptability, HTML5 games have spread widely and quickly. In contrast to its brisk market share growth, development of HTML5 games has some challenges. More often than not, the most profitable games are the most labor-consuming ones. After working to overcome the challenges, it eventually becomes apparent that the common cause is a lack of technical knowledge.
So in this article we will provide a minimum overview of how HTML5 games function, how they can be developed, and what might be their future.
1. What is HTML5 anyway?
Since HTML1 was created in 1993, HTML, a standard text-encoding system, has been upgraded over the years up to HTML4, published in 1999.
The HTML5 specification, released in 2014, has various advantages, including cleaner code, mobile application development frameworks, and HTML Offline Web Application API, which allows applications to continue to work regardless of Internet connections.
All these factors make HTML5 a ubiquitous and an indispensable tool for web development.
As a standard, HTML5 was retired on January 28, 2021, succeeded by a specification known as the HTML Living Standard.
2. What are HTML5 games?
Users do not need to download games or register, meaning they can play without worrying about storage space on their smartphones or PCs.
HTML5 game development doesn’t require building apps and can be developed by downloading source code from repositories like GitHub.
However, unlike native game development using Unity or other software, it requires browser and server expertise.
3. Background to the emergence of HTML5 games
HTML5 was created to eliminate Microsoft Silverlight and Adobe Flash. The latter was known to perform poorly and have security flaws.
A large number of companies have been developing a wide variety of full-blown HTML5 games, attracting attention of the tech industry.
4. How to find HTML5 games?
Basically, you can start an HTML5 game by simply clicking a URL embedded in a website. In order to find them, you don’t need Google Play Store or App Store, but rather dedicated portals.
Because individual games can be downloaded from multiple portals, diverse types of games belonging to different genres can be found on them. Below are just a few examples of such portals:
・FB Instant Games
5. HTML5 game development
5-1. HTML Canvas drawing
Canvas is an HTML element that formulates drawings and shapes of characters or various objects in a game.
The canvas tag is easy to use without requiring a lot of programming skills.
5-1.1 What does Canvas enable you to do?
Canvas tags enable you to depict movements and scaling of characters and objects without using multiple divs.
・Drawing images in jpg/png/gif format.
・Drawing straight lines, rectangles, ellipses, Bézier curves, etc.
・Scaling and shifting images.
5-1.2 CSS is necessary to make HTML5 games with Canvas
CSS is applied to create animated graphics with canvas.
You can use CSS to set the background of Canvas objects as these can have transparent backgrounds. On the other hand, CSS cannot modify the inside of areas that have been drawn by canvas.
1. <!DOCTYPE html>
4. <meta charset=”UTF-8″>
5. <title>Use canvas in HTML/title>
8. <canvas id=”canvas”></canvas>
5-1.4 Sample use of Canvas
The following describes a rectangle with canvas.
2. const canvas = document.getElementById(‘canvas’);
3. const ctx = canvas.getContext(‘2d’);
4. ctx.fillStyle = ‘#999’;
5. ctx.fillRect(10, 10, 150, 100);
Canvas element in HTML is referenced by Document.getElementById(). Then the element’s context is obtained and stored in the parameter, ctx. Images are rendered by an interface named CanvasRenderingContext2D, a part of Canvas API, the color of the rectangle is specified with fillStyle, and the dimensions are determined with fillRect. These are only the bare basics. The foundation for HTML5 games is completed when you add detailed programming for drawings: e.g. responses when a figure is clicked or when the cursor is moved over a figure.
5-2. Adding sound and music with Web Audio API
Let’s take a look at just a handful of things that can be done with Web Audio API.
5-2.1 Better than audio elements
Back in the days, audio elements were used to place music and sound in simple games.
Audio elements in HTML5 games often perform poorly with audio not sounding as expected or large latency, depending on the device or environment, while the Web Audio API allows stable play of any multi-channels audio on both iOS or Android devices.
5-2.2 Adding audio
Equipping games with amazing audio can be quite a challenge. But convincing audio not only refines a player’s experience, but helps capture fans who are going to keep coming back.
To accomplish this, it’s crucial to avoid monotonous and short-looped music that likely drives you insane, although it has been common background music in simple HTML games.
With Web Audio API developers could, for example, join different tracks together and make natural shifts between them with minimum effort to add a nice music loop to a game.
Web Audio API also allows audio to be imported in batches via XHR using BufferLoader. Loading audio usually takes a long time, so to maintain efficiency it’s better to load it incrementally in background while players are loading a page or playing.
5-2.3 Examples of sound effect usage
One place the Web Audio API really shines is playing back sound from multiple, precisely timed sources simultaneously.
Let’s take a look at an example where a player is engaged in a machine-gun battle. The sound of gunfire needs to be varied based on the player’s relative position and distance from the target.
To better simulate the randomness of the real firing sound, The Web Audio API provides two simple ways to adjust the scene: 1) Shifting the time between bullets firing. 2) Changing playbackRate and pitch of each sample.
The worlds of many games are based on geometric principles, either in 2D or in 3D. For this reason, Web Audio API supports stereophonic positional audio for creating a more immersive game experience.
6.Storing data in web storage
Cookies have also been used to store browser data. However, they have a storage limit of 4 KB as well as storage deadlines.
It makes them pale in comparison to web storage that can permanently save up to 5 MB of data.
6-1. Local storage
Local storage, as the name suggests, locally saves up to 5MB of data per origin, enabling offline gameplay.
Script tags and forms only access it when necessary unlike cookies that are sent every time a user visits a website.
6-2. Session storage
Session storage stores data in a browser until the browser/window/tab is closed.
The downside is that game data isn’t shared between windows and tabs.
Both local storage and session storage can be used depending on the specific game and its purpose.
Both types of storage support key-value databases. Key-value databases store data as a collection of records, each record is paired with a unique key that can be used to retrieve data.
7. HTML5 game genres
・Role-playing (MMORPG, TRPG, etc. )
Although required developer skill level varies greatly with genres, those with limited knowledge need not worry. Even beginners can create games with simple coding.
8. Will HTML5 games increase in popularity?
Yes, there is much to be excited about. As browsing technology evolves and 5G arrives, HTML5 games are expected to be more stable and immersive than native apps.
Many leading game publishers have already been developing full-fledged HTML5 games every year.
For example, Square Enix, a Japanese production enterprise best known for its seminal game series, Final Fantasy, released two browser games: Imperial SaGa and its predecessor Imperial SaGa Eclipse.
Both are installments of the famous SaGa science fantasy franchise. After Square Enix terminated their support of Imperial SaGa due to waning support for Adobe Flash in December 2019, Imperial SaGa Eclipse made with HTML5 gained a lot of attention.
Given that it requires not just hard work but also very good luck to make a substantial profit with game apps in recent market cycles, HTML5 games will, sooner or later, surpass other mobile games in the industry.