Jump to content

Limit number of objects in group


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

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.

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.


  • Recently Browsing   0 members

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