Jump to content
  • Advertisement
Sign in to follow this  

Irrlicht Event Receiver

This topic is 4436 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Sigh I have this code, but my keys aren't doing anything...
#include <iostream>
#include <irrlicht.h>

using namespace std;
using namespace irr;
using namespace video;
using namespace core;
using namespace io;
using namespace scene;

#pragma comment(lib, "Irrlicht.lib")

int ballX = 25;
int	ballY = 25;
int barX = 22;
int barY = 48;
ISceneNode *node = 0;

class MyEventReceiver : public IEventReceiver
{
public:
	virtual bool OnEvent(SEvent event)
	{
		/*
		If the key 'W' or 'S' was left up, we get the position of the scene node,
		and modify the Y coordinate a little bit. So if you press 'W', the node
		moves up, and if you press 'S' it moves down.
		*/

		if (node != 0 && event.EventType == irr::EET_KEY_INPUT_EVENT&&
			!event.KeyInput.PressedDown)
		{
			switch(event.KeyInput.Key)
			{
			case KEY_RIGHT:
				{
					barX = barX + 1;
				}
			case KEY_LEFT:
				{
					barX = barX - 1;
				}
				return true;
			}
		}

		return false;
	}
};


int main()
{

	MyEventReceiver events;

	// Setup the device
	IrrlichtDevice *device = createDevice(EDT_OPENGL, dimension2d<s32>(50,50),8,false,false,false, &events);
	// Get the video Driver
	IVideoDriver *driver = device->getVideoDriver();
	// Window Caption
	device->setWindowCaption(L"Break Da Pixels");
	// Get images
	ITexture *ball = driver->getTexture("./graphics/ball.bmp");
	ITexture *bar = driver->getTexture("./graphics/bar.bmp");

	// Variables
	bool keys[2]; // For the keys



	// Game Loop
	while(device->run() && driver)
	{
		if(device->isWindowActive())
		{
			driver->beginScene(true,true,SColor(0,0,0,0));
				driver->draw2DImage(ball,position2d<s32>(ballX,ballY),rect<s32>(0,0,1,1));
				driver->draw2DImage(bar,position2d<s32>(barX,barY),rect<s32>(0,0,5,1));		
			driver->endScene();

		}
	}
	device->drop();
	return 0;
}


Share this post


Link to post
Share on other sites
Advertisement
Well, with your setup, you have that global variable "node", right? And in your event message deal, one of your conditions is "if(node != 0)", and by looking at the code you've provided, node is never used anywhere else or set or anything, so node is zero when it comes around to your if statement, which is probably the problem.

Share this post


Link to post
Share on other sites
Ok, that fixed it. Thanks.

I have another couple of problems tho. When I press the right key, the bar doesn't move at all. Also, any Irrlicht Gurus know how to make it so you can hold down the key and it'll keep moving? Thanks!

Share this post


Link to post
Share on other sites
Aha, ok. Thanks :P I guess I'm not as good at c++ as I first tought :P

EDIT: I fixed my being able to hold the key down. Thanks!

[Edited by - Mr_Fhqwhgads on March 29, 2006 12:11:21 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!