Having a surface follow the mouse?

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? 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

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 PendletonOn Thu, 2003-02-27 at 16:10, Tane Piper wrote:

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

±-----------------------------------+

You can also use SDL_GetMouseState(), but as Bob already pointed out, the problem is
with your BlitTile function call.On Thu, Feb 27, 2003 at 10:10:15PM -0000, Tane Piper wrote:

Is there a better way to grab the mouse state
(including the button presses so I can “deposit” the tile on the main
surface)?


Ivan Stankovic, @Ivan_Stankovic