Advertisement

Dynamically allocating Map Arrays

Started by May 18, 2001 05:00 PM
1 comment, last by Citan 23 years, 8 months ago
Hello, I apologize in advance if this question is asked frequently. I want load a map of arbitrary dimensions from a file but I am having problems dynamically allocating a two-dimensional array.I have read the article hear at GameDev entitled "Dynamic Tile Maps 1.0" by Lee French and I tried using the code but i was getting an invalid page fualt error in the part where the array is accessed. I was hoping that somebody could give me some insight on how do go about allocating this memory. Thank You.
personally, in that scenario, i fake it.

class CMapSquare{    /*declarations for whatever    an individual map square contains*/};class CMap{private:    int m_iWidth;    int m_iHeight;    CMapSquare* m_pMapSquares;public:    CMap(int iWidth,int iHeight);    ~CMap();    CMapSquare* GetSquare(int x,int y);    int GetWidth(){return(m_iWidth);}    int GetHeight(){return(m_iHeight);}};CMap::CMap(int iWidth,int iHeight){    m_iWidth=iWidth;    m_iHeight=iHeight;    m_pMapSquares=new CMapSquares[m_iWidth*m_iHeight];}CMap::~CMap(){    delete [] m_pMapSquares;}CMapSquare* CMap::GetSquare(int x,int y){    return(m_pMapSquares[x+y*GetWidth()]);}

Get off my lawn!

Advertisement
Thank You very much for the quick and informative response. I would not have thought of doing it that way in a million years.

This topic is closed to new replies.

Advertisement