Array of types vs collection of types
BlitzPlus Forums/BlitzPlus Programming/Array of types vs collection of types
| ||
Do you ever find that 'sometimes' its better to have an array of types instead of a collection of types? An array of types allows you to access any type with out going through the whole for each loop. Maybe I'm missing something, and I could accomplish what I want without using the array. |
| ||
I used arrays of types when I needed to reach several exact positions. |
| ||
Each has its own strengths and you should use whatever is appropriate for the job. If I have a tilebased game and I need each tile to hold certain details I would make the tile itself a type but I would create a 2d array to hold the tiles because I will need to access specific tiles based on an x,y position. In the same game the enemies are spawned from spawn gates. These I can just define as an enemy type and just use the type collection for accessing them because I never need to access specific enemies. My code will always act upon the whole collection when moving, checking for collisions etc. |
| ||
Arrays of types are definitely the best way in some cases, there's nothing "wrong" with using them (if you use the right code for the jod). |