Setting limits on a pan

edited October 2013 in How To...

Hello!

I know this is a SUPER noobie question, but I am very new to Processing and having a ton of trouble with this.

Basically, I have an image and I have programmed it to be panned when the user drags the mouse and zoomed with 'z' and 'x' keys. I have searched everywhere, and cannot find how to limit the frame it can be panned in, if that makes sense. I basically do not want to be able to see the background at any point - if the image is not zoomed, it should not be able to be panned around since it is at the limit. It shouldn't be able to be pulled off screen. Does this make sense?

I can post the code so far on Friday (10/11), since it is saved on a different computer, but it is super basic. If anyone knows off hand how to do this, it would help a ton. Thanks!!

Answers

  • Answer ✓
    pan_x = constrain(pan_x,0,myImage.width-width);
    pan_y = constrain(pan_y,0,myImage.height-height);
    
Sign In or Register to comment.