# Spawning objects near you

**URL:** <https://phaser.discourse.group/t/spawning-objects-near-you/2947>\
**Category:** Phaser 3\
**Created:** [June 30, 2019, 4:36pm UTC](https://phaser.discourse.group/t/spawning-objects-near-you/2947 "2019-06-30T16:36:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shirou1](https://avatars.discourse-cdn.com/v4/letter/s/48db29/32.png) [@Shirou1](https://phaser.discourse.group/u/Shirou1)\
**Post date:** [June 30, 2019, 4:36pm UTC](https://phaser.discourse.group/t/spawning-objects-near-you/2947/1 "2019-06-30T16:36:50Z")

</div>

Hi,

So for school, we’re assigned to change the phaser tutorial a bit. So right now, each time you collect the 12 stars, a bomb spawns. I made a pretty big map (2000,600) and want to have multiple stars in it. And each time you collect one, a bomb spawns in a radius arround you. How could I do that?

This is the code from the tutorial that has to be changed:

if (stars.countActive(true) === 0)  
{  
// A new batch of stars to collect  
stars.children.iterate(function (child) {

```
        child.enableBody(true, child.x, 0, true, true);

    });

    var x = (player.x < 400) ? Phaser.Math.Between(400, 800) : Phaser.Math.Between(0, 400);

    var bomb = bombs.create(x, 16, 'bomb');
    bomb.setBounce(1);
    bomb.setCollideWorldBounds(true);
    bomb.setVelocity(Phaser.Math.Between(-200, 200), 20);
    bomb.allowGravity = false;

}
```

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [June 30, 2019, 5:21pm UTC](https://phaser.discourse.group/t/spawning-objects-near-you/2947/2 "2019-06-30T17:21:49Z")

</div>

Start by extracting a new function:

```javascript
function createBomb (x, y) {
  var bomb = bombs.create(x, y, 'bomb');
  // etc. …
}

```

Then modify `collectStar()`. You can find the player’s position in `player`.

---

<div class="post-metadata">

**Author:** ![Shirou1](https://avatars.discourse-cdn.com/v4/letter/s/48db29/32.png) [@Shirou1](https://phaser.discourse.group/u/Shirou1)\
**Post date:** [June 30, 2019, 8:06pm UTC](https://phaser.discourse.group/t/spawning-objects-near-you/2947/3 "2019-06-30T20:06:47Z")

</div>

Don’t enitrely know what you mean after the etc. part and modifying collectstar, would you mind typing it more out? I’m still trying to learn phaser and my other classmates don’t understand it as well and our teacher lets us figure it out
