Jump to content

Limit number of objects in group


michael-Bell
 Share

Recommended Posts

Sorry if this is a simple problem, this is my time using Phaser

 

I am making a simple platforming game where you shoot at boxes, I am trying to limit the number of bullets that can be onscreen at any given time. In TypeScript, you can pass along the max number when you create the group, as shown here(http://jessefreeman.com/game-dev/building-a-html5-game-with-phaser/).

 

bulletGroup = myGame.createGroup(10); // the max number is 10

 

To make this group in Javascript, I would use

 

BulletGroup = game.add.group();

 

But if I try to pass along 10, then I get an error in the phaser.js file saying:

TypeError: c.addChild is not a function
 

Can someone suggest how I can resolve this problem?

Link to comment
Share on other sites

That's a really old tutorial, using a really old version of Phaser, sorry.

 

There is no limit on the number of items in a Group any more. But there is no reason why you couldn't pre-fill the Group with 10 bullets and then just recycle them as required, I mean as long as you don't create any further bullets the Group can never grow in size.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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