Jump to content

reversing sprite using


tonyedwardspz
 Share

Recommended Posts

I have created a small platform game to try out phaser. I'm having trouble with reversing a sprite when colliding with a specific tile.

 

I have created the map with Tiled and place specific tiles to create an enemy patrol zone. When an enemy (from a group) collides with the tile it should turn around and go in the opposite direction. I'm using the code below.

 

Within the game.create I'm using setTileIndexCallback to trigger the below function.

 

create: function () {  // other code here    map = this.add.tilemap('level1');    map.addTilesetImage('terrain', 'Tileset');    hogs = this.game.add.group();    enemyHogs = new EnemyHogGroup(this.game, hogs);    map.setTileIndexCallback([75,76], this.reverseWalking, hogs, layer);}reverseWalking: function (sprite, tile, other){             console.log("reverse walking - game");             sprite.body.velocity.x *= 1; }

The reverseWalking function is outputting to the console, but nothing I try against the sprite is having any effect.

 

Can anyone suggest anything? Any help much appreciated.

Link to comment
Share on other sites

The first thing I would check is that the sprite isn't triggering the collision multiple times (which it almost certainly could in this situation). I.e. it might be reversing, then reversing again back into the tile, then again and so on. But so fast you don't notice anything but a stuck sprite.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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