Jump to content

Search the Community

Showing results for tags 'collide collision phaser'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Facebook Instant Games
    • Web Gaming Standards
    • Coding and Game Design
    • Paid Promotion (Buy Banner)
  • Frameworks
    • Pixi.js
    • Phaser 3
    • Phaser 2
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
    • GameMonetize
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered
    • Marketplace (Sell Apps, Websites, Games)

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Twitter


Skype


Location


Interests

Found 1 result

  1. // Initialize Phaser, and creates a 400x490px gamevar game = new Phaser.Game(400, 490, Phaser.AUTO, 'game_div');// Creates a new 'main' state that wil contain the gamevar main_state = { preload: function() { // Function called first to load all the assets // Change the background color of the game this.game.stage.backgroundColor = '#71c5cf'; // Load the bird sprite this.game.load.image('bird', 'assets/bird.png'); // Load the pipe sprite this.game.load.image('pipe', 'assets/pipe.png'); }, create: function() { game.physics.startSystem(Phaser.Physics.ARCADE); // Fuction called after 'preload' to setup the game // 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); // Create multiple pipes this.pipes = game.add.group(); this.pipes.createMultiple(20, 'pipe'); this.pipes.enableBody = true; // Timer and adds rows of pipes this.timer = this.game.time.events.loop(1500, this.add_row_of_pipes, this); // Adding key values. upKey = game.input.keyboard.addKey(Phaser.Keyboard.UP); downKey = game.input.keyboard.addKey(Phaser.Keyboard.DOWN); leftKey = game.input.keyboard.addKey(Phaser.Keyboard.LEFT); rightKey = game.input.keyboard.addKey(Phaser.Keyboard.RIGHT); this.bird.body.collideWorldBounds = true; this.score = 0; var style = { font: "30px Arial", fill: "#ffffff" }; this.label_score = this.game.add.text(20, 20, "0", style); game.physics.arcade.enable(this.bird); }, update: function() { // Function called 60 times per second // 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(); if (leftKey.isDown) { this.bird.body.velocity.x = -350 } else if (rightKey.isDown) { this.bird.body.velocity.x = 350 } game.physics.arcade.collide(this.bird, this.pipes); }, // Make the bird jump jump: function() { // Add a vertical velocity to the bird this.bird.body.velocity.y = -350;}, // Restart the game restart_game: function() { // Start the 'main' state, which restarts the game this.game.state.start('main'); this.game.time.events.remove(this.timer);}, 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 pipe to make it move left pipe.body.velocity.y = -200; // Kill the pipe when it's no longer visible pipe.outOfBoundsKill = true; }, add_row_of_pipes: function() { var hole = Math.floor(Math.random()*5)+1;// for (var i = 0; i < 8; i++)// if (i != hole && i != hole +1) // this.add_one_pipe(400, i*60+10); for (var i = 0; i < 8; i++) if (i != hole && i != hole +1) this.add_one_pipe(i*60+10, 500); this.score += 1; this.label_score.content = this.score; },};// Add and start the 'main' state to start the gamegame.state.add('main', main_state); game.state.start('main'); I can't figure out for the life of me why this won't work I get an error saying gravity is null...
×
×
  • Create New...