DuranDuran

Members
  • Content count

    10
  • Joined

  • Last visited

  1. DuranDuran

    Player sprite falls through ground on collision...

    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.
  2. DuranDuran

    Player sprite falls through ground on collision...

    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?
  3. DuranDuran

    Player sprite falls through ground on collision...

    Thanks @samme I will use that debugging info. I have tried the fix for this you mentioned in this post: 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.
  4. DuranDuran

    Player sprite falls through ground on collision...

    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
  5. DuranDuran

    Player sprite falls through ground on collision...

    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?
  6. DuranDuran

    problem detecting collisions in game

    Hello, I am making a game using this tutorial: https://gamedevacademy.org/how-to-make-an-infinitely-scrolling-game-with-phaser/ I made some changes to it using the Phaser Basic Project template. I am having a problem with the collision detection. In the update function I have these lines detecting if a collision has happened: update: function () { console.log("in the update function!!!!!!!!!"); // Honestly, just about anything could go here. It's YOUR game after all. // Eat your heart out! // player land on ground instead of falling through this.game.physics.arcade.collide(this.player, this.ground, this.playerHit, null, this); // player bitten by a flea this.game.physics.arcade.collide(this.player, this.fleas, this.playerBit, null, this); // player can overlap with dirt mounds this.game.physics.arcade.overlap(this.player, this.mounds, this.collect, this.checkDig, this); This collision mechanism works as long as the player does not collide with a flea or digs. (I guess this means the collision mechanism does not work.) For example when the player collides with a flea, this.playerBit is called: playerBit: function (player, flea) { //remove the flea that bit our player so it is no longer in the way flea.destroy(); //update our stats this.scratches++; this.refreshStats(); //change sprite image this.player.loadTexture('playerScratch'); this.player.animations.play('scratch', 10, true); //play whine audio this.whineSound.play(); //wait a couple of seconds for the scratch animation to play before continuing this.stopped = true; this.player.body.velocity.x = 0; this.game.time.events.add(Phaser.Timer.SECOND * 2, this.playerScratch, this); }, refreshStats: function () { this.pointsText.text = this.points; this.fleasText.text = this.maxScratches - this.scratches; }, playerScratch: function () { this.stopped = false; // check the number of scratches, if 5 or greater // the player dies if (this.scratches >= 5) { console.log("scratches greater than 4"); 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.anchor.setTo(.5, 1); 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); } console.log("leaving the playerScratch function"); }, After the player scratches, the player sinks below the ground. Why is this? Here is the update function : update: function () { console.log("in the update function!!!!!!!!!"); // Honestly, just about anything could go here. It's YOUR game after all. // Eat your heart out! // player land on ground instead of falling through this.game.physics.arcade.collide(this.player, this.ground, this.playerHit, null, this); // player bitten by a flea this.game.physics.arcade.collide(this.player, this.fleas, this.playerBit, null, this); // player can overlap with dirt mounds this.game.physics.arcade.overlap(this.player, this.mounds, this.collect, this.checkDig, this); //only respond to keys and keep the speed if the player is alive if (this.player.alive && !this.stopped) { this.player.body.velocity.x = 250; //We do a little math to determine whether the game world has wrapped around. //If so, we want to destroy everything and regenerate, so the game will remain random if (!this.wrapping && this.player.x < this.game.width) { //Not used yet, but may be useful to know how many times we've wrapped this.wraps++; // once we wrap we want to destroy everything and regenerate the world this.wrapping = true; this.fleas.destroy(); this.generateFleas(); this.mounds.destroy(); this.generateMounds(); // then put things back in the correct order this.game.world.bringToTop(this.grass); this.game.world.bringToTop(this.mounds); this.game.world.bringToTop(this.ground); } else if (this.player.x >= this.game.width) { this.wrapping = false; } //take the appropriate action for swiping up or pressing up arrow on keyboard //we don't wait until the swipe is finished (this.swipe.isUp), // because of latency problems (it takes too long to jump before hitting a flea) if (this.swipe.isDown && (this.swipe.positionDown.y > this.swipe.position.y)) { this.playerJump(); } else if (this.cursors.up.isDown) { this.playerJump(); } //The game world is infinite in the x-direction, so we wrap around. //We subtract padding so the player will remain in the middle of the screen when //wrapping, rather than going to the end of the screen first. this.game.world.wrap(this.player, -(this.game.width / 2), false, true, false); } },
  7. DuranDuran

    Phaser.StateManager - No state found with the key: boot

    Thank you for the explanation.
  8. DuranDuran

    Phaser.StateManager - No state found with the key: boot

    Great, it worked, thanks. I appreciate it. I have one other question, why did it work? Was it because I needed to attach the object RunRun to the window? Was I in the scope of the window object?
  9. DuranDuran

    Phaser.StateManager - No state found with the key: boot

    The error message is -> Phaser.StateManager - No state found with the key: Boot Please note, the index.html file is in the root folder of the project. The Boot.js file is in the js subdirectory. I have been doing some experiments, and if I remove the line var RunRun = RunRun || {}; from the index.html file then everything loads, the Phaser.StateManager finds the Boot key and everything starts to load. Any idea why?
  10. DuranDuran

    Phaser.StateManager - No state found with the key: boot

    I have a question regarding this issue. I am getting the same error. Any help would be appreciated. I wanted to use an object to contain the game, so maybe that is the issue. I define the object, RunRun, on the index.html page. I define it within the script tag. Here is what I am using for the index.html page: <!DOCTYPE HTML> <html> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-capable" content="yes"> <title>Phaser Basic Project Template</title> <script type="text/javascript" src="js/phaser.js"></script> <script type="text/javascript" src="js/Boot.js"></script> <script type="text/javascript" src="js/Preloader.js"></script> <script type="text/javascript" src="js/MainMenu.js"></script> <script type="text/javascript" src="js/Game.js"></script> </head> <body> <div id="gameContainer"></div> <script type="text/javascript"> window.onload = function() { // Create your Phaser game and inject it into the gameContainer div. // We did it in a window.onload event, but you can do it anywhere (requireJS load, anonymous function, jQuery dom ready, - whatever floats your boat) var RunRun = RunRun || {}; RunRun.game = new Phaser.Game(1024, 768, Phaser.CANVAS, 'gameContainer'); // Add the States your game has. // You don't have to do this in the html, it could be done in your Boot state too, but for simplicity I'll keep it here. RunRun.game.state.add('Boot', RunRun.Boot); RunRun.game.state.add('Preloader', RunRun.Preloader); RunRun.game.state.add('MainMenu', RunRun.MainMenu); RunRun.game.state.add('Game', RunRun.Game); // Now start the Boot state. RunRun.game.state.start('Boot'); }; </script> </body> </html> And here is the Boot.js file: var RunRun = RunRun || {}; RunRun.Boot = function() {}; console.log("hello world!!!!!!!!!"); RunRun.Boot.prototype = { init: function() { // Unless you specifically know your game needs to support multi-touch I would recommend setting this to 1 this.input.maxPointers = 1; // Phaser will automatically pause if the browser tab the game is in loses focus. You can disable that here: this.stage.disableVisibilityChange = true; if (this.RunRun.device.desktop) { // If you have any desktop specific settings, they can go in here this.scale.pageAlignHorizontally = true; } else { // Same goes for mobile settings. // In this case we're saying "scale the game, no lower than 480x260 and no higher than 1024x768" this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; this.scale.setMinMax(480, 260, 1024, 768); this.scale.forceLandscape = true; this.scale.pageAlignHorizontally = true; } }, preload: function() { // Here we load the assets required for our preloader (in this case a background and a loading bar) this.load.image('preloaderBackground', 'assets/images/testLogo.png'); this.load.image('preloaderBar', 'assets/images/preloadr-bar.png'); }, create: function() { // By this point the preloader assets have loaded to the cache, we've set the game settings // So now let's start the real preloader going this.state.start('Preloader'); } };