Jump to content

Ignore decelerate on Collide and Focus on Browser


Archer3CL
 Share

Recommended Posts

Hi!

This time I'm trying to make 2 sprites (enemies vs bullets) collide (group vs sprite). I can detect and execute my function when the objects collide but when they do... the 'enemy' sprite pull back a little and I dont want this.
What I want is that when the bullet collide with de enemy, the bullet disappear and the enemy keep moving forward.

 

I'm using Arcade Physics and this is the code.

 

Update

function update() {    game.physics.arcade.collide(enemies, bullet, destroy, null, this);}

Destroy

function destroy(bullet, enemy) {    var result = checkIfWeak(enemy, bullet);    switch (result) {        case 0:            enemy.destroy();            bullet.destroy();            break;        case 1:            bullet.destroy();            break;    }}

Enemy and Bullet physic properties

//Enemygame.physics.arcade.enable(enemy);enemy.body.acceleration.y += 25;//Bulletgame.physics.arcade.enable(bullet);bullet.body.acceleration.y -= 50;

And my next question is:

 

Does Phaser have an option to keep my game running even after the user is no longer on the window / tab / browser?

 

Thanks for the help

Link to comment
Share on other sites

Instead of using collide, use overlap - this just detects when they touch, whereas collide applies some separation logic to make it look like they've hit each other.

function update() {    game.physics.arcade.overlap(enemies, bullet, destroy, null, this);}

Does Phaser have an option to keep my game running even after the user is no longer on the window / tab / browser?

 

Yes, in your preload or create function just add the following:

game.stage.disableVisibilityChange = true;
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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