Sign in to follow this  
bschneid

how to access my array-ed data members

Recommended Posts

This problem came up when I was working on a new 2d tiled game. I have a class called Tile. Tile has a variable called "type" which defines the sort of tile to be drawn (grass, dirt, etc). I then have a class called Map which stores an array of Tiles. The problem arises when I try to define the map by giving different tiles different values so that there are different types of terrain. I need to know how to set the "type" values for Tile. I know I can access them like Map.ArrayOfTiles[x][y].Type = whatever, but is it possible to define them all at once like you would an array (like this: {1,2,3,4})? I know that's not very clear, but I hope you understand. I can try to explain more if needed.

Share this post


Link to post
Share on other sites
I don't believe so, or at least it won't be very easy with big maps. It would be best to either load the information from a file, or to generate it with a loop or two.

You can only go like so array[5]={1,2,3,4,5} when array[] is declared, and since you cannot assign member data a value in the same line it is created, I don't believe that you can do this.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this