Ashaira
Member
|
Using class methods on button press
i made a class for the main menu by separating the elements into different methods. The program works and the menu gets rendered but when i try to attach a function which is a member of the same class to one of the buttons like in the tutorial
(
Code:
window+=exitButton.create(Rect( 1.2f, -1.53f, 2.0f, -1.3f),"").func(Exit);
)
i get different access errors. ('CMainMenu::Exit': function call missing argument list; use '&CMainMenu::Exit' to create a pointer to member)
When i correct the code like the error says i get a parameter conversion error. So how would i go about putting a method of that class into the button code?
EDIT: forgot to mention that the button code is in the constructor of the class its in.
EDIT2: found a way around the problem but i would still like to know how to access the methods (or declare them if that is the real problem)
(This post was last modified: 05-02-2011 11:05 AM by Ashaira.)
|
|
05-02-2011 06:32 AM |
|
Dandruff
Member
|
RE: Using class methods on button press
T.Exit()?
|
|
05-02-2011 07:06 AM |
|
Seba
Member
|
RE: Using class methods on button press
Quote:exitButton.func(Exit);
|
|
05-02-2011 08:40 AM |
|
Esenthel
Administrator
|
RE: Using class methods on button press
Methods for func must be static
|
|
05-02-2011 09:57 AM |
|
Ashaira
Member
|
RE: Using class methods on button press
i tried what both of u said and i get the same error. this is how the class code looks maybe it will help.
Code:
#include "StdAfx.h"
#include "MainMenu.h"
CMainMenu::CMainMenu()
{
Gui +=window.create(Rect(-1.625f , -1.025f , 1.625f , 1.1f),"MainMenu"); // create window and add it to Gui desktop
//window+=text .create(Vec2( 0.5f , -0.15f ),"text" ); // create text and add it to 'window', coordinates are relative to parent (its top left corner)
window+=arcadeButton.create(Rect( 1.2f, -0.53f, 2.0f, -0.3f),""); // create button and add it to 'window', coordinates are relative to parent (its top left corner)
window+=versusButton.create(Rect( 1.2f, -1.03f, 2.0f, -0.8f),"");
window+=exitButton.create(Rect( 1.2f, -1.53f, 2.0f, -1.3f),"");
arcadeButton.image=Images("../Tutorials/Pics/arcade.gfx");
versusButton.image=Images("../Tutorials/Pics/versus.gfx");
exitButton.image=Images("../Tutorials/Pics/exit.gfx");
Gui.style_window.image_back =Images("../Tutorials/Pics/mainmenu bg.gfx");
Gui.style_window.back_color =WHITE;
Gui.style_window.border_width=0.01f;
}
CMainMenu::~CMainMenu(void)
{
}
void
CMainMenu::Update()
{
Gui.update(); // update GUI
}
void
CMainMenu::Draw()
{
Gui.draw(); // update GUI
}
void
CMainMenu::Exit()
{
exit = true;
}
This is the cpp not the header.
(05-02-2011 09:57 AM)Esenthel Wrote: Methods for func must be static
sry didn't see ur post. i just tried making a static func but it still gives me the same error even with the static function.
(This post was last modified: 05-02-2011 10:32 AM by Ashaira.)
|
|
05-02-2011 10:27 AM |
|
Harry
Member
|
RE: Using class methods on button press
Did you try that?
Code:
static void func(Ptr)
{
Exit();
};
window+=exitButton.create(Rect( 1.2f, -1.53f, 2.0f, -1.3f),"").func(func);
or in Update (it should work):
Code:
if(exitButton())Exit();
|
|
05-02-2011 11:33 AM |
|
Ashaira
Member
|
RE: Using class methods on button press
(05-02-2011 11:33 AM)Harry Wrote: Did you try that?
Code:
static void func(Ptr)
{
Exit();
};
window+=exitButton.create(Rect( 1.2f, -1.53f, 2.0f, -1.3f),"").func(func);
or in Update (it should work):
Code:
if(exitButton())Exit();
yeah i ended up using the second one. still dont get how the accessing of func works when using the first option but thnx.
|
|
05-02-2011 01:09 PM |
|
Seba
Member
|
RE: Using class methods on button press
Look into:
Quote:07 - Game Menu.cpp
|
|
05-02-2011 02:01 PM |
|