Jump to content

Overlap not working after reset player


Bala
 Share

Recommended Posts

After reset to player and ball position the overlap function not working, I am very new to phaser, Could someone please help me out.

 

Here is the reset and overlap code:

 

 
function reset()
{
player1.frame = 6;
player2.reset(400-80,game.world.height-437);
game.physics.startSystem(Phaser.Physics.ARCADE);
player2.body.velocity.x = 0;
 
ball.reset(400-30,400);
ball.scale.setTo(0.4,0.4);
game.physics.arcade.enable(player2);
game.physics.arcade.enable(ball);
 
}
 
function update(){
player2.body.velocity.x = 0;
game.physics.arcade.overlap(player2, ball, collectBall, null, this);
}

 

 

Link to comment
Share on other sites

I'd make sure you only call game.physics.arcade.enable once (and also there's no need to call game.physics.startSystem at all, as Arcade is on by default) on the creation of your sprites (in the create function usually) as it's unnecessary to call it each time you reset your sprites. Everything else as far as I can see seems fine, so it may be these unnecessary calls resetting the physics system maybe?

Link to comment
Share on other sites

Hi lewster32,

 

I have removed those lines but still the same problem exist.. Can you please tell me how we can restart the game without refresh the page? Shall we call create function once again instead of reset func?

Link to comment
Share on other sites

I'm not sure what's causing the problem - it doesn't look to me like anything else in the code you've shown me would cause the overlap function to fail.

 

The only fool-proof way to restart the game fully is to refresh the page, otherwise you will need to use states and keep everything within the state contexts and/or ensure any globals are reset to their defaults when you restart the game.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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