Jump to content

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() {
	game.physics.arcade.collide(bombFire, floors);
function bombFires(){
	if(bombCount > 0 && spaceKey.downDuration(1)){
		bombText.setText('Bomb ' + bombCount + ' x');	
		bombFire = game.add.sprite(cyclist.body.x + 20, cyclist.body.y + 70, '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);

			game.physics.enable(bombsFire, Phaser.Physics.ARCADE);
			bombsFire.body.gravity.y = gravitation;
			bombsFire.body.velocity.x =320;
			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. 

            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 :( 

Link to comment
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.

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.


  • Recently Browsing   0 members

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