Is creating a separate pool for each individual image created from a png appropriate?
- by Panzercrisis
I'm still possibly a little green about object-pooling, and I want to make sure something like this is a sound design pattern before really embarking upon it. Take the following code (which uses the Starling framework in ActionScript 3):
[Embed(source = "/../assets/images/game/misc/red_door.png")]
private const RED_DOOR:Class;
private const RED_DOOR_TEXTURE:Texture = Texture.fromBitmap(new RED_DOOR());
private const m_vRedDoorPool:Vector.<Image> = new Vector.<Image>(50, true);
.
.
.
public function produceRedDoor():Image
{
// get a Red Door image
}
public function retireRedDoor(pImage:Image):void
{
// retire a Red Door Image
}
Except that there are four colors: red, green, blue, and yellow. So now we have a separate pool for each color, a separate produce function for each color, and a separate retire function for each color. Additionally there are several items in the game that follow this 4-color pattern, so for each of them, we have four pools, four produce functions, and four retire functions.
There are more colors involved in the images themselves than just their predominant one, so trying to throw all the doors, for instance, in a single pool, and then changing their color properties around isn't going to work. Also the nonexistence of the static keyword is due to its slowness in AS3.
Is this the right way to do things?