Drag around an image
in
Programming Questions
•
2 years ago
Hi there!
I'm really new to processing (and fairly new to coding, too!) and I'm trying to make a small prototype.
What I have is a big image (say, 4 time my viewport) and I need to drag it around in a smooth way. I have two behaviors I want:
1) if I drag, I move the map in the direction I'm dragging (like in PS or Illustrator when you drag around your artboard.
2) if I click on the viewport the map should center the point I've clicked in a smooth way.
Here is my code for now:
- PImage mapSfondo;
- float x=0;
- float y=0;
- float easing = 0.05;
- void setup()
- {
- size (320, 240);
- smooth();
- imageMode(CENTER);
- mapSfondo = loadImage("map.png");
- }
- void draw ()
- {
- image (mapSfondo, x,y);
- }
- void mouseDragged ()
- {
- x += (mouseX - x) * easing;
- y += (mouseY-y)*easing;
- }
Plus, I'm still not sure how to do the second behavior. Can someone help me? Thanks!
1