[SDL] Having a surface follow the mouse??

Bob Pendleton bob at pendleton.com
Thu Feb 27 15:17:02 PST 2003


On Thu, 2003-02-27 at 16:10, Tane Piper wrote:
> Hey everyone,
> 
> I'm trying to make an in-game editor for my engine, and what I want is to
> allow the user to place tiles on screen to make up the level.
> 
> Using the [ & ] keys, the user can select what tile they want, and I want to
> be able to have the tile graphic follow the mouse to where the user then
> places that tile.  At the moment, I have a SDL_Event called mouseevent and I
> get a pointer to it's current X & Y coords on screen:
> 
> const SDL_Event *mouseevent;
> if ( mouseevent->type == SDL_MOUSEMOTION ) {
>                curX = mouseevent->motion.x;
>                curY = mouseevent->motion.y;
>      }
> 
> BlitTile(tileset,tileX,0,20,20,screen,curX,curY);
> 
> The BlitTile function then draws the tile to the screen, but just draws it
> at 0,0 on the screen.  I am using a mouse event example from the SDL docs,
> so what am I doing wrong?  

Have you proved to your self that the curX and curY are being used
correctly inside your BlitTile function? Printed them out to see the
real value? Then, have you made sure that the values are passed
correctly to the real blit function?

Clearly, the coordinates are NOT getting from the mouse event to the SDL
blit function. Trace the actual values using either a debugger or print
statements to find what value are being passed, and where they are being
lost.

		Bob Pendleton

> Is there a better way to grab the mouse state
> (including the button presses so I can "deposit" the tile on the main
> surface)?
> 
> Thanks,
> Tane
> http://tane.cream.org
> 
> 
> 
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl
-- 
+------------------------------------+
+ Bob Pendleton, consultant for hire +
+ Resume: http://www.jump.net/~bobp  +
+ Email:  bob at pendleton.com          +
+------------------------------------+





More information about the SDL mailing list