Sign in to follow this  
1Bit

Scroll screen

Recommended Posts

1Bit    100
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 this post


Link to post
Share on other sites
ApochPiQ    23003
Are you unsure of the basic technique, or the implementation details?

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

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

Share this post


Link to post
Share on other sites
BeerNutts    4400
[quote name='1Bit' timestamp='1310950531' post='4836562']
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...
[/quote]

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 this post


Link to post
Share on other sites
1Bit    100
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...

Share this post


Link to post
Share on other sites
1Bit    100
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this