Getting entities from buckets

To get access to all entities in a bucket, use the global function GetEntitiesFromBucket:

ETHEntityArray bucketArray;

GetEntitiesFromBucket(vector2(1,1), bucketArray); for (uint t = 0; t < bucketArray.Size(); t++) { bucketArray[t].SetColor(newColor); }

In the example above, we fill the array with all entities on bucket (1,1) and set a custom color to them.

It is also possible to hold two or more buckets in a single array by using the appending += operator:

ETHEntityArray bucketArray;
GetEntitiesFromBucket(vector2(1,1), bucketArray);

ETHEntityArray otherArray;
GetEntitiesFromBucket(vector2(1,2), otherArray);

bucketArray += otherArray;

otherArray.Clear();

bucketArray will now hold all entities in the buckets (1,1) and (1,2).

The global function GetBucket may be used to easily find out to which bucket a point in space belongs:

ETHEntityArray bucketArray;
const vector2 monsterBucket = GetBucket(monster.GetPositionXY());
GetEntitiesFromBucket(monsterBucket, bucketArray);

Or you can use the ETHEntity::GetCurrentBucket method to quickly find which bucket holds the entity:

ETHEntityArray bucketArray;
const vector2 bucket = monster.GetCurrentBucket();
GetEntitiesFromBucket(bucket, bucketArray);