Jump to content

Parallax background


Nikow
 Share

Recommended Posts

Hi !

 

I'm looking for create a speed runner like or a jumping game like Doodle jump.

 

My question is : What's the better way to make the background parallax effect with Phaser ?

 

Thanks !

Link to comment
Share on other sites

MichaelD is correct. Here is an implementation if you need it:
 

preload: function() {  // Load our tilesprite image for the background  this.game.load.image('background', 'Path/To/Your/Background.png');  // Load our tilesprite image for the ground  this.game.load.image('ground', 'Path/To/Your/Ground.png'); }create: function() {    // Add the tilesprite for the background to the game at position 0, 0  // params - Xpos, Ypos, Width, Height  this.bg = this.game.add.tileSprite(0, 0, backgroundWidth, backgroundWidth, 'background');  // Add the tilesprite for the ground to the game just below the background  this.ground = this.game.add.tileSprite(0, backgroundHeight, groundWidth, groundHeight);  // Now add our ground to the physics engine for collisions with the player  this.game.physics.arcade.enable(this.ground);    // Make sure it doesn't react to gravity  this.ground.body.allowGravity = false;  // Make the ground immovable  this.ground.body.immovable = true;}update: function() {  // Create collision check for player and ground  this.game.physics.arcade.collide(this.player, this.ground);  // Finally we move the two tilesprites at different speeds to simulate parallax  this.bg.tilePosition.x -= 0.5;  this.ground.tilePosition.x -= 1.5;}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...