Jump to content

Problems with setTileIndexCallback


braddollar
 Share

Recommended Posts

'm working on a relatively basic platformer where the player can teleport.

I've achieved this by simply getting the player's current Y coordinate, and then adding or subtracting from there to teleport the player.

This occasionally results in the player ending up inside of a wall, so I need to either check to make sure they are not teleporting into a wall before moving the player (perhaps this would be the easiest way, but i'm not sure how to accomplish it), or I need to move the player back to their previous position if they end up intersecting a wall.

Initially I didn't start using a tilemap, and manually placed all the sprites for the level. During that time I just checked for an overlap after the teleport, and returned the player to the previous position if they overlapped with any of the world sprites. This worked great. I have since switched to a tilemap, but now my previous resolution no longer works. If I use: player.overlap(layer) it returns true no matter where the player is in the world, whether they are touching the walls of the world or just floating through the air.

I tried to use map.setTileIndexCallback(1, stuck(), this), but this does not seem to work properly. Upon loading the game, the callback is executed as soon as the player is loaded in, no matter where I place them in the game, and then when the players falls and hits the ground i receive error:

Uncaught TypeError:
tile.layer.callbacks[tile.index].callback.call is not a function(…)separateTile @ phaser.2.6.js:88459
collideSpriteVsTilemapLayer @ phaser.2.6.js:88376
collideHandler @ phaser.2.6.js:85318
collide @ phaser.2.6.js:85125
update @ game.js:38
update @ phaser.2.6.js:30128
updateLogic @ phaser.2.6.js:36337
update @ phaser.2.6.js:36280
updateRAF @ phaser.2.6.js:61979
_onLoop @ phaser.2.6.js:61962

I have looked at the example for tile callbacks, and tile properties, but I can't figure out where the error is coming from.

Here is my world creation code: 

this.map = game.add.tilemap('brads'); //create tilemap
this.map.addTilesetImage('tileset'); //add tileset image
this.layer = this.map.createLayer('Tile Layer 1'); //specify layer of the tilemap, name set in tiled / json
this.layer.resizeWorld(); //resize the world to match the layer
this.map.setCollision(1); //enable collisions for the first tile in the tileset, 

this.map.setTileIndexCallback(1, this.stuck(), this); //callback for collisions


And then for collisions in the update function:

game.physics.arcade.collide(this.player, this.layer)

 

Any help would be greatly appreciated.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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