Jump to content

Arcade overlap not working on group


3ddy
 Share

Recommended Posts

Hello,

it's my first contact with Phaser physics. 

I have a ball sprite this.ball = game.add.sprite(x, .y, "ball");

I created a group with obstacles: 
 

this.obstacle = game.add.group();
this.obstacle.x = 700;
		this.obstacle.y = 350;

		var line = game.add.sprite(0, 0, "line");
		line.anchor.setTo(0.5, 0);
		this.obstacle.addChild(line);

		line = game.add.sprite(0, 0, "line");
		line.anchor.setTo(0.5, 0);
		line.angle = 90;
		this.obstacle.addChild(line);

		line = game.add.sprite(0, 0, "line");
		line.anchor.setTo(0.5, 0);
		line.angle = -90;
		this.obstacle.addChild(line);

		game.physics.enable(this.obstacle, Phaser.Physics.ARCADE);
		for (var i = 0; i < this.obstacle.children.length; i++) {
			game.physics.enable(this.obstacle.children[i], Phaser.Physics.ARCADE);
            this.obstacle.children[i].body.angularVelocity = 30;
        }

Then in update function I'm checking for collisions:

update: function(){      
		  var obstacleHit = false;
		  game.physics.arcade.overlap(this.ball, this.obstacle, function(ball, obstacle){
			if(!obstacleHit){
				obstacleHit = true;
			}
          }, null, this);
          
		  if (obstacleHit) {
			this.ball.destroy();
          }
     },

 

But it works only with one of my three obstacles (don't know which one exactly because they are all the same, close to each other). In other words, it founds collision only on one of three sprites in my this.obstacle group.

What am I doing wrong? I was trying with creating different names (line1,line2,line3) but I guess it didn't change anything.


EDIT: I have found what may be wrong

Collisions are working but only at the place where I spawned my obstacles, not against they current position (they are rotating, body.angularVelocity is set to 50). Any advice?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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