Jump to content

Tilesprite collision issue


srobertson421
 Share

Recommended Posts

Hi guys! I'm currently having an issue with using a tilesprite as the ground for an infinite runner game. Using Arcade physics I set a body to the tilesprite so that I could check collision between my sprite and the ground. The problem comes when the collision actually happens. The sprite body doesn't flag "body.touching" as down nor does it work with "body.onFloor()".

 

A by-product of this issue is that my jump function is negated for some reason. Once my sprite collides with the ground he can't move up at all.

 

Any help would be appreciated!!

 

This is my main game state:

Play = function(game) {  this.game = game;  this.boy = new Player(game);  this.girl = new Girl(game);  this.bg = null;  this.ground = null;}Play.prototype = {  create: function() {        this.bg = this.game.add.tileSprite(0, 0, 438, 136, 'background');    this.ground = this.game.add.tileSprite(0, 125, 438, 44, 'ground');    this.game.physics.arcade.enable(this.ground);    this.ground.body.allowGravity = false;    this.ground.body.immovable = true;    this.ground.body.setSize(this.ground.width, this.ground.height - 10, 0, 10);        this.boy.create();    this.girl.create();  },  update: function() {        this.bg.tilePosition.x -= 0.5;    this.ground.tilePosition.x -= 1.5;        this.boy.update();    this.girl.update();        this.game.physics.arcade.collide(this.boy.player, this.ground);      }

And here is my player class:

Player = function(game) {  this.game = game;  this.player = null;  this.cursors = null;}Player.prototype = {  create: function() {    this.player = this.game.add.sprite(this.game.world.width / 2, this.game.world.height / 2, 'boy')    this.player.anchor.setTo(0.5, 0.5);    this.player.scale.setTo(0.5, 0.5);    this.game.physics.arcade.enable(this.player);    this.player.body.collideWorldBounds = true;        this.player.animations.add('run', ['run1', 'run3', 'run2', 'run4'], 8, true, false);    this.player.animations.add('jump', ['jump1', 'jump2'], 5, false, false);    this.player.animations.add('fall', ['fall1', 'fall2', 'fall3'], 8, false, false);        this.cursors = this.game.input.keyboard.createCursorKeys();  },  update: function() {        this.player.body.velocity.x = 0;    this.player.animations.play('run');        if (this.cursors.left.isDown) {      this.player.body.velocity.x = -100;    } else if (this.cursors.right.isDown) {      this.player.body.velocity.x = 100;    }        if (this.cursors.up.isDown) {      this.player.body.velocity.y = -200;      this.player.animations.play('jump');    }

Here is a live version:
http://largemoose.cloudvent.net/infinite-runner/index.html

 

 

Thanks in advance!!

Link to comment
Share on other sites

Whoops!! Nevermind, I figured it out. Seems I shouldn't have been calling the "collide()" method after my sprite update method. Just called the collision before the update and it works.

 

Is there a way to delete a post to avoid looking like a jackass? lol ;)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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