Jump to content

Player sprite falls through ground on collision...


siobhan
 Share

Recommended Posts

Hello! 

I'm new to Phaser and HTML5 game development (but not to JS), and have been going through a few free tutorials online. I've already done the mobile toddler's game tutorial, and a simple sidescroller game tutorial, great fun so far!

Today I tried to follow an infinite scolling game tutorial (not the same author and not as well written as the first two I followed), but I can't get it to work... The dog falls through the ground on collision with the fleas, and stays stuck down there while the game keeps scrolling. The dog also falls through the ground also after the digging animation...

I compared my game.js code to the author's Game.js code, line by line, and didn't see anything missing – I even went so far as to reorder everything the same way she did (the other files were quasi-identical). This is what I found:

  • If I only paste the author's code in place of mine: the game still doesn't work as expected.
  • If I only use the phaser.js v2.1.3 file (from the downloadable source files), instead of the phaser.js v2.6.2 file I use: the game still doesn't work as expected.
  • If I use both the author's Game.js file and phaser.js v2.1.3: the game works!

I think that the article must be missing something that can be found in the author's code, because I followed the tutorial exactly.

But given that swapping her code for mine still doesn't fix the game, does anyone have any idea what might be causing the player to fall through the ground on collision/overlap? Might it have something to do with gravity, or other physics in Phaser 2.1.3 vs 2.6.2?

Thanks in advance!

Link to comment
Share on other sites

Hi Siobhan, when the dog goes from digging/scratching to walking again, the "dog" texture is reloaded and the physics body is resized (correctly) but not repositioned. The overlap with the ground below is large enough that the physics engine lets it fall through instead of trying to separate them. I don't know why it changes with Phaser 2.6.2 but I guess it's a detail of the collision handling.

doggy.png

Link to comment
Share on other sites

  • 1 year later...

First, thank you @samme the information was very helpful.

I was wondering, how did you find this out?  If there a way to make the outline of the sprite visible for debugging?

Secondly, I made a change to the playerScratch,  I added a anchor.setTo function:

playerScratch: function() {
this.stopped = false;
 
// check the number of scratches, if 5 or greater
// the player dies
if (this.scratches >= 5) {
this.player.alive = false;
 
// reset world,
this.fleas.destroy();
this.mounds.destroy();
 
this.player.loadTexture('dog');
this.player.animations.play('walk', 10, true);
this.player.body.setSize(this.player.standDimensions.width, this.player.standDimensions.height);
 
//.. then run home
this.player.scale.x = -1;
this.player.body.velocity.x = -1000;
 
// run off the screen
this.game.camera.unfollow();
 
//..then go to Game Over state
this.game.time.events.add(15000, this.gameOver, this);
 
} else {
console.log("in the playerScratch function!!!!!!!!!");
this.player.loadTexture('dog');
this.player.animations.play('walk', 3, true);
this.player.body.setSize(this.player.standDimensions.width, this.player.standDimensions.height);
this.player.anchor.setTo(0.5, 1.1);
}

This kept the dog from falling through the ground the first time it was bit.  If the player is bit a second time, the dog falls through the ground.  I did not change any other values for the anchor.setTo() function that appears in the game.js code.  When I change this.player.anchor.setTo in the create function to the same values as above, the player falls through after being bitten once.

Any idea why?

 

 

 

 

 

 

Link to comment
Share on other sites

I tried what you suggested.  I placed this.game.physics.arcade.TILE_BIAS = 32; in the create: function() definition in the Game.js file.  Is this the correct place to set this?

 

After the second collision, the dog sprite is redrawn noticeably lower than before. I attached the game code.

 

Game.js

Edited by DuranDuran
adding source code
Link to comment
Share on other sites

I think TILE_BIAS will make no difference in this game as there's no tilemap.

I might have fixed this issue a while back but I'm not sure where I put it.

You can use 

game.debug.body(sprite);

in render() or (in Phaser CE)

game.debug.physicsGroup(game.world);

 

Link to comment
Share on other sites

Thanks @samme I will use that debugging info.

 

I have tried the fix for this you mentioned in this post: 

On 10/20/2016 at 2:16 PM, samme said:

Hi Siobhan, when the dog goes from digging/scratching to walking again, the "dog" texture is reloaded and the physics body is resized (correctly) but not repositioned. The overlap with the ground below is large enough that the physics engine lets it fall through instead of trying to separate them. I don't know why it changes with Phaser 2.6.2 but I guess it's a detail of the collision handling.

doggy.png

But the problem still happens; The dog falls through the ground after the second bite.  I have attached the game.js file to this topic. I am using the most recent version of Phaser CE.

Link to comment
Share on other sites

  • 2 months later...

Thanks, I wanted to tell you that I have the 'bit by fleas' mechanic working correctly.  Now I am working on the digging mechanic.  Thank you for the help.

 

Now I am working on this problem: Given that the dog is over a mound with a toy in it,  when I press the down key, then the digging dog animation starts and the dog disappears beneath the ground, never to be seen again.

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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