How to get mouse click...[solved]

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.
ViperGuy911
Posts: 31
Joined: Tue Apr 12, 2005 12:20 am

How to get mouse click...[solved]

Post by ViperGuy911 »

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
Last edited by ViperGuy911 on Thu May 12, 2005 3:19 am, edited 1 time in total.
ViperGuy911
Posts: 31
Joined: Tue Apr 12, 2005 12:20 am

Post by ViperGuy911 »

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:

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.
The errors given is:

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)
Can you please tell me what I am doing wrong?


Thanks
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post by jox »

Look at the error message:

Code: Select all

error C2628: 'MyEventReceiver' followed by 'int' is illegal (did you forget a ';'?) 
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

MyEventReceiver &receiver; 
It is like it is. And because it is like it is, things are like they are.
ViperGuy911
Posts: 31
Joined: Tue Apr 12, 2005 12:20 am

Post by ViperGuy911 »

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:

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();
How would I make it from here?
Thanks. Appreciate it.
ViperGuy911
Posts: 31
Joined: Tue Apr 12, 2005 12:20 am

Post by ViperGuy911 »

I tried this and got some errors. Please fix them. PLZ.

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);
and the sound playing code:

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();
}
Thanks.
Guest

Post by Guest »

ViperGuy911 wrote:

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)); 
Thanks.
Not very familar with audiere so I might do more harm than good but...


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);
ViperGuy911
Posts: 31
Joined: Tue Apr 12, 2005 12:20 am

Post by ViperGuy911 »

No. Its not. Thanks anyway.
trekker
Posts: 18
Joined: Sat Apr 09, 2005 6:40 pm

Post by trekker »

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
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...
ViperGuy911
Posts: 31
Joined: Tue Apr 12, 2005 12:20 am

Post by ViperGuy911 »

trekker let me get back to you its late now i cant think.
trekker
Posts: 18
Joined: Sat Apr 09, 2005 6:40 pm

Post by trekker »

lol no problem....

for me the only time in the day I can think is when its late, :P
stodge
Posts: 216
Joined: Fri Dec 05, 2003 5:57 pm

Post by stodge »

if (shoot_sound = true)

should be

if (shoot_sound == true)

You need to learn some basic C/C++ before demanding help from others.

If you look further up in your code, you'll see a similar IF statement which would have given you your answer if you had bothered to look:

if (device == 0)
ViperGuy911
Posts: 31
Joined: Tue Apr 12, 2005 12:20 am

Post by ViperGuy911 »

I've tried that already, still error message.
ViperGuy911
Posts: 31
Joined: Tue Apr 12, 2005 12:20 am

Post by ViperGuy911 »

I've tried that already, still error message.

Can you please just rescript the eventReceiver, please?
I dont really understand how to set it up.

Thanks
BTW- Sorry about double post thing.
trekker
Posts: 18
Joined: Sat Apr 09, 2005 6:40 pm

Post by trekker »

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
SARIN
Posts: 139
Joined: Fri Oct 29, 2004 3:53 am

Post by SARIN »

hey, one of ur errors is here
//Mouse event
if (event.EventType == EMIE_LMOUSE_PRESSED_DOWN)
{
shoot_sound = true;
}
u should use something like if(event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN);
as event.EventType can equal EET_MOUSE_INPUT_EVENT, but not EMIE_LMOUSE_PRESSED_DOWN, and vice versa for event.MouseInput.Event
Post Reply