Jump to content

Sprite Collision with Ground not working


woratana
 Share

Recommended Posts

Hello,

 

I am using Phaser 1.1.4 and this is the code I used:

 

Game.prototype = {    create: function () {      var x = this.game.width / 2        , y = this.game.height / 2;      // this.player = this.add.sprite(x, y, 'player');      // this.player.anchor.setTo(0.5, 0.5);      // this.input.onDown.add(this.onInputDown, this);            this.game.stage.backgroundColor = '#d0f4f7';      this.game.physics.gravity.y = 250;      this.game.physics.setBoundsToWorld();      grass = this.game.add.tileSprite(0, this.game.height-600, 1024, 512, 'grassland');      ground = this.game.add.tileSprite(0, this.game.height-200, 640, 206, 'ground');      grass.body.allowGravity = false;      ground.body.allowGravity = false;      ground.body.immovable = true;      player = this.game.add.sprite(150, 200, 'player');      player.scale.setTo(3, 3);      player.animations.add('walk', [0,1,2,1]);      player.animations.play('walk', 8, true);      player.body.minVelocity.y = 5;      player.body.collideWorldBounds = true;    },    update: function () {      this.game.physics.collide(player, ground);      ground.tilePosition.x -= 1.4;      grass.tilePosition.x -= 1;      // var x, y, cx, cy, dx, dy, angle, scale;      // x = this.input.position.x;      // y = this.input.position.y;      // cx = this.world.centerX;      // cy = this.world.centerY;      // angle = Math.atan2(y - cy, x - cx) * (180 / Math.PI);      // this.player.angle = angle;      // dx = x - cx;      // dy = y - cy;      // scale = Math.sqrt(dx * dx + dy * dy) / 100;      // this.player.scale.x = scale * 0.6;      // this.player.scale.y = scale * 0.6;    },    onInputDown: function () {      //this.game.state.start('menu');    }  };

The sprite doesn't collide with the ground and it falls to bottom of the screen instead. I used tileSprite as ground, and player as sprite.

 

Please advice me if I did something wrong.

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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