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

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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