Use of JavaScript In Online Games
While HTML5 and C++ might be the first languages that you think of when you think of games, JavaScript has a big role in game development, too.
Join the DZone community and get the full member experience.
Join For FreeDo you know which programming language was used to develop your favorite online game? Many people will immediately think about HTML5 and C++, and they are actually right. These are the most common options. But what about JavaScript?
JS is considered to be the most popular and well-known programming language in the modern world. Its popularity is caused by a number of reasons, including user-friendly code and versatility. Indeed, JavaScript can also be an excellent helper when developing online games. Its scripts make it possible to easily combine JS codes with HTML5 and CSS, thereby creating excellent cross-platform applications.
This article is not another review of online ARPG game or top-list of their best features. Here, we are going to answer the question of whether it is possible to create a cool online game using JavaScript. And also, we’ll list the best engines for this task and some examples of games that can inspire you.
Is It Possible to Create a Proper Online Game Using JavaScript?
Of course, this is possible. There are many 2D and even 3D games created using pure JavaScript or its frameworks. You can find a really huge number of libraries and frameworks, written in JS, but aimed at HTML5 games development, for example — Feather. Games made with JS will not always be native, but this does not make them worse.
Creating a game on JavaScript is not only possible but also simple. In fact, you don’t even have to use Node.js or bother with the server-side of the project. All you need is a basic knowledge of JavaScript and CSS. Still, the required amount of knowledge depends on how complex your game will be. Obviously, you will need more skills to create a large-scale RPG. At the same time, you need literally basic knowledge to develop a simple platformer.
On the web, there are many various step-by-step tutorials aimed at helping you with your first online game. Decide which game you want to develop and proceed to the next step — choosing a library and engine. We have listed the best of them below.
Best JavaScript Engines to Build Web Games
PhaserJS
Phaser is one of the most popular choices among developers when creating an online game. Its database is open-source, and a large community of developers will be there to help you grasp all the processes and find answers to many questions. Phaser uses a built-in JavaScript library — PixieJS. This allows for seamless interaction between WebGL and Canvas elements.
This framework is great for beginners because it handles most of the game automation processes. Thus, you do not need to write long code for each element of your game. Physics of objects can also be achieved using special external libraries. Ultimately, your game produces a very professional feel thanks to the objects' realistic movements and behavior.
In fact, using Phaser and ready-made code from GitHub, you will roll out your first game after a couple of hours of work.
BabylonJS
Oh yes, this is one of the best frameworks for creating 3D browser games. It allows you to render objects of varying complexity, and you do not even need to write a lot of code. Creating a 3D object using a regular WebGL would take a lot of time and code. BabylonJS handles all the complexity on its own, so minimum efforts are required from you.
A few more features of BabylonJS are hardware scaling, a system of particles, smoothing, automatic scene optimization, and the ability to use 9 types of cameras with custom materials and shaders. Sounds good, doesn't it?
MelonJS
This is a lightweight open-source framework that has a number of special features. First of all, this is a "plugin-free" tool for creating games on the "wrote once, launched anywhere" principle. The framework does not have such a large community as the two previous ones, but the developers who prefer Melon are its real fans.
Let's list a few features of the framework:
- lightweight 2D engine;
- a simple HTML5 library;
- compatibility with all popular browsers: Chrome, Mozilla, Opera, Safari, Internet Explorer;
- compatibility with mobile devices;
- lightweight physics with low requirements for your computer's CPU;
- built-in support for CocoonJS and Ejecta;
- and so on.
In short, MelonJS is an ideal choice if your task is to create a simple lightweight 2D browser game with a minimal computational load.
Of course, there are many more of them. However, let's look at some popular games created using JavaScript.
Examples of JavaScript-based online games
On/Off
Oh, this platformer will wrack your brain and freak you out. We have warned you! A beautiful and simple 2D-game with cool physics that pays respects to the Super Mario era. Play with headphones since fun music makes up 30% of the atmosphere.
Konnekt
That’s a great game for training abstract thinking. A virus has infected your system and you must move the nodes to save yourself from the total infection. Try it, but you need to read the rules first.
Everyone's Sky
Oh, this is a full-scale space RPG that runs instantly and works in your browser. Explore space, enter into alliances or destroy your enemies.
1024 Moves
This game is a platformer where you need to move the cube through the map in an attempt to achieve the goal. The levels are full of small puzzles, switches, movable boxes, and so on. What may seem simple to you in the first round, will cause problems in the 6th. Oh yes, you only have 1,024 moves to complete the game!
All these games are a great opportunity to spend free time without buying, downloading, and installing anything. By the way, each of the above games is under 13kb of code. How do you like that? And there are lots of such games.
Summing Up
It is safe to say that JavaScript is used in online games. Yes, it isn't so popular now, but its community and convenience promise a bright future for JS-based online games. It is mostly platformers and puzzles now, with a focus on the intellectual components of the game rather than on graphics or else.
On the other hand, every novice coder, who wants to create a game, can use JS for this. It won't cause any problems, while the experience gained will be unique. The developer can show this game to their friends and discuss how to improve it. It is this unique experience that JavaScript brings to the game development sphere. With the help of JS, everyone has the opportunity to create their own game. Try it for yourself!
Opinions expressed by DZone contributors are their own.
Comments