Hi there,

My friend and I are making a game, which is based on a tile engine we are making. The map is loaded into an array of integers to represent each different tile. However, in the map class, we need the variable data to hold the integer array so we can access it like this: MAP level1; x = level1.data[0][0];. The problem is that we can't make the int array until we know the size (no vector replies please). The size is stored in level1.size during the function MAP::Load(). Can we do one of the following:

  1. Initialize data in the MAP::Load() function, BUT have it public, so it can be accessed from outside using level1.data[0][0] for example.
  2. Initialize data in the public section of the MAP class, then make the function MAP::Load() return the 2D int array to it.
  3. Do something else without vectors to the same effect.

Recommended Answers

All 2 Replies

Why would you want the data explosed to the outside? Use a get method to expose the location.

If you want to see the value of location 0,0, return the location with
val = level1.getMapLoc(0,0);

Thanks very much - neither of us thought of that!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.