Welcome! Log In Create A New Profile

Advanced

objects help

Posted by g_man 
objects help
December 28, 2009 05:56AM
I'm trying to create an object that would allow me to easily create buttons in libwiisprite, but i'm having some problems.
Here is my code:
enum BUTTON_COLOR{WHITE,RED,BLUE,CYAN,GREEN};

class button{
	public:
	
	void setMessage(char* m){
		strcpy(msg,m);
	}
	char* getMessage(){
		return msg;
	}

	void setLocation(int X,int Y){
		x=X;
		y=Y;
	}

	int getX(){
		return x;
	}

	int getY(){
		return y;
	}	
	
	void setDim(int w,int h){
		width = w;
		height = h;
	}

	int getWidth(){
		return width;
	}

	int getHeight(){
		return height;
	}	
	
	void setColor(BUTTON_COLOR c){
		color = c;
	}

	BUTTON_COLOR getColor(){
		return color;
	}

	void genImage();
	void buttonDraw();
	
	private:
	int x,y;
	int width;
	int height;
	char* msg;
	BUTTON_COLOR color;
	image buttonImg;
	sprite buttonSpr;
};

void button::genImage(){
	switch (color)
	{
		case WHITE:
			button::buttonImg.LoadImage(buttonWhite_png);
			break;
		case RED:
			button::buttonImg.LoadImage(buttonRed_png);
			break;
		case BLUE:
			button::buttonImg.LoadImage(buttonBlue_png);
			break;
		case CYAN:
			button::buttonImg.LoadImage(buttonCyan_png);
			break;
		case GREEN:
			button::buttonImg.LoadImage(buttonGreen_png);
			break;
	
	}
	button::buttonSpr.SetImage(buttonImg);
	button::buttonSpr.SetStrechWidth(width/31);
	button::buttonSpr.SetStrechHeight(height/31);
}
void button::buttonDraw(){
	button::buttonSpr.Draw(x,y);
}
I'm not finished yet, but i wanted to see if my code actually compiled, and it didn't. I've probably got some stupid error that i can't see.
the errors are:
f:/homebrew/buttonTest/source/template.cpp:80: error: 'image' does not name a type
f:/homebrew/buttonTest/source/template.cpp:81: error: 'sprite' does not name a type
f:/homebrew/buttonTest/source/template.cpp: In member function 'void button::genImage()':
f:/homebrew/buttonTest/source/template.cpp:88: error: 'buttonImg' is not a member of 'button'
f:/homebrew/buttonTest/source/template.cpp:91: error: 'buttonImg' is not a member of 'button'
f:/homebrew/buttonTest/source/template.cpp:94: error: 'buttonImg' is not a member of 'button'
f:/homebrew/buttonTest/source/template.cpp:97: error: 'buttonImg' is not a member of 'button'
f:/homebrew/buttonTest/source/template.cpp:100: error: 'buttonImg' is not a member of 'button'
f:/homebrew/buttonTest/source/template.cpp:104: error: 'buttonSpr' is not a member of 'button'
f:/homebrew/buttonTest/source/template.cpp:104: error: 'buttonImg' was not declared in this scope
f:/homebrew/buttonTest/source/template.cpp:105: error: 'buttonSpr' is not a member of 'button'
f:/homebrew/buttonTest/source/template.cpp:106: error: 'buttonSpr' is not a member of 'button'
f:/homebrew/buttonTest/source/template.cpp: In member function 'void button::buttonDraw()':
f:/homebrew/buttonTest/source/template.cpp:109: error: 'buttonSpr' is not a member of 'button'

Also, does anybody know what enviromental variables are affected by the windows install of devkitpro? I'm asking because i'm trying to get it to work properly on my USB drive, and it only works on the computer I initially installed it on.
Re: objects help
December 28, 2009 01:39PM
These errors are all general C++ errors caused by typos in your code.

For example:
	image buttonImg;
	sprite buttonSpr;

Should be:
	Image buttonImg;
	Sprite buttonSpr;

And other silly things like that.
Re: objects help
December 28, 2009 07:47PM
Thanks, i hate stupid mistakes, but i think i have another one. While trying to create a LayerManager in my object, it stopped working. This time I'm 99% sure it isn't a typo, because i coppied it directly from the example, here is the line:
LayerManager manager(1);
Here are the errors:
:/homebrew/buttonTest/source/template.cpp:82: error: expected identifier before numeric constant
f:/homebrew/buttonTest/source/template.cpp:82: error: expected ',' or '...' before numeric constant
f:/homebrew/buttonTest/source/template.cpp: In member function 'void buttonObj::genButton()':
f:/homebrew/buttonTest/source/template.cpp:110: error: '((buttonObj*)this)->buttonObj::manager' does not have class type
f:/homebrew/buttonTest/source/template.cpp: In member function 'void buttonObj::buttonDraw()':
f:/homebrew/buttonTest/source/template.cpp:113: error: '((buttonObj*)this)->buttonObj::manager' does not have class type
I'm pretty sure that the last 2 errors are because of the LayerManager messing up.
Re: objects help
December 28, 2009 08:26PM
I'd need to see more then that one line to help you out.
Re: objects help
December 28, 2009 09:39PM
Ok, sorry about that, here is the whole object definition.
class buttonObj{
	public:
	
	void setMessage(char* m){
		strcpy(msg,m);
	}
	char* getMessage(){
		return msg;
	}

	void setLocation(int X,int Y){
		x=X;
		y=Y;
	}

	int getX(){
		return x;
	}

	int getY(){
		return y;
	}	
	
	void setDim(int w,int h){
		width = w;
		height = h;
	}

	int getWidth(){
		return width;
	}

	int getHeight(){
		return height;
	}	
	
	void setColor(BUTTON_COLOR c){
		color = c;
	}

	BUTTON_COLOR getColor(){
		return color;
	}

	void genButton();
	void buttonDraw();
	
	private:
	int x,y;
	int width;
	int height;
	char* msg;
	BUTTON_COLOR color;
	Image buttonImg;
	Sprite buttonSpr;
	LayerManager manager(1);
};
Re: objects help
December 28, 2009 09:52PM
Seems to be caused by you only prototype genButton() and buttonDraw() instead of clearly defining them like the rest of your functions. Even if you don't have the filler code written yet, just do this:

	void genButton(){ }
	void buttonDraw(){ }
Re: objects help
December 28, 2009 11:07PM
fixed it, kinda. Instead of supplying a LayerManager in the object, i made the user supply one. This way it is much more useful.
Sorry, only registered users may post in this forum.

Click here to login