Jump to content
  • Advertisement
Sign in to follow this  
walle

Move a image with the mouse?

This topic is 5050 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello. I'm wondering, how do you move a image with the mouse in SDL? I've tried this.

...

int x=0;
int y=0;

...

while(gameloop)
{
    SDL_GetMouseState(&x,&y);
    SDL_DrawImage(img,x,y);
}

But that does only work when you aren't in the window. If you open another window and pull the mousepointer over where the SDL windov is it draws the image. I find it wery strange, does anyone know why this hapens? And a way to make it right? //walle

Share this post


Link to post
Share on other sites
Advertisement
i'm not familiar w/ SDL....but maybe there's a way you can add an IF statement to check if your window 'has focus' before your mouse/image code:


if (myWindow.hasFocus() == true)
{
SDL_GetMouseState(&x,&y);
SDL_DrawImage(img,x,y);
}


Share this post


Link to post
Share on other sites
I'm currently using SDL and the Mouse on a project and all of my SDL_GetMouseState(&x,&y); are in a loop with SDL_PollEvent(&ev);

Do you call SDL_PollEvent in your loop?

It sounds strange though when you say the position IS updated when the window does not have focus, though.

Share this post


Link to post
Share on other sites
Yes that is what I thougth strange to =)

Yes I have a poll.event but the getstate isn't in it.

like this

while(gameloop)
{
SDL_GetMouseState(&x,&y);
SDL_DrawImage(img,x,y);
while(SDL_Poll.event)
{
...
}
}

but I'll try using it in the poll event loop instead...when I come home from school =) thanks

//walle

Share this post


Link to post
Share on other sites
The polling method:


while ( SDL_PollEvent(&event) )
{
switch(event.type){
case SDL_MOUSEMOTION:
xPos = event.motion.x;
yPos = event.motion.y;
break;
}

}



Share this post


Link to post
Share on other sites
Yes. I found that bit out by the SDL documentation...probobly should have checked it before coming here...

Thanks anyway =)

//walle

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!