Adriaticlife
Image default
Business / Information Technology

Game objects

What happens in the written code? First, we import the library. Then we create an object of type Game, setting the resolution of our application, in this case 480 pixels wide and 640 pixels high. Phaser.AUTO means that the render type will be selected automatically. Optionally, you can specify Canvas or WebGL. The fourth parameter sets the parent DOM object for the game, we do not specify it.
The fifth parameter lists the main functions of the game. preload () contains the code to load resources, create () initializes the game, and update () contains the commands to run when the application is updated. On the desktop, update () is called about 60 times per second. It is this function that will contain the main game logic.

In the create () function, we add a static sprite with the background of our game. The sprite fills the space specified in the first four parameters to tileSprite.

 

Now let’s move on to the most interesting thing – let’s fill our game with logic. After declaring the variable game and before the preload () function, we will declare objects with the player’s and computer’s rackets, a ball, and also indicate the speed of their movement:

 

 

html5 games

 

https://www.dergatsjev.be/2021/01/phaser-3-javascript-and-html5-game.html