How to make a game in javascript?

I know object oriented PHP and Java, and I can correctly code Javascript at the moment.

However, for life, I'm not sure how Google made the game in JavaScript.

It seems to be compressed (code), so I can't figure out what is going on.

I thought javascript was only single-threaded, which made the development of the game even more difficult.

I saw GWT, but I thought it was more for interface design, I did not see any game development there. If someone can direct me to some toolkit or open my eyes to how people code games in Javascript, I would be grateful!

+4
source share
3 answers

Google (if you are thinking of a pacman game) used a new HTML5 function that supports a kind of "threading" called WebWorkers . You can also use timeouts, etc., to pretend to use streams, although this is actually not the case.

Writing a game in Javascript is similar to how you did it in C. Or rather messy C with most things in one file. You just need to define all your components in one javascript file (or several if you use WebWorkers) and click go. Graphics are mostly done using HTML5 canvas 2d, or if you're really on the verge of a canvas 3D canvas 3D system, which is not yet properly supported in all modern browsers.

In fact, you can create a game by simply setting one large Canvas width and height to 100%, and then program your entire system in this javascript file, ignoring the fact that you are on the Internet (if you want). Most common graphics, streaming, databases, networks, etc. The game's standard features are already built into the latest HTML 5 specification.

+4
source

This javascript-based SO question should help and google has appeared gameQuery and GameJS ... this should at least give some idea of โ€‹โ€‹what is being done.

This site also has a gallery of javascript games ...

+3
source

It is now very difficult to make a complex game in Javascript, mainly due to browser incompatibility. But the guys from Google made the earthquake port 2 in Javascript with GWT.

To create your own game, you can use HTML5 canvas or better vector graphics (VML for IE and SVG for others), possibly with the raphael.js library as an abstraction layer. You can also use some kind of physical engine, for example Box2DJS

3D Javascript is no longer an option because WebGL is under development.

0
source

Source: https://habr.com/ru/post/1314791/


All Articles