Jump to content

Overlap kill problem


waatz
 Share

Recommended Posts

Hello,

 

I'm a beginner who is trying to make a game with phaser and i'm stuck.

As you can see here : LINK

If you fire a bullet without overlap anything its fine but when you fire multiple bullet in a platform the bullet get bugged and i don't know why.

function create(){   bullets = game.add.group();   bullets.createMultiple(15, 'bullet');   bullets.setAll('outOfBoundsKill', true);   game.input.onDown.add(shoot, this);}
function shoot(){   bullet = bullets.getFirstExists(false);      if (bullet){         bullet.reset(player.x, player.y);         game.physics.moveToPointer(bullet, 500);      }}
function update(){   game.physics.overlap(bullets, platforms, platformHit, null, this);}
function platformHit(bullet){   bullet.kill();}

What i did wrong?
Thanks

Link to comment
Share on other sites

I'm always stuck on this..

 

I have do some test and i found something.. the overlap function works (platformHit function is trigger and the bullet is killed) but the bullet isnt draw.

Anyone know why my bullet isnt draw correctly?

Thanks

Link to comment
Share on other sites

Problem fixed.

I don't know if its the best way for what i want but it work.

function create(){   bullets = game.add.group();   bullets.createMultiple(1, 'bullet');   bullets.setAll('outOfBoundsKill', true);   game.input.onDown.add(shoot, this);}
function shoot(){   bullet = bullets.create(player.x, player.y, 'bullet');   bullet.game.physics.moveToPointer(bullet, 500)}
Link to comment
Share on other sites

The solution code looks like you will be creating an unlimited amount of bullet sprites (and never reuse them).

So if the player shoots 1000 times, you will have 1000 bullets in your group.

 

(Since mostly all of them will be "dead" and no longer invisible it might not impact performance that much, but it's definitively not ideal.)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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