Jump to content

  • Log In with Google      Sign In   
  • Create Account

C++ - Passing array of textures through function


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Dynamite Andy   Members   -  Reputation: 119

Like
0Likes
Like

Posted 03 May 2013 - 03:04 AM

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?



Sponsor:

#2 Brother Bob   Moderators   -  Reputation: 8605

Like
3Likes
Like

Posted 03 May 2013 - 03:13 AM

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

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


#3 Dynamite Andy   Members   -  Reputation: 119

Like
0Likes
Like

Posted 03 May 2013 - 03:21 AM

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, 03 May 2013 - 03:25 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS