[SDL] using an image as mouse cursor
j_post at pacbell.net
j_post at pacbell.net
Sat Jan 22 09:36:52 PST 2005
On Saturday 22 January 2005 04:47 am, Roger D. Vargas wrote:
> I didnt got any answer about how to convert a surface to cursor, so I
> tried another method I found in a demo app. I hide system cursor, then
> use mouse motion events to change image coordinates. The demo works
> smooth, but in my program for some reason the image floats slowly
> following mouse path during some time instead of behaving like the
> system cursor.
> This is the code I use (copied exactly from demo)
>
> if (event.motion.type==SDL_MOUSEMOTION) {
> cx=event.button.x;
> cy=event.button.y;
> cur_pos.x=cx;
> cur_pos.y=cy;
> cur_pos.w=cursor->w;
> cur_pos.h=cursor->h;
>
> //after closing if...
> SDL_BlitSurface(cursor,NULL, screen,&cur_pos);
>
> What Im doing wrong?
Probably responding to each mouse motion event. You'll get *lots* of them--if
you redraw for each one, it may bog down your system.
Try saving the x & y coordinates of each event and only redraw after there
are no more, or another event type occurs. If you're using a typical
while (SDL_PollEvent(&event))
loop, you'll catch enough mouse motion events for the cursor to move
smoothly, but not drag down the system doing unnecessary blits.
HTH,
Jeff
More information about the SDL
mailing list