Search e01
One query across the encyclopedia, books, dictionary, papers, Wikidata and the developer library. Every hit carries its source.
6 results across 6 corpora for Code examples on MDN.
Encyclopedia 0
This corpus is unavailable: timeout
Books 0
This corpus is unavailable: timeout
Dictionary 0
This corpus is unavailable: timeout
Papers 0
This corpus is unavailable: timeout
Wikidata 0
This corpus is unavailable: timeout
Developer library 6
Game development
L, CSS, and JavaScript. The [Learn web development](/docs/Learn_web_development) section is a good place to go to get started with the basics. ## Guides ## Examples For a list of web game examples, see our list of [Tutorials](/docs/Games/Tutorials). ## See also - [Game Programming Patterns](https://gameprogrammingpatterns.com/) - : An online book, written by Bob Nystrom, which discusses programming patterns
Move the ball
loading the ball asset and rendering it at the correct position as it moves. ## Having a ball Let's start by adding a property representing our ball to the `ExampleScene` class. Add the following line just after the opening line, inside the class body: ```js class ExampleScene extends Phaser.Scene { ball; // ... } ``` ## Loading the ball sprite With Phaser, loading images and printing them on our canvas is
Randomizing gameplay
velocity each time the `hitPaddle()` method is run using a line along the lines of the below. Add this new line to your code now, and try it out. ```js class ExampleScene extends Phaser.Scene { // ... hitPaddle(ball, paddle) { this.ball.anims.play("wobble"); ball.body.velocity.x = -5 * (paddle.x - ball.x); } // ... } ``` It's a little bit of magic—the new velocity is higher, the larger the distance
Physics
e instructions Remember to remove our old method of adding values to `x` and `y` from the `update()` method, i.e., restore it to the empty state: ```js class ExampleScene extends Phaser.Scene { // ... update() {} } ``` We are now handling this properly, with a physics engine. Try reloading `index.html` again. At the moment, the physics engine has no gravity or friction, so the ball will go in the given direct
Buttons
ether the game is currently being played or not, and another one to represent our button. Add these lines below your other properties definitions: ```js class ExampleScene extends Phaser.Scene { // ... previous property definitions ... playing = false; startButton; // ... rest of the class ... } ``` ## Loading the button spritesheet We can load the button spritesheet the same way we loaded the ball's wobbl
Track the score and win
and Phaser's `text()` method to print it out onto the screen. ## New properties Add two new properties right after the previously defined ones: ```js class ExampleScene extends Phaser.Scene { // ... previous property definitions ... scoreText; score = 0; // ... rest of the class ... } ``` ## Adding score text to the game display Now add this line at the end of the `create()` method: ```js this.scoreTex