andiua

Colliding between sprite or child of group and other group

Recommended Posts

Hello. I`ve just start to learned game dev with Phaser.

Read a lot topics here and saw documentation, but I don`t know what to do

I`m trying to colliding between bombs and the ground.

Ground is a group creating from JSON 

function update() {
	bombFires();
	game.physics.arcade.collide(bombFire, floors);
}
function bombFires(){
	if(bombCount > 0 && spaceKey.downDuration(1)){
		bombCount--;
		bombText.setText('Bomb ' + bombCount + ' x');	
		bombFire = game.add.sprite(cyclist.body.x + 20, cyclist.body.y + 70, 'bombFire');
		bombFire.anchor.set(0.5);
		bombFire.animations.add('bombFire');
		bombFire.animations.play('bombFire',20, true);
		game.physics.enable(bombFire, Phaser.Physics.ARCADE);
		bombFire.body.velocity.set(320, 0);
		bombFire.body.gravity.y = gravitation;
	}
}

in this case one bomb always on floor but when I pressed again spasekey old bomb fall and new is on the floor.

Also I`ve tried to do this with group, but result is the same 

function bombFires(){
	if(bombCount > 0 && spaceKey.downDuration(1)){
		bombFire = game.add.group();
		bombFire.enableBody = true;
		game.physics.enable(bombFire, Phaser.Physics.ARCADE);
		bombFire.create(cyclist.body.x + 20, cyclist.body.y + 70, 'bombFire');
		bombsFire = bombFire.getFirstExists(true);

		if(bombsFire){
			game.physics.enable(bombsFire, Phaser.Physics.ARCADE);
			bombsFire.body.gravity.y = gravitation;
			bombsFire.body.velocity.x =320;
			bombsFire.animations.add('bombFire');
			bombsFire.animations.play('bombFire',20, true);
			// game.physics.arcade.collide(bombsFire, floors);
		}
    }
}

 Also I tried forEach on update() and in function bombFires() and addChild to my hero. But nothing help. 

bombFire.forEach(function(){
            game.physics.arcade.collide(bombFire, floors);
            console.log(game.physics.arcade.collide(bombsFire, floors))
        }, this);

 

Can anyone tell me what I do wrong? I`ve no ideas already :( 

Share this post


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.