Jump to content

reversing sprite using


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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...