scope2229 Posted July 7, 2018 Share Posted July 7, 2018 Hi i have a player prefab that imports a bullet prefab. inside my player prefab i call the bullet like so this.bullets = this.scene.add.group({ classType: Bullet, maxSize: 1, runChildUpdate: true }); now maxSize i want to change on the fly. Should i place the group inside update instead and then have this this.magSize = this.scene.registry.get('magSize'); this.bullets = this.scene.add.group({ classType: Bullet, maxSize: this.magSize, runChildUpdate: true }); or another way i can think of us using an update event from the registry itself something like this.registry.events.on('changedata', this.updateData, this); then create the group inside the updateData function ???? Link to comment Share on other sites More sharing options...
scope2229 Posted July 7, 2018 Author Share Posted July 7, 2018 Or could i get rid of the maxSize and use some thing like this.magSize = this.registry.get('magSize') this.magBal = this.bulletGroup.countAlive() if(!magBal == magSize){ if(check if fire button is pressed and time since last shot > intervalShot){ fire the bullet using the normal way maxSize will always be 10 as to many otherwise } } Link to comment Share on other sites More sharing options...
scope2229 Posted July 8, 2018 Author Share Posted July 8, 2018 I found a very rudimentary way of achiving this if anyone knows of a better way be great to see but basically its like this. any more than 10 bullets is a waste of resources so ill keep maxSize at 10. then set an object equal to the groups active count. just just below the update for your cursors ask if active count is <= maxSize and then continue with your creation this.magBal = this.bullets.countActive(); if(this.fireButton.isDown && time > this.lastFired){ if(this.magBal < this.magSize){ console.log("fire button down"); let bullet = this.bullets.get(); if (bullet){ bullet.fireWeapon(this.x, this.y); this.lastFired = time + 100; } } } just as a tester rather than creating elements to collect as this is as easy as updating the registry data simply set a key to add 1 every time its pushed and you will see the bullet fire with the magSize. Later on something i can see that would be good is to change the fire rate and speed depending on the magSize or even add a reload function Link to comment Share on other sites More sharing options...
Recommended Posts