siobhan Posted October 16, 2016 Share Posted October 16, 2016 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 More sharing options...
siobhan Posted October 20, 2016 Author Share Posted October 20, 2016 I still haven't found an answer to this, does anyone have any ideas? Thanks for any help! Link to comment Share on other sites More sharing options...
samme Posted October 20, 2016 Share Posted October 20, 2016 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. Link to comment Share on other sites More sharing options...
siobhan Posted October 26, 2016 Author Share Posted October 26, 2016 Hi @samme, thank you very much for your help, you were right on the mark! Quite a weird bug, and I don't really understand why it's doing that – but at least it's easy enough to work around (I adjusted the y position ever so slightly). samme 1 Link to comment Share on other sites More sharing options...
DuranDuran Posted November 30, 2017 Share Posted November 30, 2017 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 More sharing options...
grandnaguszek Posted November 30, 2017 Share Posted November 30, 2017 I had a similar problem to this, and I found out it had to do with the Tile Bias. Normally it is set to 16, but when i set it manually to 32 the I no longer had this issue. game.physics.arcade.TILE_BIAS = 32; Link to comment Share on other sites More sharing options...
DuranDuran Posted December 1, 2017 Share Posted December 1, 2017 (edited) 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 December 1, 2017 by DuranDuran adding source code Link to comment Share on other sites More sharing options...
samme Posted December 1, 2017 Share Posted December 1, 2017 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 More sharing options...
DuranDuran Posted December 1, 2017 Share Posted December 1, 2017 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. 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 More sharing options...
samme Posted December 3, 2017 Share Posted December 3, 2017 I don't remember what I changed, but this seems to work: Game.js Link to comment Share on other sites More sharing options...
DuranDuran Posted February 11, 2018 Share Posted February 11, 2018 Thanks for the file. I tried using it to fix my game, but it is not working. Is there another tutorial I can used to learn Phaser rather than the one from Zenya? Link to comment Share on other sites More sharing options...
samme Posted February 11, 2018 Share Posted February 11, 2018 Try the classic http://phaser.io/tutorials/making-your-first-phaser-game. Link to comment Share on other sites More sharing options...
DuranDuran Posted February 12, 2018 Share Posted February 12, 2018 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 More sharing options...
Recommended Posts