Public Group

Scroll screen

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

Recommended Posts

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

Share on other sites
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.

Share on other sites

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.

Share on other sites

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

Share on other sites
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)
{
}

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.

1. 1
2. 2
Rutin
19
3. 3
JoeJ
16
4. 4
5. 5

• 30
• 22
• 13
• 13
• 17
• Forum Statistics

• Total Topics
631700
• Total Posts
3001800
×