problem too Show mouse position in SDL

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
Vortex
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 70
Joined: Sat Nov 15, 2008 1:00 pm

problem too Show mouse position in SDL

Post by Vortex »

Hello im currently learning SDL and i want to make a function in my program that shows the current position of the mouse ( x and y ) but when i try it it sais i cannot send in a string into the function that blits the surface :( i hope you understand what i mean im kinda tired and im not sitting by the computer that i got my source on so i cannot really explain so good.


how do you guys do it? :)
TorteXXX
Chaos Clown
ES Beta Backer
ES Beta Backer
Posts: 61
Joined: Sun Sep 21, 2008 4:46 am
Location: U.K.

Re: problem too Show mouse position in SDL

Post by Chaos Clown »

Well, to get the current mouse position, you'd use an event.
For example:

Code: Select all

int MouseX, MouseY;
SDL_Event event;

while (SDL_PollEvent( &event))
{
   if (event.type == SDL_MOUSEMOTION)
   {
      MouseX = event.motion.x;
      MouseY = event.motion.y;
   }
}
Although, it sounds more like the error you're having is to do with the image blitting function, are you trying to pass a string where you should be passing an SDL_Surface?
¡Sí! ¡He dejado en libertad los prisioneros y ahora vengo por ti!
~El Pollo Diablo
User avatar
KuramaYoko10
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 55
Joined: Fri Oct 31, 2008 8:02 pm

Re: problem too Show mouse position in SDL

Post by KuramaYoko10 »

Hey dude,


I am learning C and SDL too...

And about your problem, I don't know if I understood right but you have several comands to manipulate the mouse, you have to look the SDL_mouse.h file!
One of them to look the exact position when this command is executed is this:

Code: Select all

int x;
int y;

SDL_GetMouseState(&x, &y);
Now if you want to display every position of mouse on screen as you move it, you can go by where ChaosClown have pointed xD

Hope it helps!!
Type a message here!!
[b][color=#BF0000]MarauderIIC[/color][/b] wrote:"Never" is never true in programming.
User avatar
M_D_K
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1087
Joined: Tue Oct 28, 2008 10:33 am
Favorite Gaming Platforms: PC
Programming Language of Choice: C/++
Location: UK

Re: problem too Show mouse position in SDL

Post by M_D_K »

you can also do:

Code: Select all

//mouse_x and mouse_y are int
//mouseButtons are unsigned int
SDL_PumpEvents();
mouseButtons = SDL_GetMouseState(&mouse_x, &mouse_y);
I prefer this cause you get all mouse button states at the same time.
To check whech buttons are pressed you can use this

Code: Select all

//button is stuff like SDL_BUTTON_LEFT, SDL_BUTTON_WHEELDOWN, etc
//the & is a bitwise and
//not to be confused with logical and which is &&
bool MouseBtnDown(int button)
{
    return (mouseButtons&SDL_BUTTON(button))!=0; 
};
Gyro Sheen wrote:you pour their inventory onto my life
IRC wrote: <sparda> The routine had a stack overflow, sorry.
<sparda> Apparently the stack was full of shit.
User avatar
Vortex
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 70
Joined: Sat Nov 15, 2008 1:00 pm

Re: problem too Show mouse position in SDL

Post by Vortex »

Thanks for your anwsers, i havent been able to try it cause my computer is fucked wich my stuff is on :oops:
i just wanted to let you know that i have recived your anwsers :)
TorteXXX
Post Reply