Button Problems

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
AlexL
Posts: 184
Joined: Tue Mar 02, 2004 6:06 pm
Location: Washington State

Button Problems

Post by AlexL »

I've been having even more problems Image Though some of the past problems where figured out on my own, but I'm stuck on this one... I have created a button and an event for when the button is pushed, and it compiles just fine, but when I run the program and click on the button nothing happens at all Image

Would anyone mind taking the time to help me on this problem?
---

Code: Select all

guienv -> addButton(rect<s32>(10,10,60,35), 0, 101, L"Exit Demo");

Code: Select all

bool RBGame::OnEvent(SEvent event)
{
	if (event.EventType == EET_GUI_EVENT)
	{
		s32 id = event.GUIEvent.Caller->getID();
		switch(id)
		{
		case 101:
			if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED)
			{
				device -> closeDevice();
			}
		}
	}
	return false;
}
flyingsaucer

Post by flyingsaucer »

is your class RBGame declared as an IEventReceiver??....did you write "this" for the receiver in your createDevice - call???
AlexL
Posts: 184
Joined: Tue Mar 02, 2004 6:06 pm
Location: Washington State

Post by AlexL »

See Below
AlexL
Posts: 184
Joined: Tue Mar 02, 2004 6:06 pm
Location: Washington State

Post by AlexL »

I've decided to post all of the code for the project since that might make it easier for the problem to be solved. Thanks in advance.
---
Main.cpp

Code: Select all

//--------------------------------------------------
// RollerBall! © 2004, Alexander M. Loren
// Created: March 1, 2004
//--------------------------------------------------
// Included Headers
//--------------------------------------------------
#include <irrlicht.h> // Rendering Engine
#include <audiere.h> // Audio Engine
#include <windows.h>
#include <stdio.h>
#include "rb_game.h"

//--------------------------------------------------
// Included Libs
//--------------------------------------------------
#pragma comment(lib, "Irrlicht.lib") // Rendering Engine
#pragma comment(lib, "audiere.lib") // Audio Engine

//--------------------------------------------------
// Namespaces
//--------------------------------------------------
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
using namespace audiere;

//--------------------------------------------------
// Window Function
//--------------------------------------------------
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
{
	video::EDriverType driverType = video::EDT_DIRECTX9;

	RBGame gameInstance;
	gameInstance.intMenu();

	return 0;
}
Rb_game.h

Code: Select all

//--------------------------------------------------
// RollerBall! © 2004, Alexander M. Loren
// Created: March 1, 2004
//--------------------------------------------------
// Included Headers
//--------------------------------------------------
#include <irrlicht.h> // Rendering Engine
#include <audiere.h> // Audio Engine
#include <windows.h>

//--------------------------------------------------
// Included Libs
//--------------------------------------------------
#pragma comment(lib, "Irrlicht.lib") // Rendering Engine
#pragma comment(lib, "audiere.lib") // Audio Engine

//--------------------------------------------------
// Namespaces
//--------------------------------------------------
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
using namespace audiere;

//--------------------------------------------------
// Game Class
//--------------------------------------------------
class RBGame : public IEventReceiver
{
public:
	void intGame();
	void intMenu();
	void intAudio();

private:
	IGUIButton* exitButton;
	AudioDevicePtr audiereDevice;
};

//--------------------------------------------------
// Event Class
//--------------------------------------------------
class RBEventReceiver : public IEventReceiver
{
public:
	virtual bool OnEvent(SEvent event)
	{
		if (event.EventType == EET_GUI_EVENT)
		{
			s32 id = event.GUIEvent.Caller->getID();
			switch(id)
			{
			case 101:
				if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED)
				{
					device -> closeDevice();
				}
			}
		}
		return false;
	}

private:
	IrrlichtDevice *device;
};
Rb_game.cpp

Code: Select all

//--------------------------------------------------
// RollerBall! © 2004, Alexander M. Loren
// Created: March 1, 2004
//--------------------------------------------------
// Included Headers
//--------------------------------------------------
#include <stdio.h>
#include "rb_game.h"

//--------------------------------------------------
// Game Run
//--------------------------------------------------
void RBGame::intGame()
{
	IrrlichtDevice* device = createDevice(video::EDT_DIRECTX9, dimension2d<s32>(800,600), 16, false, true, 0);
	video::IVideoDriver* driver = device -> getVideoDriver();
	scene::ISceneManager* smgr = device -> getSceneManager();
	gui::IGUIEnvironment* guienv = device -> getGUIEnvironment();

	//--------------------------------------------------
	// Device Setup
	//--------------------------------------------------
	device -> setWindowCaption(L"RollerBall - v.0.1");
	device -> getFileSystem() -> addZipFileArchive("./data.rar"); // onRelease: addZipFileArchive("./data.dat");


	//--------------------------------------------------
	// Interface Setup
	//--------------------------------------------------
	IGUIImage* score_img = guienv -> addImage(rect<int>(10,10,253,83));
	IGUIImage* time_img = guienv -> addImage(rect<int>(10,93,253,83));
	score_img -> setImage(driver -> getTexture("score.bmp"));
	time_img -> setImage(driver -> getTexture("time.bmp"));

	//--------------------------------------------------
	// Render Loop
	//--------------------------------------------------
	while(device->run())
	{
		driver -> beginScene(true, true, SColor(100,100,100,100));
		smgr -> drawAll();
		guienv -> drawAll();
		driver -> endScene();
	}
	device -> drop();
}

//--------------------------------------------------
// Game Menu
//--------------------------------------------------
void RBGame::intMenu()
{
	RBEventReceiver receiver;

	IrrlichtDevice* device = createDevice(video::EDT_DIRECTX9, dimension2d<s32>(800,600), 16, false, true, 0);
	video::IVideoDriver* driver = device -> getVideoDriver();
	scene::ISceneManager* smgr = device -> getSceneManager();
	gui::IGUIEnvironment* guienv = device -> getGUIEnvironment();

	//--------------------------------------------------
	// Device Setup
	//--------------------------------------------------
	device -> setWindowCaption(L"RollerBall - v.0.1");
	device -> getFileSystem() -> addZipFileArchive("./data.rar"); // onRelease: addZipFileArchive("./data.dat");

	//--------------------------------------------------
	// Interface Setup
	//--------------------------------------------------
	exitButton = guienv -> addButton(rect<s32>(10,10,60,35), 0, 101, L"Exit Demo");

	//--------------------------------------------------
	// Render Loop
	//--------------------------------------------------
	while(device->run())
	{
		driver -> beginScene(true, true, SColor(100,100,100,100));
		smgr -> drawAll();
		guienv -> drawAll();
		driver -> endScene();
	}
	device -> drop();
}

//--------------------------------------------------
// Audio Setup
//--------------------------------------------------
void RBGame::intAudio()
{
	audiereDevice = OpenDevice();
	if (!audiereDevice) 
		return;
}
Ronin
Posts: 116
Joined: Wed Mar 03, 2004 6:23 pm
Location: Germany

Post by Ronin »

Hi,

when you call createDevice you have to use a pointer to your EventReceiver as last parameter or use setEventReceiver instead. I think you forgot this.

Just make an EventReceiver with

Code: Select all

RBEventReceiver receiver;
and initialize your device with

Code: Select all

IrrlichtDevice* device = createDevice(video::EDT_DIRECTX9, dimension2d<s32>(800,600), 16, false, true, &receiver);
That should work.

Ronin
Post Reply