Bobcp Posted September 25, 2015 Share Posted September 25, 2015 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 More sharing options...
Cudabear Posted September 25, 2015 Share Posted September 25, 2015 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'); } Bobcp 1 Link to comment Share on other sites More sharing options...
Bobcp Posted September 25, 2015 Author Share Posted September 25, 2015 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 Link to comment Share on other sites More sharing options...
Recommended Posts