I need to store elements in a multidimensional array. Specifically, I need to save “tiles” to a grid (e.g. Grass at x:2 y:5, Dirt at x:3 y:5, etc.). Using a multidimensional feels very hacked up and is very glitchy (having to resize my arrays and having to create new ones were they are non-existant). Is there some kind of element made for this? Something I can say obj.getPos(2,5) and get my Grass Element and use obj.setPos(DirtObj, 3, 5) to set it to my Dirt Element?
I’m just wondering if there is something easier to use than multidimensional arrays in vb.net, that is all. Thanks!
Option 1 – Class
If you’re going to be adding, removing and inserting objects, I would use a List of Lists since this will give you direct access to the object at a given coordinate (X, Y) and let you set the object directly without having to re-size them.
For example, you could have a
Tileclass and use the Lists like this:Option 2 – Enum
If all you’re using the objects for is their value you don’t even need to create a
Tileclass instead you could just create aTileTypesenum with some values likeDirt,Grass, etc and set them:You should be able to build upon this and take it from there.