Mouse coordinates

Code:
if(SDL_PollEvent(&events))
{
if(events.type == SDL_QUIT)
done = true;
if( events.type == SDL_KEYDOWN )
{
switch( events.key.keysym.sym )
{
case SDLK_ESCAPE: done = true; break;
case SDLK_LEFT: Sprites.Sprites[0].xV -= 70; break;
case SDLK_RIGHT: Sprites.Sprites[0].xV += 70; break;
case SDLK_UP: Sprites.Sprites[0].yV -= 70; break;
case SDLK_DOWN: Sprites.Sprites[0].yV += 70; break;
}
}
if( events.type == SDL_KEYUP )
{
switch( events.key.keysym.sym )
{
case SDLK_LEFT: Sprites.Sprites[0].xV += 70; break;
case SDLK_RIGHT: Sprites.Sprites[0].xV -= 70; break;
case SDLK_UP: Sprites.Sprites[0].yV += 70; break;
case SDLK_DOWN: Sprites.Sprites[0].yV -= 70; break;
}
}
if( events.type == SDL_MOUSEMOTION )
{

		}

Each time key pressed the mouse disappears into some strange coordinates (52662,52662), only on the mouse event it updates its position.

RomanZ wrote:

Each time key pressed the mouse disappears into some strange coordinates (52662,52662), only on the mouse event it updates its position.

How are you determining this? I don’t see any text output or anything like that in your code…

Also, for responding to the various event types it makes more sense to use a switch statement or a series of else-if’s. (Since the type can only have a single value, there’s no point in using successive ‘if’ statements.)

i used cout.
cout << window->cursor.getX() << endl;

So you’re using a C++ port of SDL? What version of SDL?On Mon, Aug 23, 2010 at 4:24 PM, RomanZ wrote:

i used cout.
cout << window->cursor.getX() << endl;


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

RomanZ wrote:

i used cout.
cout << window->cursor.getX() << endl;

What is ‘window->cursor.getX()’? Is that your code, or some external library? Does the data come from SDL?

The only guess I can make based on the info you’ve provided is that you’re trying to access the mouse coordinates when the event is not a ‘mouse’ event. The SDL event type is a union, so what data is accessible and valid depends on what type of event is represented. In other words, the mouse position data will not always be valid/accessible.

If you need further help, I think you’ll need to provide more details about how and where you’re acquiring the mouse position data.

1.2.14

i think it exactly whats happening, would you like me to upload the project?

Ya, I think you’re going to have to post some code if you need more helpOn Mon, Aug 23, 2010 at 4:42 PM, RomanZ wrote:

i think it exactly whats happening, would you like me to upload the
project?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

1.2.14

I don’t know if it’s the same bug, but I experienced something like that
with 1.2.? on Linux and reported it on this list a few years ago.

Only when you use fullscreen mode, when you hide the cursor, the mouse
gets warped to some semirandom location. There was some very convoluted
explanation related to fractional positions and the like, to understand
which you should know SDL internals - that I don’t.

I think at the end the general conclusion was that that was a bug, but I
have no idea if it got fixed and if yes, from which revision does it work.

As a workaround, I have a little wrapper:

void HideCursor( int hide )
{
int x, y;

SDL_GetMouseState( &x, &y );
SDL_ShowCursor( hide ? SDL_DISABLE : SDL_ENABLE );
SDL_WarpMouse( x, y );

}

That works.

ZoltanOn Mon, 23 Aug 2010, RomanZ wrote: