How to get mouse click...[solved]
-
- Posts: 31
- Joined: Tue Apr 12, 2005 12:20 am
How to get mouse click...[solved]
Hi. I am appoligizing in the begging if this has already been answerd. I used the search first but didn't find anything.
What is the code for if the left mouse button is pressed then....
Thank you so much
What is the code for if the left mouse button is pressed then....
Thank you so much
Last edited by ViperGuy911 on Thu May 12, 2005 3:19 am, edited 1 time in total.
-
- Posts: 31
- Joined: Tue Apr 12, 2005 12:20 am
Okay. I have done some reading and I found out that is is with the EventReceiver. I set it up and guess what, theres a problem. Here's the code:
The errors given is:
Can you please tell me what I am doing wrong?
Thanks
Code: Select all
#include <irrlicht.h>
#include <iostream>
#include <audiere.h>
using namespace irr;
using namespace audiere;
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(lib, "audiere.lib")
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
//Mouse event
if (event.EventType == EMIE_LMOUSE_PRESSED_DOWN)
{
sound->setRepeat(false);
sound->setVolume(0.5f);
sound->play()
}
}
}
int main()
{
MyEventReceiver &receiver;
video::E_DRIVER_TYPE driverType;
printf("Please select the driver you want for this example:\n"\
" (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.2\n"\
" (d) Software Renderer\n (e) NullDevice\n (otherKey) exit\n\n");
.......and so on.
Code: Select all
--------------------Configuration: FPS - Win32 Debug--------------------
Compiling...
main.cpp
C:\Documents and Settings\Tigran\My Documents\C++ TUTS\FPS\main.cpp(27) : error C2628: 'MyEventReceiver' followed by 'int' is illegal (did you forget a ';'?)
C:\Documents and Settings\Tigran\My Documents\C++ TUTS\FPS\main.cpp(29) : error C2530: 'receiver' : references must be initialized
C:\Documents and Settings\Tigran\My Documents\C++ TUTS\FPS\main.cpp(50) : error C2664: '__thiscall MyEventReceiver::MyEventReceiver(const class MyEventReceiver &)' : cannot convert parameter 1 from 'const int' to 'const class MyEventReceiver &'
Reason: cannot convert from 'const int' to 'const class MyEventReceiver'
No constructor could take the source type, or constructor overload resolution was ambiguous
C:\Documents and Settings\Tigran\My Documents\C++ TUTS\FPS\main.cpp(59) : error C2664: '__thiscall MyEventReceiver::MyEventReceiver(const class MyEventReceiver &)' : cannot convert parameter 1 from 'const int' to 'const class MyEventReceiver &'
Reason: cannot convert from 'const int' to 'const class MyEventReceiver'
No constructor could take the source type, or constructor overload resolution was ambiguous
C:\Documents and Settings\Tigran\My Documents\C++ TUTS\FPS\main.cpp(171) : error C2664: '__thiscall MyEventReceiver::MyEventReceiver(const class MyEventReceiver &)' : cannot convert parameter 1 from 'const int' to 'const class MyEventReceiver &'
Reason: cannot convert from 'const int' to 'const class MyEventReceiver'
No constructor could take the source type, or constructor overload resolution was ambiguous
Error executing cl.exe.
main.obj - 5 error(s), 0 warning(s)
Thanks
Look at the error message:
So did you forget a ';'? Yes you did. You have to finish your class declaration with a semicolon (after the last '}' of class MyEventReceiver).
Also you better remove the '&' from this line:
Code: Select all
error C2628: 'MyEventReceiver' followed by 'int' is illegal (did you forget a ';'?)
Also you better remove the '&' from this line:
Code: Select all
MyEventReceiver &receiver;
It is like it is. And because it is like it is, things are like they are.
-
- Posts: 31
- Joined: Tue Apr 12, 2005 12:20 am
Thx. Theres more error message. lol. I want it to play a sound after I press the left mouse button. The code for the sound is set up in the int_main()
its this:
How would I make it from here?
Thanks. Appreciate it.
its this:
Code: Select all
AudioDevicePtr sound_device(OpenDevice());
OutputStreamPtr stream(OpenSound(sound_device, "Theme.mp3", true));
OutputStreamPtr sound(OpenSound(sound_device, "shoot.wav", false));
stream->setRepeat(true);
stream->setVolume(1.5f);
stream->play();
Thanks. Appreciate it.
-
- Posts: 31
- Joined: Tue Apr 12, 2005 12:20 am
I tried this and got some errors. Please fix them. PLZ.
and the sound playing code:
Thanks.
Code: Select all
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
//sound to play variable
bool shoot_sound;
//Mouse event
if (event.EventType == EMIE_LMOUSE_PRESSED_DOWN)
{
shoot_sound = true;
}
if (event.EventType == EMIE_LMOUSE_LEFT_UP)
{
shoot_sound = false;
}
}
};
int main()
{
MyEventReceiver DaReceiver;
video::E_DRIVER_TYPE driverType;
printf("Please select the driver you want for this example:\n"\
" (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.2\n"\
" (d) Software Renderer\n (e) NullDevice\n (otherKey) exit\n\n");
char i;
std::cin >> i;
switch(i)
{
case 'a': driverType = video::EDT_DIRECTX9;break;
case 'b': driverType = video::EDT_DIRECTX8;break;
case 'c': driverType = video::EDT_OPENGL; break;
case 'd': driverType = video::EDT_SOFTWARE; break;
case 'e': driverType = video::EDT_NULL; break;
default: return 0;
}
IrrlichtDevice *device = createDevice(driverType,
core::dimension2d<s32>(640, 480), 32, false);
if (device == 0)
return 1;
device->setEventReceiver(DaReceiver);
Code: Select all
// play background music and gun shot sound
AudioDevicePtr sound_device(OpenDevice());
OutputStreamPtr stream(OpenSound(sound_device, "Theme.mp3", true));
OutputStreamPtr sound(OpenSound(sound_device, "shoot.wav", false));
stream->setRepeat(true);
stream->setVolume(1.5f);
stream->play();
if (shoot_sound = true)
{
sound->setRepeat(false);
sound->setVolume(0.5f);
sound->play();
}
if (shoot_sound = false)
{
sound->stop();
}
Not very familar with audiere so I might do more harm than good but...ViperGuy911 wrote:Thanks.Code: Select all
// play background music and gun shot sound AudioDevicePtr sound_device(OpenDevice()); OutputStreamPtr stream(OpenSound(sound_device, "Theme.mp3", true)); OutputStreamPtr sound(OpenSound(sound_device, "shoot.wav", false));
should this be
AudioDevicePtr *sound_device;
OutputStreamPtr *stream;
OutputStreamPtr *sound;
sound_device=OpenDevice(); //are you sure you don't need any augs here?
stream=OpenSound(sound_device, "Theme.mp3", true);
sound=OpenSound(sound_device, "shoot.wav", false);
Hi,
In the below code within the if condition you are assigning a value to shoot_sound instead of comparing the value with a ==
-trek
[edit]
The sound->stop() is not really needed either... because the setRepeat is off the gun shot sound will only be played once and then stop (assuming that the player does not continue to hold the mouse button down forcing shoot_sound continually true). If sound->stop is called then it may interrupt the gun shot sound, this may not be a desirable effect.... just a thought...
In the below code within the if condition you are assigning a value to shoot_sound instead of comparing the value with a ==
-trek
ViperGuy911 wrote: if (shoot_sound = true)
{
sound->setRepeat(false);
sound->setVolume(0.5f);
sound->play();
}
if (shoot_sound = false)
{
sound->stop();
}
[/code]
[edit]
The sound->stop() is not really needed either... because the setRepeat is off the gun shot sound will only be played once and then stop (assuming that the player does not continue to hold the mouse button down forcing shoot_sound continually true). If sound->stop is called then it may interrupt the gun shot sound, this may not be a desirable effect.... just a thought...
-
- Posts: 31
- Joined: Tue Apr 12, 2005 12:20 am
-
- Posts: 31
- Joined: Tue Apr 12, 2005 12:20 am
-
- Posts: 31
- Joined: Tue Apr 12, 2005 12:20 am
Hiya,
Here is some code that works kinda like you are wanting: I modified one of the examples so there is some stuff in it that is not really needed.
-trek
http://www.l2clan.com/irrlicht/sample.cpp
gunshot file I used:
http://www.l2clan.com/irrlicht/shot.wav
Here is some code that works kinda like you are wanting: I modified one of the examples so there is some stuff in it that is not really needed.
-trek
http://www.l2clan.com/irrlicht/sample.cpp
gunshot file I used:
http://www.l2clan.com/irrlicht/shot.wav
hey, one of ur errors is here
as event.EventType can equal EET_MOUSE_INPUT_EVENT, but not EMIE_LMOUSE_PRESSED_DOWN, and vice versa for event.MouseInput.Event
u should use something like if(event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN);//Mouse event
if (event.EventType == EMIE_LMOUSE_PRESSED_DOWN)
{
shoot_sound = true;
}
as event.EventType can equal EET_MOUSE_INPUT_EVENT, but not EMIE_LMOUSE_PRESSED_DOWN, and vice versa for event.MouseInput.Event