En el tutorial de hoy, vamos a empezar con la primera parte para realizar un juego fenomenal en JavaScriptJavaScript es un lenguaje de programación que funciona en el lado del cliente y con el que las webs pueden ser más funcionales. Incorporación en código HTML El código JavaScript puede ser incrustado en las páginas HTML, para que adquieran funcionalidad. Existen varias opciones. Puede estar entre las etiquetas <SCRIPT> y </SCRIPT>, puede estar contenido en un archivo externo, puede ser un parámetro de las etiquetas HTML, y puede estar plus. East postConcepto de Post¿Qué es un Post?Un Post es todo aquel contenido, sea post, opinión, noticia u otro género, que un autor publica en un blog. Este puede ser de carácter corporativo o meramente ocioso; pero siempre tiene como meta arrojar información o reflejar una idea, al mismo tiempo de facilitar que los usuarios encuentren la web donde se recoge por medio de de buscadores y demás plataformas online.Generalmente, se han plus es una de las muestras de que este programming languageConcepto de Lenguaje de programación¿Qué es un Lenguaje de programación y qué significa?Un Lenguaje de programación es un recopilatorio de instrucciones y términos, un lenguaje formal, que se construye y se emplea para que un PC o un dispositivo pueda crear distintos tipos de datos. Por lo general, hablamos de él como el idioma que el programador habla con la máquina para crear un programa de cualquier tipo.Hay distintos clases plus es sumamente vérsatil, fácil de aprender, y te ayudará a simplificar muchos aspectos de tu código. Así que, sin mas que decir ¡Comencemos!
Step 1: Getting started with an animated background
I really wanted to write a tutorial on a gaming technology that I like to use, so here it is. In this story, we are going to start making a little game of shoot'em up with PixiJS, a very simple and cool Javascript library.
What we are going to do exactly is make a spaceship capable of moving and shooting, enemy waves coming in and a beautiful animated background with moving clouds. The first part (this one you read now) will focus on the background.
How to start?
Let's start by launching our project: I have uploaded an already established code structure, so we are all working on the same basis. However, if you want to do it yourself, I put a photo from my folder just below:
Click here to download your folder

