Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Collision as Trigger


Recommended Posts

I'm new to phaser and really just trying to familiarize myself with it.


I've got a sprite group moving across the screen from right to left and when it reaches certain locations I would like it to perform certain actions; for now I'm just having it log to the console.

game.physics.collide(group, triggerWall, function(){  console.log('it hit the wall');}, null, this);

The wall is an invisible sprite that 1px wide and 100% the height of the game.


It logs to the console as expected (about 100x, due to the width of the group)


The issue I'm having trouble with is there's a "jitter" when the group crosses the line. Each sprite in the group is moved a few pixels and then moves back.


Heres how I've set up the sprites in the group:

group = game.add.group();for (var i = 0; i < 5; i++){  var sprite;        sprite = group.create(x, y, 'block', 1);  sprite.name = 'block' + i;  sprite.height = 30;  sprite.width = 30;  sprite.body.allowCollision = true;  sprite.body.immovable = false;}

and my "wall"

triggerWall = game.add.sprite((game.world.width/2), 1, 'barrier'));triggerWall.name = 'triggerWall';triggerWall.scale.setTo(1, game.world.height);triggerWall.body.immovable = true;triggerWall.visible = false;

So I'm wondering how to avoid the "jitter", or if there's a better way to detect the location of a sprite/group besides using a collision.


Link to comment
Share on other sites


  • Recently Browsing   0 members

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