onfirのブログ -7ページ目

onfirのブログ

ブログの説明を入力します。

About two months ago, I've set a goal: the production of a weekly in HTML5 new game. Up to now, I've got nine games. Now a lot of people wanted me to write about how to make these games, in this article, let us come together with HTML5 make Flappy Bird. Flappy Bird is a very good and easy to use game can serve as a good tutorial HTML5 game. In this tutorial, we use only 65 Phaser framework to write a line of code js Starter Flappy Bird. Click here to experience the first game we are Air Jordan 13 about to be made. Tip 1: You have to be JavaScript Tip 2: Want to learn more about the Phaser framework of knowledge can be seen in this article getting started tutorial (recently busy with work, translated later) is set as a template to download my tutorial production, Nike Shoes which includes: phaser .min.js, simplified Phaser framework v1.1.5index.html, to show the game files main.js, we write the code where asset /, to save the birds and the picture tube folder (bird. png and pipe.png) Open 2012 Cheap Nike Air Jordan 1 High Heels For Sale Beige Pink index.html with a browser, open with a text editor main.js in main.js can see the basic structure we mentioned before Phaser engineering // Initialize Phaser, and creates a 400x490px gamevar game = new Phaser.Game (400, 490, Phaser.AUTO, 'game_div'); // Creates a new 'main' state that will contain the gamevar main_state = {preload: function () {// Function called first to load all the assets}, create: function () {// Fuction called after 'preload' to setup the game}, update: function () {// Function called 60 times per second},}; // Add and start the ' main 'state to start the gamegame.state.add (' main ', main_state); game.state.start (' main '); Next we once preload (), create () and update () method, and increase some new methods. Birds make us look at how to use the spacebar to add a control birds. First, we update the preload (), create () Air Max for Men and update () method. preload: function () {// 2013 Air Jordan 4 (IV) Retro Change the background color of the game this.game.stage.backgroundColor = '# 71c5cf'; // Load the bird sprite this.game.load.image ('bird', 'assets / bird .png ');}, create: function () {// Display the bird on the screen this.bird = this.game.add.sprite (100, 245,' bird '); // Add gravity to the bird to make it fall this.bird.body.gravity.y = 1000; // Call the 'jump' function when the spacekey is hit var space_key = this.game.input.keyboard.addKey (Phaser.Keyboard.SPACEBAR); space_key. onDown.add (this.jump, this);}, update: function () {// If the bird is out of the world (too high or too low), call the 'restart_game' function if (this.bird.inWorld == false) this.restart_game ();}, in which three of the following methods, we add two new methods. // Make the bird jump jump: function () {// Add a vertical velocity to the bird this.bird.body.velocity.y = -350;}, // Restart Air Jordan 11 the gamerestart_game: function () {// Start the 'main' state, which restarts the game this.game.state.start ('main');}, save and refresh main.js index.html you can get a space-keys to control the bird. Pipe production add preload () in the tube loading this.game.load.image ('pipe', 'assets / pipe.png'); draw a tube method and then add the create () in. Because we are in the game to use a plurality of tubes, so we do a group of 20 included tube segment. this.pipes = game.add.group (); this.pipes.createMultiple (20, 'pipe'); now we need a new way to add a tube into the game, by default, all of the tubes have not been activation did not show. We chose a pipe to activate him and show him that he remove his active state in the case of not show, so we have to use a different pipe. add_one_pipe: function (x, y) {// Get the first dead pipe of our group var pipe = this.pipes.getFirstDead (); // Set the new position of the pipe pipe.reset (x, y); // Add velocity to the Air Jordan 10 pipe to make it move left pipe.body.velocity.x = -200; // Kill the pipe when it's no longer Air Jordan 12 visible pipe.outOfBoundsKill = true;}, the previous method only shows a Air Jordans Men's segment of the tube, but we in a vertical line to display 6 paragraphs, and to ensure that the middle of a gap to make birdie adopted. The following method implements this functionality. add_row_of_pipes:! function () {var hole = Math.floor (Math.random () * 5) +1; for (var i = 0; i \u0026 lt; 8; i ++) if (i = hole \u0026 amp; \u0026 amp; i! = hole +1) this.add_one_pipe (400, i Nike Shoes Global * 60 + 10);}, we need to call once every 1.5 seconds add_row_of_pipes () method to achieve added tube. To achieve this purpose, we add a timer create () method. this.timer = this.game.time.events.loop (1500, this.add_row_of_pipes, this); Finally restart_game Lebron James Shoes () top, add the following line of code to implement a method to stop the timer at the beginning of the game again. this.game.time.events.remove (this.timer); now you can test, and has been a bit like a game. The final step to achieve scores Air Jordan 1 and collision Nike shoes online to achieve our scores and collision, it's simple. Add the following code to create () to achieve the 180-159220 Nike LeBron 7 VII Soldier White Black Running Shoes score in the display. this.score = 0; var style = {font: \u0026 quot; 30px Arial \u0026 quot ;, fill: \u0026 quot; # ffffff \u0026 quot;}; this.label_score = this.game.add.text (20, 20, \u0026 quot; 0 \u0026 quot ;, style) ; The following code into add_row_of_pipes () is used to achieve increased scores. this.score + = 1; this.label_score.content = this.score; the following code into the update () method to achieve call restart_game encountered every time the pipe (). this.game.physics.overlap (this.bird, this.pipes, this.restart_game, null, this); you're done! Congratulations, you get a Flappy bird of HTML5 version. Click here to get all the resources. Air Max for Women Game features have been achieved, but it is too simple. The following tutorial we add sound effects, animations, menus and so on. Teach you to use HTML5 make Flappy Bird (under) the original author twitter:lessmilkteach you to use HTML5 make Flappy Bird (on)