evilwizard

Members
  • Content count

    10
  • Joined

  • Last visited

  1. I appreciate the help samme, I will try this out. Edit: I was able to better define the problem. Please check out my edit above
  2. This sounds really stupid considering Phaser.Tilemap has built in getTileBelow and getTileAbove functions. However, I still can't get this to work. I am creating a Pacman clone in Phaser, and have ran into trouble. I have a method moveUp() that looks like this moveUp: function() { if (cursors.up.justPressed() && this.pathUpAvailable()) { pacman.body.velocity.x = 0; pacman.body.velocity.y = -(gameStats.pacmanVelocity); pacman.frame = 6; pacman.animations.stop(); pacman.animations.play('pacmanUp'); } }, In short, I have four different animations defined depending on which direction Pacman is going in. As such, it doesn't make since to play the animation for moving right when he's moving up and there is a wall to the right. As such, I decided I needed to create four separate functions to determine whether there is a wall in each direction. Here is what the pathUpAvailable() method looks like. pathUpAvailable: function() { return map.getTileAbove(0, (pacman.x / map.tileWidth) | 0, (pacman.y / map.tileWidth) | 0).index == -1; }, If you look at the documentation here http://phaser.io/docs/2.4.4/Phaser.Tilemap.html#getTileAbove It says that this method takes in the following three parameters. layer: The index of the current layer. In my case, I only have one, which defaults to 0. x: The x coordinate to get the tile from. It's important to note that this is measured in tiles not pixels. The x position for a sprite is measured by pixels. As such, we need to divide this value by the tile width as defined in a Tiled JSON file. This value will be a number with decimal points, so it needs to be rounded. Since arrays are zero-indexed in JavaScript we must take the floor of this value, which shorthands to | 0. y: See above. Measured in tiles not pixels This returns a Tile object, of which it seems like the index property determines whether there is a tile there or not. If there isn't, -1 will be returned. This has led to some unpredictable results. Sometimes, it will work, but for example, when the x coordinate of the character is above 400, I will receive the following in my console. Cannot read property 'index' of undefined at Object.pathUpAvailable at Object.moveUp at Object.movePacMan at Object.update I have attached a screenshot demonstrating where the issue occurs Here are a couple of things to keep in mind. It might look like I made a mistake using map.tileWidth twice for the x and y axis and it probably was a mistake. That said, both my tileWidth and tileHeight are set to 6 pixels, so that wasn't the problem here I would like to eventually display the score at the top, so I decided to center the map. I called map.fixedToCamera = false; and then set the position property of the map to center it. Given that I received the above message at a high x coordinate position, this would seem to indicate the problem was with that. I think showing my map1.json file could also be helpful here. { "height":76, "layers":[ { "data":[621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 621, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 621, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 621, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 621, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 621, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 621, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 621, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 621, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 621, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 621, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 0, 621, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 621, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 0, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 621, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 621, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 621, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 0, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 621, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 0, 621, 0, 0, 0, 0, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 621, 621, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621], "height":76, "name":"WallLayer", "opacity":1, "type":"tilelayer", "visible":true, "width":64, "x":0, "y":0 }], "nextobjectid":1, "orientation":"orthogonal", "renderorder":"right-down", "tileheight":6, "tilesets":[ { "columns":61, "firstgid":1, "image":"..\/images\/pacman_tiles.png", "imageheight":384, "imagewidth":368, "margin":0, "name":"pacman_tiles", "spacing":0, "tilecount":3904, "tileheight":6, "tilewidth":6 }], "tilewidth":6, "version":1, "width":64 } Specifically, check the number of tiles which equals 3904. Here was my buildMap function. buildMap: function() { map = this.game.add.tilemap('map1'); map.addTilesetImage('pacman_tiles', 'pacmanTiles'); wallLayer = map.createLayer('WallLayer'); map.setCollisionBetween(1, 5000, true, 'WallLayer'); }, I set the collision to 5000, which is more than the number of tiles.
  3. Just do something like this this.game.add.sprite(100, 100, this.randCharacter()); randCharacter: function() { return this.game.rnd.pick(['goblin', 'orc', 'skeleton']) }
  4. I managed to solve the angular velocity with the nifty game.physics.arcade.velocityFromAngle function.. However, the problem of detecting the current platform the sprite is on persists.
  5. I am creating a platforming game that has multiple different platforms. Some platforms slope up and others slope down. Upward Sloping Platforms * If the character moves right, his y position will increase * If the character moves left, his y position will decrease * The angle property of these platforms is negative Downward Sloping Platforms * If the character moves right, his y position will decrease * If the character moves left, his y position will increase; * The angle property of these platforms is positive The following tries to find the colliding platform. My update function looks something like this game.physics.arcade.collide(hero, platforms, function() { currentPlatform = platforms.children.filter(p => p.getBounds().contains(hero.x, hero.y))[0]; gameState.moveRight(); gameState.moveLeft(); }); } I need this platform to calculate whether the character will move upwards or downwards. Here is an example if (cursors.right.isDown) { if (currentPlatform) { hero.y = currentPlatform.angle < 0 ? hero.y - 0.04 : hero.y + 0.04; } } This obviously doesn't work, and the 0.04 value is hard coded, because I can't figure out how to increment with an angle. I've also tried calling sprite.body.touching, which returns the following Object {none: true, up: false, down: false, left: false, right: false} I am completely lost right now.
  6. I made a pretty good Frogger clone using PhaserJS, but when refactoring the code, I ran into a very, very strange problem. My vehicles currently have a velocity of 200. When Frogger collides with one of them, that vehicle's velocity drops in half. Frogger also gains the velocity of that object. In update this.game.physics.arcade.collide(frogger, vehicles, this.loseLife); Here's my vehicles code objects.forEach(o => this.game.physics.arcade.enable(o)); [normalCar1, normalCar2, normalCar3, specialVehicle1, specialVehicle2, specialVehicle3, emergencyVehicle1, emergencyVehicle2, emergencyVehicle3].forEach(function(object) { object.body.velocity.x = object.direction == 'right' ? 200 : -200; }); Here is my loseLife() function loseLife: function() { /*switch (frogger.health) { case 5: lifeFive.destroy(); break; case 4: lifeFour.destroy(); break; case 3: lifeThree.destroy(); break; case 2: lifeTwo.destroy(); break; case 1: lifeOne.destroy(); break; }*/ frogger.damage(1); gameState.resetPosition(); gameState.resetRows(); /*if (!frogger.alive) { clearInterval(sinkLillies); game.state.start('gameover'); }*/ }, The important method here is resetPosition() which moves Frogger back to the starting position resetPosition: function() { frogger.alpha = 0; frogger.x = this.game.world.centerX; frogger.y = this.game.world.height - 18; game.time.events.add(1000, function() { this.game.timer = 50000; frogger.alpha = 1; }, this); }, The important thing here is that I do not specify that I want the velocity to increase Hopefully, a video will make it easier to understand https://webmshare.com/DmoAQ Edit: A temporary working solution I was able to "solve" this by adding this line in the resetPosition() function frogger.body.velocity.x = 0; And to remove that weird behavior of the car slowing down objects.forEach(function(object) { this.game.physics.arcade.enable(object); object.body.immovable = true; }); This is a hack though. I shouldn't have to explicitly add these lines, because collisions shouldn't cause this behavior in the first place.
  7. I would like to thank you for your quick response. Indeed, you must pass in something for all of the parameters, even if it's null. I got confused because the documentation said they were optional. Adding null to the frame parameter solves this issue. Once again, thank you. This was very helpful for me
  8. I looked at the documentation on how to create a sprite https://phaser.io/docs/2.6.2/Phaser.GameObjectFactory.html#sprite It takes in the following parameters x y key frame group It's very easy to add a sprite with just the first three parameters car1 = this.game.add.sprite(800, 400, 'car'); But it fails when I try to add the car to a group car1 = this.game.add.sprite(800, 400, 'car', objects); If I went with the first declaration and then added objects.add(car1) it will then work I need to use the second declaration because my codebase is becoming way too large, and I need fewer lines. Not sure, why this is failing. Maybe an update killed this functionality?
  9. The problem was I had my river background covering up the objects. That's why they still existed, they were just underneath the river. In my update function, I added this line to the beginning game.world.sendToBack(river);
  10. I am creating a Frogger game with Phaser and to make my codebase more maintainable, I decided to split functionality into separate JavaScript files. A lot of my code has been removed to make this as concise as possible. Here is my preload function. I have a lot more assets, but removed a lot of them for this example. It doesn't look like there's a problem there as all of these images render without calling my moveObjects() method in the update block. function preload() { ["truck", "shortlog", "frogger"].forEach(function(sprite) { game.load.image(`${sprite}`, `assets/images/${sprite}.png`); }); } Outside of the main functions, I create an objects variable. My goal is to populate it with sprites. var objects In my create function, I call two functions from separate files that deal with the vehicles and river logic respectively. function create() { game.physics.startSystem(Phaser.Physics.ARCADE); objects = game.add.group(); addVehicles(); addRiver(); } In vehicles.js, here is my addVehicles() function. The problem doesn't lie with this method as the end functionality is as expected. Vehicles move horizontally across the screen in their intended directions. function addVehicles() { bulldozer1 = game.add.sprite(50, 465, "bulldozer"); bulldozer2 = game.add.sprite(250, 465, "bulldozer"); truck1 = game.add.sprite(600, 330, "truck"); truck2 = game.add.sprite(400, 330, "truck"); [truck1, truck2].forEach(function(car) { car.direction = "left"; objects.add(car); }); [bulldozer1, bulldozer2].forEach(function(car) { car.direction = "right"; objects.add(car); }); } Here is my addRiver() function. Although the code is nearly identical to the function above, it looks like this function breaks things. function addRiver() { lilly1 = game.add.sprite(50, 235, "lilly"); lilly2 = game.add.sprite(220, 235, "lilly"); log1 = game.add.sprite(50, 190, "shortlog"); log2 = game.add.sprite(250, 190, "shortlog"); [lilly1, lilly2].forEach(function(obstacle) { obstacle.direction = "left"; objects.add(obstacle); }); [log1, log2].forEach(function(obstacle) { obstacle.direction = "right"; objects.add(obstacle); }); } In my update() function in main.js, I call a function to move these objects. function update() { moveObjects(); } When an object passes the game world's boundaries, it needs to reappear on the opposite side. The cycleObject method is used here function cycleObject(object) { if (object.position.x > 800) { object.position.x = 0; } else { if (object.position.x < -50) { object.position.x = 750; } } } Finally, I have my moveObjects() method function moveObjects() { for (var i = 0; i < objects.children.length; i++) { objects.children[i].position.x += (objects.children[i].direction == "right" ? 3 : -3); cycleObject(objects.children[i]); } } Result The vehicles behave as expected. The problem is that the river obstacles (logs) have disappeared. The surprising thing is what happens when I call objects.children.length I get the expected value. I can also access one of these hidden objects and find that their position property updates. Another problem is that I don't get any error messages either. My methods in vehicles.js and river.js are virtually identical. I am not sure what's going on here.