# How to use mousePressed with mouseX and mouseY?

**URL:** <https://discourse.processing.org/t/how-to-use-mousepressed-with-mousex-and-mousey/12000>\
**Category:** Coding Questions\
**Created:** [June 12, 2019, 1:14am UTC](https://discourse.processing.org/t/how-to-use-mousepressed-with-mousex-and-mousey/12000 "2019-06-12T01:14:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![carriemarrie](https://avatars.discourse-cdn.com/v4/letter/c/e68b1a/32.png) [@carriemarrie](https://discourse.processing.org/u/carriemarrie)\
**Post date:** [June 12, 2019, 1:14am UTC](https://discourse.processing.org/t/how-to-use-mousepressed-with-mousex-and-mousey/12000/1 "2019-06-12T01:14:02Z")

</div>

I have 6 different objects and I’d like to choose one of the objects and move it to the next screen. Right now there is just 3D box on the next screen. But I don’t know how to do it. Any help would be needed!

Here’s the code

> ```
> var rotX = 0;
> var rotY = 0;
> var rotZ = 0;
> var _text;
> 
> var screen = 0;
> 
> function setup() {
> createCanvas(500, 700, WEBGL);
> smooth();
> 
> _text = createGraphics(400,300);
> 
> _text.fill(100);
> _text.textAlign(CENTER);
> _text.textSize(20);
> _text.text('Choose the design', 200, 180);
> _text.textSize(15);
> _text.text('Continue', 320, 270);
> 
> ```
> 
> }
> 
> ```
> function draw() {
> 
> background(180, 80, 80);
> 
> if (screen == 0){
> 
> let locX = mouseX - height / 2;
> let locY = mouseY - width / 2;
> 
> push();
> translate(0, 0, -50);
> noStroke();
> fill(200, 60, 40);
> rect(-250, -380, 500, 800);
> pop();
> 
> push();
> translate(0, 0, -50);
> fill(235);
> stroke(0);
> rect(-235, -310, 140, 140);
> rect(-70, -310, 140, 140);
> rect(95, -310, 140, 140);
> rect(-235, -120, 140, 140);
> rect(-70, -120, 140, 140);
> rect(95, -120, 140, 140);
> rect(-125, 100, 250, 250);
> pop();
> 
> fill(255);
> push();
> translate(-150, -220);
> rotateY(frameCount * 0.01);
> rotateX(frameCount * 0.01);
> smooth();
> ambientLight(60, 60, 60);
> pointLight(255, 255, 255, locX, locY, 100);
> frameRate(25);
> fill(250, 0, 0);
> box(70);
> pop();
> 
> push();
> translate(0, -210);
> rotateY(frameCount * 0.01);
> rotateX(frameCount * 0.01);
> smooth();
> ambientLight(60, 60, 60);
> pointLight(255, 255, 255, locX, locY, 100);
> frameRate(25);
> fill(250, 90, 0);
> cylinder(50, 20);
> pop();
> 
> push();
> translate(150, -220);
> rotateY(frameCount * 0.01);
> rotateX(frameCount * 0.01);
> smooth();
> ambientLight(60, 60, 60);
> pointLight(255, 255, 255, locX, locY, 100);
> frameRate(25);
> fill(20, 80, 150);
> cone(50, 70);
> pop();
> 
> push();
> translate(-150, -45);
> rotateY(frameCount * 0.01);
> rotateX(frameCount * 0.01);
> smooth();
> ambientLight(60, 60, 60);
> pointLight(255, 255, 255, locX, locY, 100);
> frameRate(25);
> fill(90, 80, 200);
> torus(30, 15);
> pop();
> 
> push();
> translate(0, -45);
> rotateY(frameCount * 0.01);
> rotateX(frameCount * 0.01);
> smooth();
> ambientLight(60, 60, 60);
> pointLight(255, 255, 255, locX, locY, 100);
> frameRate(25);
> fill(20, 190, 250);
> box(60, 30, 40);
> 
> pop();
> 
> push();
> translate(150, -45);
> 
> rotateY(frameCount * 0.01);
> rotateX(frameCount * 0.01);
> smooth();
> ambientLight(60, 60, 60);
> pointLight(255, 255, 255, locX, locY, 100);
> frameRate(25);
> fill(20, 250, 200);
> ellipsoid(60, 15, 40);
> pop();
> 
> push();
> ambientLight(random(250), random(230));
> noStroke();
> fill(20);
> ellipse(180, 230, 60, 60);
> fill(250);
> ellipse(180, 230, 43, 43);
> fill(0);
> ellipse(180, 230, 35, 35);
> pop();
> 
> push();
> if (mouseX < 180 && mouseY < 220) {
> translate(0, 220);
> rotateY(frameCount * 0.01);
> rotateX(frameCount * 0.01);
> smooth();
> ambientLight(60, 60, 60);
> pointLight(255, 255, 255, locX, locY, 100);
> frameRate(25);
> fill(250, 0, 0);
> box(70);
> } else if (mouseX < 320 && mouseY < 220){
> translate(0, 220);
> rotateY(frameCount * 0.01);
> rotateX(frameCount * 0.01);
> smooth();
> ambientLight(60, 60, 60);
> pointLight(255, 255, 255, locX, locY, 100);
> frameRate(25);
> fill(250, 90, 0);
> cylinder(50, 20);
> } else if (mouseX < 480 && mouseY < 220){
> translate(0, 220);
> rotateY(frameCount * 0.01);
> rotateX(frameCount * 0.01);
> smooth();
> ambientLight(60, 60, 60);
> pointLight(255, 255, 255, locX, locY, 100);
> frameRate(25);
> fill(20, 80, 150);
> cone(50, 70);
> } else if (mouseX < 180 && mouseY < 420){
> translate(0, 220);
> rotateY(frameCount * 0.01);
> rotateX(frameCount * 0.01);
> smooth();
> ambientLight(60, 60, 60);
> pointLight(255, 255, 255, locX, locY, 100);
> frameRate(25);
> fill(90, 80, 200);
> torus(30, 15);
> } else if (mouseX < 320 && mouseY < 420){
> translate(0, 220);
> rotateY(frameCount * 0.01);
> rotateX(frameCount * 0.01);
> smooth();
> ambientLight(60, 60, 60);
> pointLight(255, 255, 255, locX, locY, 100);
> frameRate(25);
> fill(20, 190, 250);
> box(60, 30, 40);
> } else if (mouseX < 480 && mouseY < 420){
> translate(0, 220);
> rotateY(frameCount * 0.01);
> rotateX(frameCount * 0.01);
> smooth();
> ambientLight(60, 60, 60);
> pointLight(255, 255, 255, locX, locY, 100);
> frameRate(25);
> fill(20, 250, 200);
> ellipsoid(60, 15, 40);
> }
> pop();
> 
> texture(_text);
> noStroke();
> plane(600, 600);
> } else if (screen == 1) {
> 
> background (200);
> 
> push();
> translate (0, 0, -50);
> fill(255, 0, 0);
> rect(-250, -350, 500, 700);
> pop();
> 
> fill(255);
> push();
> rotateY(rotY);
> rotateX(rotX);
> translate(mouseX - width/2, mouseY - height/2);
> box(75, 100, 50);
> pop();
> }}
> 
> function mouseDragged(){
> if (screen == 0) {
> screen = 1;
> } else if (screen ==1) {
> 
> rotY += (mouseX - pmouseX) * 0.01;
> rotX += -(mouseY - pmouseY) * 0.01;
> 
> ```
> 
> }}

---

<div class="post-metadata">

**Author:** ![InferNova](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/infernova/32/6009_2.png) [@InferNova](https://discourse.processing.org/u/InferNova)\
**Post date:** [June 12, 2019, 12:22pm UTC](https://discourse.processing.org/t/how-to-use-mousepressed-with-mousex-and-mousey/12000/2 "2019-06-12T12:22:00Z")

</div>

Hey There!

Have you looked into mousePressed ? Also having a bounding for each shape to be able to choose it.  
And it be great for a simple example !

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [June 14, 2019, 11:02pm UTC](https://discourse.processing.org/t/how-to-use-mousepressed-with-mousex-and-mousey/12000/3 "2019-06-14T23:02:40Z")

</div>

> [@carriemarrie](#):
>
> choose one of the objects and move it to the next screen

Do you mean, click one object with the mouse and then draw a new screen with only that clicked object, not all six?
