druphoria Posted July 17, 2014 Share Posted July 17, 2014 I'm creating a platformer right now and I want to trigger a death function each time the player falls into a hole. Ideally the player will also fall off screen. It seems that if I have collideWorldBounds equal to true, then it automatically makes the player collide with all four sides of the world without a way to specify that I only want this to occur for the left and right sides. I came up with a hacky solution which is to overwrite the function checkWorldBounds in Phaser's Body class and remove the final clause the if-clause that checks for collision with the bottom of the world. I'm wondering if there is a more straightforward way to do this within the framework that I am missing. Link to comment Share on other sites More sharing options...
druphoria Posted July 17, 2014 Author Share Posted July 17, 2014 Actually this solution is working out quite nicely. Here, I overwrite the method to not check for lower bound:// Allow the sprite to fall off screenfunction disableLowerWorldBoundsCheck(sprite) { sprite.body.checkWorldBounds = function () { if (this.position.x < this.game.physics.arcade.bounds.x && this.game.physics.arcade.checkCollision.left) { this.position.x = this.game.physics.arcade.bounds.x; this.velocity.x *= -this.bounce.x; this.blocked.left = true; } else if (this.right > this.game.physics.arcade.bounds.right && this.game.physics.arcade.checkCollision.right) { this.position.x = this.game.physics.arcade.bounds.right - this.width; this.velocity.x *= -this.bounce.x; this.blocked.right = true; } if (this.position.y < this.game.physics.arcade.bounds.y && this.game.physics.arcade.checkCollision.up) { this.position.y = this.game.physics.arcade.bounds.y; this.velocity.y *= -this.bounce.y; this.blocked.up = true; } };}Here I attach the kill function:this.sprite.body.checkWorldBounds = true;this.sprite.events.onOutOfBounds.add(this.killPlayer, this); Link to comment Share on other sites More sharing options...
InsaneHero Posted July 17, 2014 Share Posted July 17, 2014 That seems like a pretty clean solution to me. Link to comment Share on other sites More sharing options...
Dumtard Posted July 17, 2014 Share Posted July 17, 2014 game.physics.arcade.checkCollision.down = false Link to comment Share on other sites More sharing options...
Recommended Posts