Excalibur icon indicating copy to clipboard operation
Excalibur copied to clipboard

Feature request: Custom arguments in Pool's builder func

Open keasy9 opened this issue 2 months ago • 3 comments

First, thank you for really convinent api and many usefull features!

Context

I'm making simple galaxy shooter game with exalibur, where enemies have different textures, based on a parameter in constructor (just a Enum). And I wanna use pool for enemies, so I need to be able change texture type of enemy when getting it from pool.

Proposal

This is possible now like these:

pool.get().setType(EnemyType.Rocket)

but it will more convenient if I could do somethhing like these:

pool.get(EnemyType.Rocket)

keasy9 avatar Oct 25 '25 05:10 keasy9

I totally support this feature! It should be possible to extract the argument list type from the builder function. To avoid breaking existing stuff, would it be okay to add a new .getWithParameters(...builderParams)?

I'm making simple galaxy shooter game with exalibur, where enemies have different textures, based on a parameter in constructor (just a Enum). And I wanna use pool for enemies, so I need to be able change texture type of enemy when getting it from pool.

Also for your specific game, RentalPool might be better since that one assumes objects live for a long time, Pool assumes objects are short lived and reclaimed all at once when .done() is called.

eonarheim avatar Oct 27 '25 13:10 eonarheim

Yes, but I think that .getWithParameters name is too long for convenient use, maybe .getWithParams(...builderParams) or even .getWith(...builderParams)? However, naming is up to you.

And thanks for good advice about RentalPool!

keasy9 avatar Oct 31 '25 03:10 keasy9

Oh I like .getWith(...)!

eonarheim avatar Nov 16 '25 14:11 eonarheim