• Content count

  • Joined

  • Last visited

  1. Problem with Arcade body.SetSize()

    @JTronLabs I was bedeviled by a problem in my new game where, on reseting the sprite in a pool of objects, the body sizes were all super wonky. Your fix was the ticket! Thanks so much for sharing!
  2. Head or Body and why

    You can definitely put all of the script tags in the body (which is what I always do), but yes Phaser JS does need to be the first one.
  3. Correct Player Position

    Just wanted to update here that I spent today looking at the Create a Procedural Endless runner book and, with relatively few code changes, I've changed the entire methodology of the structure from one where the platforms move to one where the player is the only element moving. This introduced a few new minor issues (such as positioning of certain sprites like the coin count and life count), but the major glitches appear to have been fixed!
  4. Correct Player Position

    Thanks for the replies @end3r and @drhayes I was (sigh) thinking of actually scrapping the whole thing and trying a different infinite runner approach where only the player moves, based on the Create an Endless Runner book. But perhaps I can try the custom collision or readjusting the velocity first... And, good point about the outOfBoundsKill. I could replace those kill functions with that.
  5. Correct Player Position

    Also wanted to mention that I tried using the update method to continually set the player.x, but that interfered with collision.
  6. How to Deduct Player Lives

    Just wanted to say that I got this working with the ghosting/shield method. Thanks @mattstyles !
  7. Correct Player Position

    Howdy all, I have another question. I'm making an endless runner with the method of moving the tiles to the left and assigning the player an equal and opposite velocity so that it stays in the same place. The problem is that the player doesn't stay in the same place. I've added a velocity of 0 on jump, so the problem isn't that the player is jumping forward. There are just almost imperceptible little movements (I've logged out the player.x during the course of the game and it will move back and forth 5 or 10 pixels) which sometime snowball into big issues where the player hits the left edge of the screen. I haven't been able to isolate the root cause of the problem. The player can collect coins, hearts, and can hit enemies, however, I'm checking overlap on each of these, not collide. Here is the update function in my Game.js: update: function() { /* COLLISION WITH POOLS */ if (this.player.alive) { this.platformPool.forEachAlive(function(platform, index) {, platform, this.hitWall, null, this); this.enemiesPool.forEachAlive(function(enemy, index) {, platform); }, this); // update floor tile speed constantly platform.forEach(function(floor) { floor.body.velocity.x = -this.levelSpeed; }, this); //check if platform needs to be killed if(platform.length && platform.children[platform.length - 1].right < 0) { platform.kill(); } }, this); // update coin and life sprite speed constantly this.coinsPool.forEachAlive(function(coin) { coin.body.velocity.x = -this.levelSpeed; }, this); this.lifePool.forEachAlive(function(life) { life.body.velocity.x = -this.levelSpeed; }, this);, this.coinsPool, this.collectCoin, null, this);, this.lifePool, this.collectLife, null, this);, this.enemiesPool, this.hurtPlayer, null, this);, this.projectilesPool, this.killEnemy, null, this); this.processDelayedEffects(); /* CHECK PLAYER BOOLEANS */ if (this.player.body.touching.down && !this.isHit && !this.isShooting) {'running'); this.player.body.velocity.x = this.levelSpeed; } if (!this.player.body.touching.down) { this.player.body.velocity.x = 0; } if (!this.player.body.touching.down && this.isJumping) { //if up in the air //console.log('player is in the air'); //this.player.x = 400; this.canShoot = true; } if (this.isShooting && this.player.body.touching.down) { //if shooting this.isShooting = false; this.player.body.velocity.x = this.levelSpeed; } /* CONTROLS */ if(this.cursors.up.isDown ||{ this.playerJump(); } else if (this.cursors.up.isUp || { this.isJumping = false; } if(this.spaceKey.isDown){ this.shoot(); } /* PLATFORM CREATION */ //if the last sprite in the platform group is showing, then create a new platform //console.log(this.currentPlatform.children); if(this.currentPlatform.length && this.currentPlatform.children[this.currentPlatform.length - 1].right < { this.createPlatform(); } /* KILL SWITCH */ //kill coins that leave the screen this.coinsPool.forEachAlive(function(coin){ if (coin.right <= 0){ coin.kill(); } }, this); //kill enemies that leave the screen this.enemiesPool.forEachAlive(function(enemy){ if (enemy.right <= 0 || enemy.left <= 200){ enemy.kill(); } }, this); } /* ALLOW ENEMIES TO REMAIN ON PLATFORMS AFTER DEATH */ this.platformPool.forEachAlive(function(platform, index){ this.enemiesPool.forEachAlive(function(enemy, index){, platform); }, this); }, this); /* CHECK IF PLAYER NEEDS TO DIE */ if( >= || this.player.left <= 0 || this.myLivesLeft <= 0) { //alpha doesn't work when bitmapData sprite is continuously redrawn //so only run gameOver once'dying'); this.playerLives.destroy(true, true); this.speedUpTimer.destroy(); this.nextLevelTimer.timer.destroy(); if(this.gameOverCounter <= 0) { this.gameOver(); this.gameOverCounter++; } } }, Any suggestions would be appreciated!
  8. Why aren't my walls solid?

    @danmoople Don't know if this will help, but in my case, I was altering the player's position with player.x, which was interfering with collision detection. Once I commented out that line, collision worked as expected.
  9. How to Deduct Player Lives

    Thanks so much for the suggestion @FinalFantasyVII! @mattstyles Thanks for the list of options! I did see one tutorial where a shield, as you described it, or ghosting as the tutorial described it was implemented. That may be the best of all possible worlds. I had previously tried killing the enemy on impact and it worked, but it doesn't mesh with the game, I think. I'll also look into a collisionEnter. I'll report back if I hit another obstacle.
  10. Player collide with floor sides?

    I finally figured this out thanks to this thread: I was manipulating player.x, which was fiddling with collision. Now I just need to fix an issue where the player's position keeps getting screwed up when hitting an enemy.
  11. How to Deduct Player Lives

    I'm creating an infinite scroller and (among other things) I'm having trouble with deducting player lives. I've looked at various tutorials, but most of them seem to kill the player whenever they hit an obstacle. Ideally, I'd like to deduct a life from the player until they have no more lives. The problem I'm experiencing is that I'm checking overlap with the player and a pool of enemies (btw, works the same way if I check for collision). In the callback, I only want to deduct a life the first time the player comes in contact with the enemy. What's happening now is that a single contact will destroy all the hearts. I've tried using a counter, but that doesn't seem to work well as any attempt to reset it seems to be happening too quickly. I've also tried to use signals, but they seem to result in the same behavior as using the callback. The code looks like this: // In update, this.enemiesPool, this.hurtPlayer, null, this); // Callback hurtPlayer: function(player, enemy) { console.log(this.hitCounter); //do this during overlap this.isHit = true; this.canShoot = false'attacking');'hit'); //only destroy a heart the first time you contact the enemy //enemy should detract 1 heart at most // if (this.hitCounter <= 0) { // this.destroyHeart(); // } // this.hitCounter++; this.destroyHeart(); //enemy.kill(); }, //Destroy heart destroyHeart: function() { console.log(this.myLives); switch(this.myLives) { case 4: this.life4.destroy(); break; case 3: this.life3.destroy(); break; case 2: this.life2.destroy(); break; case 1: this.life1.destroy(); break; } this.myLives--; }, Any suggestions?
  12. Why aren't my walls solid?

    @samme In my case, I definitely am checking collision between walls and player and I've verified that walls show they were being touched, but the player still falls through.
  13. Why aren't my walls solid?

    I have a similar question, so any help would be appreciated!
  14. Player collide with floor sides?

    Howdy all, I've looked everywhere but I can't seem to find an answer. I'm making an infinite scroller. The platforms are automatically generated and they are made up of a pool of floor sprites nested into a pool of platforms (groups of floor sprites). For example: // Creating platforms in Game.js createPlatform: function(){ var nextPlatformData = this.generateRandomPlatform(); if (nextPlatformData) { this.currentPlatform = this.platformPool.getFirstDead(); if (!this.currentPlatform) { this.currentPlatform = new SupRun.Platform(, this.floorPool, nextPlatformData.numTiles, + nextPlatformData.separation, nextPlatformData.y, -this.levelSpeed, this.coinsPool, this.enemiesPool, this.enemySprite, this.player, false); } else { this.currentPlatform.prepare( nextPlatformData.numTiles, + nextPlatformData.separation, nextPlatformData.y, -this.levelSpeed, this.coinsPool, this.enemiesPool, this.enemySprite, this.player, false); } this.platformPool.add(this.currentPlatform); this.currIndex++; } } //Creating groups of floor sprites in Platform.js prefab SupRun.Platform.prototype.prepare = function(numTiles, x, y, speed, player) { //console.log(speed); this.alive = true; var i = 0; while(i < numTiles){ var floorTile = this.floorPool.getFirstExists(false); if (!floorTile){ floorTile = new Phaser.Sprite(, x + i * this.tileSize, y, 'floor'); } else { floorTile.reset(x + i * this.tileSize, y); } this.add(floorTile); i++; } //set physics properties this.setAll('body.immovable', true); this.setAll('body.allowGravity', false); this.setAll('body.velocity.x', speed); this.addCoins(speed); this.addEnemies(speed, this.player); }; The player collides with the top of the of the platforms just fine. However, I would like the player to hit the side of the wall and just fall straight down, instead of falling through. Is this possible?
  15. Timer onComplete callback not working

    Finally fixed it! It isn't perfect but at least it uses Phaser methods. Like so: Paleo.Thorg.prototype.displayNextLetter = function(textObject, message, counter) { this.textObject.visible = true; this.textObject.text = this.message.substr(0, this.counter); this.counter += 1; if (this.counter > this.message.length){ Paleo.Thorg.timerEvent.timer.onComplete.dispatch(); } }; Paleo.Thorg.prototype.displayLetterByLetterText = function (textObject, message, onCompleteCallback) { Paleo.Thorg.timerEvent =, message.length, this.displayNextLetter, {textObject: textObject, message: message, counter: 1}); Paleo.Thorg.timerEvent.timer.onComplete.addOnce(onCompleteCallback, this, 10); }; Thanks a bunch for your help @harrywatson!