Necesitaremos un serverLos servidores son ordenadores centrales y potentes dentro del campo de la tecnología de la información que procesan y proporcionan software y archivos en una red. Desde el punto de vista de un cliente, varios ordenadores en una red pueden ponerse en contacto con el servidor central para conseguir la información solicitada. En la arquitectura cliente-servidor, el servidor puede ser un software que proporciona un servicio y se ejecuta en plus local para ejecutar el juego: Te invito a descargar WAMP si estás trabajando con Windows, o MAMP para macOS, son gratuitos y fáciles de usar. Vamos a poner tu carpeta de juegos en el servidor (htdocs for MAMP / www for WAMP) y teclear el linkConcepto de Dominio¿Qué es un Enlace?En Internet, un link, además conocido como enlace o hipervínculo, es cualquier texto o imagen que se encuentra en una página web y en la que el usuario puede pulsar o clicar para ser dirigido a otro contenido distinto. Es el principal medio de “desplazamiento” en la red, puesto que se encuentra presente en prácticamente cualquier portal que visites a día de hoy, inclusive en plus localhost en tu browserUn navegador (además: browser) es una herramienta informática que te permite ver documentos y datos y navegar por la red. Los navegadores pueden mostrar distintos tipos de recursos de información; principalmente documentos HTML, a pesar de todo, además son posibles otros tipos de archivos y contenido multimedia, como PDF, JPEG, MPEG, GIF o el lenguaje de meta marcado. A través el uso de complementos especiales y la configuración respectivo, los plus favorito (para mí sería: httpEl HTTP (Hyper Text Transfer Protocol) es un protocolo que se usa para transmitir datos en redes. HTTP es un estándar técnico generalmente aceptado que establece cómo un cliente web se comunica con un servidor para que los datos solicitados por el cliente puedan ser cargados y mostrados. Información general Junto con el URL y el HTML, HTTP es uno de los conceptos más importantes de Internet (www). Fue desarrollado plus://localhost:8888/Spaceship/bin/)
In indexUn index o índice es generalmente un directorio en un orden específico que se usa con fines de orientación. En términos de motores de búsqueda, un índice es la lista de páginas web que es emitido por el motor de búsqueda en respuesta a una solicitud de búsqueda del usuario. Información general La lista que se muestra posteriormente de introducir una solicitud de búsqueda específica se llama SERPs (Search Engine plus.html, we are importing the header javascript files:
<script src="../src/lib/pixi.min.js"></script> <script src="“../src/main.js”"></script>
… And we need to do the same for every file we make. Next comes the Pixi initialization (which is based on the WebGL rendering engine):
var renderer = PIXI.autoDetectRenderer (window.innerWidth, window.innerHeight);
For this tutorial, we tell the game to cover the entire browser window, so if you try it now you will get a totally black background.
The main.js file is where the whole game begins. It's like a manager, with the first run function of the game, and the loop where we can tell the game what to do in each frame. What we want is a blue background for the sky when the game starts, so let's update the init function:
function init () {renderer.backgroundColor = 0x22A7F0; renderer.render (stage); loop (); }
Pixi is using the hex color format, so you need to write your color code preceded by 0x. Let's save and see the result in your browser!
Clouds everywhere!
This background is very boring, let's add some floating clouds.
First, let's add a new class file CloudManager in the folder src (which will create and move the clouds).
class CloudManager {constructor () {} update () {}}
Don't forget to add it to the file index.html how did we do for main.js:
<script src="../src/lib/pixi.min.js"></script> <script src="../src/CloudManager.js"></script> <script src="../src/main.js"></script>
The constructor is the entry point of this class where we can add the spawn function for our clouds. What we want is basically a method capable of creating a cloud each X seconds, and it's perfect because there's a javascript thing for this:
window.setInterval (function () {}, 1000);
This piece of code, placed in the constructor, will call what is inside the game brackets every 1000 milliseconds (= 1 second).
Let's add cloud sprites in the assets folder, and as best we have 2 different images: (the clouds are white with a transparent background so they were invisible on this page, but here are the links on GitHub:
We need to load the sprites before the game starts, so add them in the function Pixi.loader.add:
PIXI.loader.add (["assets / cloud_1.png", "assets / cloud_2.png"]). Load (init);
Ok now we can show the clouds in the method setInterval of CloudManager:
window.setInterval (function () {const sprite = (Math.random ()> 0.5? "cloud_1": "cloud_2"); this.cloud = new PIXI.Sprite (PIXI.loader.resources ["assets /" + sprite + ".png"]. texture); this.cloud.anchor.set (0.5, 0.5); this.cloud.position.set (renderer.width * 1.2, renderer.height * Math.random ()); stage. addChild (this.cloud);}, 1000);
To resume this code:
- First, we are calculating a random number between 0 and 1, it is either less than 0.5, so we store the first sprite in a constant, or it is the second.
- Then, we create a new sprite object with the image we obtained in the previous line.
- The point of origin of this sprite is going to be its upper left corner, so we set its anchor point in the center.
- We have to show the cloud beyond the right edge of the screen, so that it can move to the left across the screen: renderer.width * 1.2 is the position of the left edge + the width of the screen + 20% of its width. We can be sure that we will not see it spawning. For position and, renderer.height * Math.random () is a number between 0 and the height of the window. Therefore, the vertical position of the cloud will be located between the top and bottom of the screen.
- Lastly, we add this cloud to the scene.
If you run this code, nothing should appear, and it's on purpose because they have to disappear from view. So now we have to make them move.
The update feature is the place to do it. But we need to store the clouds in a array to be able to iterate and set their positions. Let's initialize a new array in the builder of CloudManager:
this.cloudsList = [];
... and pushes the clouds in after the stage.addChild function:
this.cloudsList.push (this.cloud);
Now we can iterate the update array and set the position of each cloud:
this.cloudsList.forEach (function (element) {element.position.x - = 4;});
Now it should be working!
Oh wait, something should be bothering us: where are all those clouds going?
Yes, if we don't remove them after they left the screen, they will still exist and may cause some performance issues. Let's add a forEach declaration for each of them that clears them when their horizontal position is slightly lower than the left edge of the screen (so we can't see them exiting):
if (element.position.x <-renderer.width * 0.3) {element.destroy (); array.splice (0, 1); }
We are done with the clouds!
How about making a random variation in the size of the clouds? Add this to the cloud building block:
let minScale = 0.2; let maxScale = 1.2; let scale = Math.random () * (maxScale - minScale) + minScale; this.cloud.scale.set (scale, scale);
If you are missing something or it doesn't work in your code, you can check the result here.
Now continue to the next part to finish our first game in JavaScript. Keep going!





