Jump to content

Collide ask (overlap too)


Aperosuz
 Share

Recommended Posts

Hi

I'm working on a game with phaser 2.4.4 and I have 2 problems with my collide (this 2 line is at the end of my upgrade):

this.physics.arcade.collide(this.shield, this.bullet, this.Reditum(this.shield, bullet, enemy));
this.physics.arcade.collide(this.boat, this.bullet, this.checkCollisions());

My first problems, when I start the game, he go in the Reditum function before any collision between the shield and the bullet, so he crash quickly because he can't find the enemy or the bullet...

My second problems, came after have put this 2 lines in my function enemyshot (My goal was to set available the collision detection only if they have already shot a bullet), the game don't crash but the collision don't work, my bullet cross my shield and my boat without any action.

Here you can find how my shield and my boat were created (i can move the two with WASD and move the shield at the top, bot, left and right with arrows keys):

setupPlayer: function() {
  		this.boat = this.add.sprite(505, 325 , 'boat');
	    this.health = 3;
	    this.boat.anchor.setTo(0.5, 0.5);
	    this.physics.arcade.enable(this.boat);
	    this.boat.body.immovable = true;

	    this.shield = this.add.sprite(this.boat.x  , this.boat.y + 60 , '1');
	    this.shield.anchor.setTo(0.5, 0.5);
	    this.physics.arcade.enable(this.shield);
	    this.shield.body.collideWorldBounds = true;
	    this.shield.body.immovable = true;

  	},

And here how my bullet were created :

this.nbrbullet = 100;

		// Add an empty sprite group into our game
		this.bulletPool = this.add.group();
	
		// Enable physics to the whole sprite group
		this.bulletPool.enableBody = true;
		this.bulletPool.physicsBodyType = Phaser.Physics.ARCADE;
		
		
		this.bulletPool.createMultiple(this.nbrbullet, 'bullet');
		
		// Sets anchors of all sprites
		this.bulletPool.setAll('anchor.x', 0.5);
		this.bulletPool.setAll('anchor.y', 1);
		
		// Automatically kill the bullet sprites when they go out of bounds
		this.bulletPool.setAll('outOfBoundsKill', true);
		this.bulletPool.setAll('checkWorldBounds', true);
		 
		this.nextShotAt = 500;

And here how they are shot:

var bullet = this.bulletPool.getFirstExists(false) 
		if (this.time.now > this.nextShotAt && this.nbrbullet > 0) {
			bullet.reset(enemy.x, enemy.y);
			bullet.body.collideWorldBounds = true;
			bullet.body.bounce.setTo(1, 1);
			if(enemy.x == 35){
				bullet.body.velocity.x = 200;
			}
			if(enemy.y == 35){
				bullet.body.velocity.y = 200;
			}
			if(enemy.x == 975){
				bullet.body.velocity.x = -200;
			}
			if(enemy.y == 615){
				bullet.body.velocity.y = -200;
			}
		}

I hope someone have an idea, if you think the problems come another place, ask me !!

Thanks you

Link to comment
Share on other sites

Well, in your Reditum function you're colliding the enemy and bullet again. And the arguments to your Reditum function aren't right for a collision handler; they only have two arguments, not three. You're doing the thing where you call "this.backSuccess" instead of passing it to the collision function.

That's probably why this.enemy is null. Collision handlers only take two arguments.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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