Scroll screen

Started by
3 comments, last by 1Bit 12 years, 9 months ago
Ok so its simple, I want to get the Mouse X and Y coords and scroll the screen based on them, I need some help though, any one wants to help post pseudo code?

SDL_GetMouseState(&X, &Y);

I know I need this function right here...

help is appreciated...
Advertisement
Are you unsure of the basic technique, or the implementation details?

if(x < 50) { scroll_left(); }
if(x > screenwidth - 50) { scroll_right(); }
if(y < 50) { scroll_up(); }
if(y > screenheight - 50) { scroll_down(); }


Of course it makes more sense to make the "50" a configurable variable so people can set the margins they want.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]


Ok so its simple, I want to get the Mouse X and Y coords and scroll the screen based on them, I need some help though, any one wants to help post pseudo code?

SDL_GetMouseState(&X, &Y);

I know I need this function right here...

help is appreciated...


You basically want to set the mouse to a known location (like the middle of the screen), then, on every mouse mouse, subtract the X difference from the known location X, and scroll the screen that much. make sure it's signed, so, if the mouse moves right 5 pixels, you'll scroll +5 (right), and if the mouse moves left 5 pixels, you'll move -5 (left).
Then, reset the mouse to the known location. Repeat.

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

Thanks for your answers, I got it ;)

I have another question though:



I'm trying to make this map editor, I got a function to do something when the mouse is right clicked, now, my problem is I can't figure out what to do to lets say Add/Remove a tile at the cursor's current position...

TileList[ID].TypeID == NONE;

TileList is a vector and the [ID] is the Tiles themselves, so lets say ID == 1 that would be the first tile (top left corner)

I'm guessing I need to manipulate the [ID] part to get the current tile based on my coordinates?

it is 1 AM and I am beat from work and I have to get up early in a couple of hours......................................

even typing this the idea itself comes to mind but lol I'm too tired and my head is starting to hurt...
Well after typing that up I decided to try one more time and it turns out I was in the right track, I just need to find the X and Y coordinates and do a little math to find the current ID the cursor position and then

if (LeftClick== 1)
{
AddTile();
}

LeftClick is an integer that is 1 when the LeftClick button on the mouse is being held down, and 0 otherwise...

I tested it with a "temporary function" and it worked, now I need to make a couple of adjustments, just thought I notify you.

This topic is closed to new replies.

Advertisement