Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Stopping View Scrolling  (Read 2565 times)

0 Members and 1 Guest are viewing this topic.

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Stopping View Scrolling
« on: July 10, 2011, 08:19:03 am »
I am attempting to make the view scroll while the user has their mouse on the right or left side of the window. It is scrolling over and image and I need it to automatically stop when it reaches the edge of the image.

I have a tried few methods, but none have worked out.

[list=1]1. I have tried putting a line of black of pixels along the first and last columns. I then had the program look at the current pixels that the mouse is over and look for the black pixels, but as there has to be a margin area for the mouse to scroll with that didn't work.

2. I put another line of pixels at the edge of the scrolling margin but that didn't work out as planned either.

3. I have tried just sensing the black surrounding the image, but that isn't part of the image, so I can't sense it for a color.[/list:o]

I can think of only one more method, but I have no idea how to implement it.

-Somehow have the computer know where the view is on the image.
    The only trouble I have with this is that the Offset for scrolling is 100f * the frame rate. I assume that will make the frame rate vary from computer to computer, so I can't count using that. Correct if I'm mistaken.

Don't know if this will help but:
The window is 1280x720.
The image is 3840x720 (3x the window length).
-Wander

DeroldClifford

  • Newbie
  • *
  • Posts: 2
    • View Profile
Stopping View Scrolling
« Reply #1 on: September 07, 2011, 04:50:20 am »
:oops:
I'm to new at this to give you actual code, however I would break it down as so:

Code: [Select]
psodo
ViewPort (x, y, width, height)
bool leftA = false;               //left side active?
bool rightA = true;              //right side active?

Change(ViewPort);

if ViewPort.x <= 0
{
     ViewPort.x = 0;
     leftA = false;
}
else
{
     leftA = true;
}

if ViewPort.x >= picture.width-ViewPort.width
{
     ViewPort.x = picture.width-ViewPort.width;
     rightA = false;
}
else
{
     rightA = true;
}

void Change(ViewPort)
{
     (I said move it left)
     {
          if rightA = true move it
          else do nothing.
     }

     (I said move it right)
     {
          if leftA = true move it
          else do nothing.
     }
}

/* of course above code won't work in any current language,
but should give an idea in what ways you might like to go*/
Barely a beginner, so please correct me, not burn me.

thePyro_13

  • Full Member
  • ***
  • Posts: 156
    • View Profile
Stopping View Scrolling
« Reply #2 on: September 07, 2011, 05:49:38 am »
I would try and use GetViewPort to get the screen rect bellow the view.
EDIT: which seems like what Derold is suggesting as well. However I would just keep moving the view back onto the image before rendering rather than blocking the scroll action in the first place.

Get the top left corner(change according to which image edge you want to check against) of that rect and use it as a vector from the world origin to the view.

Do the same with the sprites.GetPosition() * width(or hight or nothing depending on which corner you want).

Then you can compare them to see where the view is compared to the image.

such:
if( GetViewPort().bottomright.x > image.GetPosition + sprite.GetSize().x)
    \\view is beyond the right edge of the sprite move it so that:
     GetViewPort().bottomright.x == image.GetPosition + sprite.GetSize().x

And so on for left(and up and down if you wish as well).
You should be able to use this concept to develop a solution.

 

anything