Jump to content

Lost life if collide, not correct work


Bobcp
 Share

Recommended Posts

Hi, i'm new to phaser, try to create first game, i have some problems with colision.

 

In case, if character collide with object, he loses one life. It work, but if i jump on object, some times character loses 2 life, help me please, why it happen?

game.physics.arcade.collide(jim, snowballGroup, lostLife);       lostLife = function (){           snowballGroup.forEachAlive(function(snowball) {					if(!snowball.hasOverlap){                    snowball.hasOverlap =true;		    life=life-1;                    jim.body.enable = false;                    jimAliveTimer = game.time.events.add(Phaser.Timer.SECOND *2, jimAlive, this);		    console.log('LifeLost');	         }           })       }        snowballCreate = function() {  			snowball = snowballGroup.create(1500,game.world.height-100-heightGround, 'snowball');			snowball.body.gravity.y = 2000;   			snowball.body.bounce.y = 0.1;                        snowball.body.mass = 10;			snowball.anchor.setTo(0.5, 0.5)				snowball.hasScored=false;		  			snowball.hasOverlap=false;				}
Link to comment
Share on other sites

So it appears your lostLife() collision function is currently searching through all the snowballs to find which ones have the hasOverlap property set to false.  I'm not sure why you're doing this, but because you're looping through every snowball every time there's a collision with one snowball, it seems sometimes there's more than one snowball with this property set to false, causing the player to lose two lives.

What are you trying to do with this hasOverlap property, anyway?  Wouldn't this be better?

 

game.physics.arcade.collide(jim, snowballGroup, lostLife);       lostLife = function (jim, snowball){            snowball.hasOverlap =true;            life=life-1;            jim.body.enable = false;            jimAliveTimer = game.time.events.add(Phaser.Timer.SECOND *2, jimAlive, this);            console.log('LifeLost');       }
Link to comment
Share on other sites

 

So it appears your lostLife() collision function is currently searching through all the snowballs to find which ones have the hasOverlap property set to false.  I'm not sure why you're doing this, but because you're looping through every snowball every time there's a collision with one snowball, it seems sometimes there's more than one snowball with this property set to false, causing the player to lose two lives.

What are you trying to do with this hasOverlap property, anyway?  Wouldn't this be better?

 

game.physics.arcade.collide(jim, snowballGroup, lostLife);       lostLife = function (jim, snowball){            snowball.hasOverlap =true;            life=life-1;            jim.body.enable = false;            jimAliveTimer = game.time.events.add(Phaser.Timer.SECOND *2, jimAlive, this);            console.log('LifeLost');       }

Thank you! Very much, i'm nevbie in phaser, i try to do some stuff, and i think   game.physics.arcade.collide(jim, snowballGroup, lostLife);  not identify what exactly child will be apply function.

 

Sorry for stupid question  :rolleyes: 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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