Mouse Events???
-
- Posts: 42
- Joined: Sun Nov 16, 2008 11:23 pm
- Location: Melbourne, Australia
- Contact:
Mouse Events???
I'm having a bit of trouble with mouse events, i did a search and got this http://irrlicht.sourceforge.net/phpBB2/ ... lick+event but im still confused with what i have to do to get the reciever working.
all i want to be able to do is draw a sprite at x, y when left is pressed..
All help is appreciated.[/code]
all i want to be able to do is draw a sprite at x, y when left is pressed..
All help is appreciated.[/code]
You need to write a class that is derived from IEventReceiver and implements OnEvent(). In the OnEvent() function, you look for left mouse button presses. When the left mouse button is pressed down you create a sprite and place it as needed.
Sometime after the IrrlichtDevice has been created, you create an instance of your event receiver, and pass it to the device with a call to setEventReceiver().
Travis
Sometime after the IrrlichtDevice has been created, you create an instance of your event receiver, and pass it to the device with a call to setEventReceiver().
Travis
-
- Posts: 42
- Joined: Sun Nov 16, 2008 11:23 pm
- Location: Melbourne, Australia
- Contact:
i had tried that by using this code as the event reciever
but it kept getting errors, and i did try to fix it for mouse events with what was provided in the topic but still didnt work...
Code: Select all
class MyEventReceiver1 : public IEventReceiver
{
public:
virtual bool OnEvent(const SEvent& event)
{
if (event.EventType == irr::EET_KEY_INPUT_EVENT)
KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
else if (event.EventType == EET_MOUSE_INPUT_EVENT)
KeyIsDown[event.MouseInput.Event] = event.MouseInput.Event;
return false;
}
virtual bool IsKeyDown(EKEY_CODE keyCode) const
{
return KeyIsDown[keyCode];
}
MyEventReceiver1()
{
for (int i=0; i<KEY_KEY_CODES_COUNT; ++i)
KeyIsDown[i] = false;
}
private:
bool KeyIsDown[KEY_KEY_CODES_COUNT];
};
-
- Posts: 362
- Joined: Sun Dec 16, 2007 9:25 pm
MastEventReceiver is great: http://irrlicht.sourceforge.net/phpBB2/ ... 57&start=0
Post this userbar I made on other websites to show your support for Irrlicht!
http://img147.imageshack.us/img147/1261 ... wernq4.png
http://img147.imageshack.us/img147/1261 ... wernq4.png
First, if you had attempted to fix the code according to what I posted in the other thread, then I'd expect you'd have something differrent than the original poster. Second, why would you copy code that you know doesn't work?
Regardless, if you're just trying to find out when the left mouse button is pressed, why do you need the key state array? Why not just simplify your code down to something that you can manage, and then make it more complicated as you learn?
How about you start with this...
Try that on for size. See if you can get it to compile and if it will receive an event. Once that is working, show us the code you think you'd have to write to detect a left mouse button press. Then, when you've successfully detected a left button press, you'll need to write some code to generate your 'sprite', or maybe just move it.
Hint: Everything you need to know is in IEventReceiver.h and on these forums.
Hint: Search the forums for IEventReceiver and EMIE_LMOUSE_PRESSED_DOWN.
Travis
Regardless, if you're just trying to find out when the left mouse button is pressed, why do you need the key state array? Why not just simplify your code down to something that you can manage, and then make it more complicated as you learn?
How about you start with this...
Code: Select all
#include <stdio.h>
class MyEventReceiver1 : public IEventReceiver
{
public:
MyEventReceiver1()
{
}
virtual bool OnEvent(const SEvent& event)
{
printf ("hello world\n");
return false;
}
};
Hint: Everything you need to know is in IEventReceiver.h and on these forums.
Hint: Search the forums for IEventReceiver and EMIE_LMOUSE_PRESSED_DOWN.
Travis
-
- Posts: 42
- Joined: Sun Nov 16, 2008 11:23 pm
- Location: Melbourne, Australia
- Contact:
-
- Posts: 42
- Joined: Sun Nov 16, 2008 11:23 pm
- Location: Melbourne, Australia
- Contact:
vitek i looked at that little snippet and i have tried to compile it, but dont know what to do with it and i get errors.
i dont know what im supposed to do with it
Code: Select all
1>c:\users\jason\desktop\irrdemos\eventtest\eventtest\main.cpp(4) : error C2504: 'IEventReceiver' : base class undefined
1>c:\users\jason\desktop\irrdemos\eventtest\eventtest\main.cpp(10) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\jason\desktop\irrdemos\eventtest\eventtest\main.cpp(10) : error C2143: syntax error : missing ',' before '&'
1>Build log was saved at "file://c:\Users\Jason\Desktop\IrrDemos\eventtest\eventtest\Debug\BuildLog.htm"
1>eventtest - 3 error(s), 0 warning(s)
Everything in Irrlicht, including the class IEventReceiver, are in the namespace irr. You either need to explicitly qualify it (i.e., you write irr::IEventReceiver), or you need to bring the namespace in with using namespace irr;.
I'm making the assumption that you are using one of the example programs as a starting point. If you were, the code would have compiled without error.
Travis
I'm making the assumption that you are using one of the example programs as a starting point. If you were, the code would have compiled without error.
Travis
-
- Posts: 42
- Joined: Sun Nov 16, 2008 11:23 pm
- Location: Melbourne, Australia
- Contact:
i got that code you gave me to compile without any errors, but i dont know what direction this is taking me..
Code: Select all
#include <Irrlicht.h>
#include <stdio.h>
#pragma comment(lib, "Irrlicht.lib")
using namespace irr;
class MyEventReceiver1 : public IEventReceiver
{
public:
MyEventReceiver1()
{
}
virtual bool OnEvent(const SEvent& event)
{
printf ("hello world\n");
return false;
}
};
int main()
{
printf ("hi\n");
system("pause");
return 0;
}
all Irrlicht events are send to the onEvent() function first...lucifer1101 wrote:i got that code you gave me to compile without any errors, but i dont know what direction this is taking me..
there you can check the event and act on it...
if the event is finished, then return true,
and if Irrlicht shall also handle the event return false
Tutorials #04-Movement and #05-UserInterface are good references...
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
It is taking you toward a solution. One that you implement on your own instead of having handed to you. You're doing good so far. Just be patient. This may take some time, but by the time you're done, you'll hopefully understand how to learn to use things on your own. This will allow you to work more independently.lucifer1101 wrote:i got that code you gave me to compile without any errors, but i dont know what direction this is taking me..
So the code that you've posted compiles. Awesome. So lets add more code to make it actually do something. The first thing you need to do in an Irrlicht app is to create an IrrlichtDevice. You need to do this. Then you need to create an instance of your event receiver, and register it with the device.
All of the above is very easy. It is covered in several of the example programs. Again, if you search for IEventReceiver and EMIE_LMOUSE_PRESSED_DOWN, you might find some relevant topics.
Travis