Sign in to follow this  
dynamiteandy

C++ - Passing array of textures through function

Recommended Posts

dynamiteandy    119

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[i].initialize(gamePtr,panelNS::WIDTH,gamePanel[i].getHeight(),ncols,textureM[gamePanel[i].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?

Share this post


Link to post
Share on other sites
Brother Bob    10344

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

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

Share this post


Link to post
Share on other sites
dynamiteandy    119

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[i].initialize(gamePtr,panelNS::WIDTH,gamePanel[i].getHeight(),ncols,textureM[gamePanel[i].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[i].ReturnColour()] with &textureM[gamePanel[i].ReturnColour()]

Edited by Dynamite Andy

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