I'm having trouble trying to access an array used in my main class from another class. My application is an editor for making a 2d platform game - it basically allows you to place down 2D assets (segments) and build up a level.
My main class handles an array of map segment classes (each segment class in the array holds information such as position, scale and rotation of the segment on the map) and draws them to screen.
I have a separate class which is basically a panel (dragabble, and resizable like you would find in something like Photoshop) that is initialised in the main class and is used to draw a grid of available segments from a file. What I need is the ability to click on one of the segments which then adds information to the array that is referenced in the main class.
I have my main class "Map" which declares an array:
map.h (simplified)
class Map
{
public:
MapSegment* mapSeg[512];
};
I'm then trying to send a reference of that array when I create the panel to display the available segments, like so:
Panel* segmentPane = new SegmentPanel(sf::Rect<float>(200,200,250,200), mapSeg);
Segment Panel header is formed as follows:
class SegmentPanel : public Panel
{
public:
SegmentPanel(sf::Rect<float> _position, MapSegment* mapSeg[512];);
void Update();
void Draw(sf::RenderWindow & renderWindow);
void ReadSegments();
private:
std::vector<SegmentDefinition *> segDef;
MapSegment* mapSeg[512];
};
And SegmentPanel cpp:
SegmentPanel::SegmentPanel(sf::Rect<float> _position, MapSegment* mapSeg[512])
: Panel(_position)
{
panelTitle = "Segment Selection";
}
void SegmentPanel::Update()
{
// Update segments
}
void SegmentPanel::Draw(sf::RenderWindow & renderWindow)
{
// Draw default panel items
Panel::Draw(renderWindow);
// Draw segments
}
However, add elements to the array from SegmentPanel.cpp class doesn't seem to be reflected in my main Main class - it seems to create a new array in memory.
I'm still fairly new to C++ after working with C#!