C++ - Passing array of textures through function

Started by
1 comment, last by dynamiteandy 10 years, 11 months ago

Hi, So in my game I've been working on all morning I've decided to create a class that will manage the multiple panels in my game.

Before this I was originally just making the panels in the game loop.

So anyways in my game.cpp file I have texture array which has all the textures for the panels.


TextureManager panelTexture[22];

Is what it is. This was initalised calling the function initalize with the following parameters, the panel had a variety of sizes and colours. hence the two functions inside of it.


if(!gamePanel.initialize(this,paddleNS::WIDTH,gamePanel.ReturnSize(),0,&panelTexture[gamePanel.ReturnColour()]))
		throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing player paddle"));

because i've now decided to use this manager class the function will now need to pass the panelTexture array to the panel manager class. Like so?


// Panelmanager.h
virtual bool initialize(Game *gamePtr, int width, int height, int ncols,
                            TextureManager *textureM[]);
// Panelmanager.cpp
bool panelManager::initialize(Game *gamePtr, int width, int height, int ncols,
                            TextureManager *textureM[])
{
    for (int i = 0; i < MAX_PANELS; i++)
    {
        gamePanel.initialize(gamePtr,panelNS::WIDTH,gamePanel.getHeight(),ncols,textureM[gamePanel.ReturnColour()]);
    }
}

So i am now able to call the panelmanager initalize function to initalize the game panels., however im having problems with this.


if(!gamePanels.initialize(this,0,0,0,&panelTexture))
		throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing player paddle"));

I cant seem the pass the array, when i try &panelTexture i get the following error


	1	IntelliSense: argument of type "TextureManager (*)[22]" is incompatible with parameter of type "TextureManager **"	

when i try &panelTexture[] i get this error


	1	IntelliSense: expected an expression

Basically I am stumped with errors at this bit, Could anyone advise on how to get past this?

Advertisement

The function should take a pointer, and you pass the array as it is.

virtual bool initialize(..., TextureManager *textureM);
...
if(!gamePanels.initialize(..., panelTexture))

The function should take a pointer, and you pass the array as it is.


virtual bool initialize(..., TextureManager *textureM);
...
if(!gamePanels.initialize(..., panelTexture))

That fixed that bit, but now i face this problem in panelManager intialize.


bool panelManager::initialize(Game *gamePtr, int width, int height, int ncols,
                            TextureManager *textureM)
{
	for (int i = 0; i < MAX_PANELS; i++)
	{
		gamePanel.initialize(gamePtr,panelNS::WIDTH,gamePanel.getHeight(),ncols,textureM[gamePanel.ReturnColour()]);
	}
}

	1	IntelliSense: invalid destructor declaration
	2	IntelliSense: no suitable conversion function from "TextureManager" to "TextureManager *" exists

Edit: Think i got it, replaced textureM[gamePanel.ReturnColour()] with &textureM[gamePanel.ReturnColour()]

This topic is closed to new replies.

Advertisement